⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localinput.cpp

📁 可用该程序将avi的电影文件转化为TS流
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** localinput.cpp: Local streams*-------------------------------------------------------------------------------* (c)1999-2001 VideoLAN* $Id: localinput.cpp,v 1.11 2002/10/01 08:09:11 jpsaman Exp $** Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>** This program is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License* as published by the Free Software Foundation; either version 2* of the License, or (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.**-------------------------------------------------------------------------------********************************************************************************///------------------------------------------------------------------------------// Preamble//------------------------------------------------------------------------------#include "../../core/defs.h"#include "../../core/core.h"#include "../../mpeg/mpeg.h"#include "../../mpeg/ts.h"#include "../../mpeg/rtp.h"#include "../../server/program.h"#include "../../server/buffer.h"#include "../../server/output.h"#include "../../server/channel.h"#include "../../server/broadcast.h"#include "../../server/request.h"#include "../../server/input.h"#include "../../server/tsstreamer.h"#include "../../mpeg/reader.h"#include "../../mpeg/converter.h"#include "localinput.h"//------------------------------------------------------------------------------// Library declaration//------------------------------------------------------------------------------#ifdef __PLUGIN__GENERATE_LIB_ARGS(C_LocalInputModule, handle);#endif//------------------------------------------------------------------------------// Builtin declaration//------------------------------------------------------------------------------#ifdef __BUILTIN__C_Module* NewBuiltin_localinput(handle hLog){  return new C_LocalInputModule(hLog);}#endif/******************************************************************************** C_LocalInput class****************************************************************************************************************************************************************///------------------------------------------------------------------------------// Constructor//------------------------------------------------------------------------------C_LocalInput::C_LocalInput(C_Module* pModule,                           const C_String& strName) : C_Input(pModule,                                                              strName){}//------------------------------------------------------------------------------// Destructor//------------------------------------------------------------------------------C_LocalInput::~C_LocalInput(){}//------------------------------------------------------------------------------// Initialization//------------------------------------------------------------------------------void C_LocalInput::OnInit(){  C_Application* pApp = C_Application::GetApp();  ASSERT(pApp);  // Get the path to the config file  C_String strSettingName = GetName() + ".ConfigPath";  m_strConfigPath = pApp->GetSetting(strSettingName, "");  // Load settings  m_cSettings.Load(m_strConfigPath + "/input.cfg", false);  m_strFilesPath = m_cSettings.GetSetting("Input.FilesPath", "");  if(    m_strFilesPath.Length()      && m_strFilesPath[m_strFilesPath.Length() -1] != '/')    m_strFilesPath += "/";  // Build the program list  C_String strPgrmCount = m_cSettings.GetSetting("Input.ProgramCount", "0");  unsigned int uiPgrmCount = strPgrmCount.ToInt();  if(uiPgrmCount)  {    for(unsigned int ui = 1; ui <= uiPgrmCount; ui++)    {      C_String strName = m_cSettings.GetSetting(C_String(ui) + ".Name",                                                C_String("Pgrm") + ui);      C_String* pStr = new C_String(strName);      m_vProgramNames.Add(pStr);    }  }  else  {    Log(m_hLog, LOG_WARN,        "The \"ProgramCount\" variable isn't specified in the file \"" +        m_strConfigPath + "/input.cfg\"");  }}//------------------------------------------------------------------------------// Destruction//------------------------------------------------------------------------------void C_LocalInput::OnDestroy(){}//------------------------------------------------------------------------------////------------------------------------------------------------------------------C_List<C_Program> C_LocalInput::OnGetAvailablePgrms(){  C_List<C_Program> cPgrmList;  for(unsigned int ui = 0; ui < m_vProgramNames.Size(); ui++)  {    C_Program* pProgram = new C_Program(/*ui + 1,*/ m_vProgramNames[ui]);    ASSERT(pProgram);    cPgrmList.PushEnd(pProgram);  }  return cPgrmList;}//------------------------------------------------------------------------------// Start the reception of the given program//------------------------------------------------------------------------------void C_LocalInput::OnStartStreaming(C_Broadcast* pBroadcast){  ASSERT(pBroadcast);  // We choose a TS packet buffer able to store up to 3s of stream at 8 Mbits/s  C_NetList* pTsProvider = new C_NetList(3*3*797);  // The netlist must be at least of the size of the Reader buffer +  // the size of the output buffer + 2 to be sure that there are always free  // packets in it  const C_Channel* pChannel = pBroadcast->GetChannel();  ASSERT(pTsProvider->Capacity() - pChannel->GetBuffCapacity() - 2 > 0);  unsigned int uiSize = pTsProvider->Capacity() -pChannel->GetBuffCapacity()-2;  C_SyncFifo* pBuffer;  // Get the type of the program  unsigned int uiId =        m_vProgramNames.Find(pBroadcast->GetProgram()->GetName()) + 1;  ASSERT(uiId > 0);  C_String strType = m_cSettings.GetSetting(C_String(uiId) + ".Type",                                            "Mpeg2-TS").ToLower();  C_String strReaderType;  C_String strConverterType;  // Specific behaviour depends on the type  if(strType == "mpeg1-ps")             // Mpeg 1 - Program Stream  {    // Update the size of the buffer and create it    uiSize -= 2;    pBuffer = new C_SyncFifo(uiSize);    // Reader configuration    strReaderType = "file";    C_String strFile = m_strFilesPath +                       m_cSettings.GetSetting(C_String(uiId)+".FileName", "");    pBroadcast->SetOption("filename", strFile);    // Converter configuration    strConverterType = "ps2ts";    pBroadcast->SetOption("mpegversion", "1");    pBroadcast->SetOption("preparse", "1");  }  else if(strType == "mpeg2-ps")        // Mpeg 2 - Program Stream  {    // Update the size of the buffer and create it    uiSize -= 2;    pBuffer = new C_SyncFifo(uiSize);    // Reader configuration    strReaderType = "file";    C_String strFile = m_strFilesPath +                       m_cSettings.GetSetting(C_String(uiId)+".FileName", "");    pBroadcast->SetOption("filename", strFile);    // Converter configuration    strConverterType = "ps2ts";    pBroadcast->SetOption("mpegversion", "2");    pBroadcast->SetOption("preparse", "1");  }  else if(strType == "mpeg2-ts")        // Mpeg 2 - Transport Stream  {    // Update the size of the buffer and create it    pBuffer = new C_SyncFifo(uiSize);    // Reader configuration    strReaderType = "file";    C_String strFile = m_strFilesPath +                       m_cSettings.GetSetting(C_String(uiId)+".FileName", "");    pBroadcast->SetOption("filename", strFile);    // Converter configuration    strConverterType = "ts2ts";  }  else if(strType == "dvd")             // DVD device (Mpeg2 PS)  {    // Update the size of the buffer and create it    uiSize -= 2;    pBuffer = new C_SyncFifo(uiSize);    // Reader configuration    strReaderType = "dvd";    C_String strDevice = m_cSettings.GetSetting(C_String(uiId)+".Device", "");    pBroadcast->SetOption("device", strDevice);    // Converter configuration    strConverterType = "ps2ts";    pBroadcast->SetOption("mpegversion", "2");    pBroadcast->SetOption("preparse", "0");  }  else  {    delete pTsProvider;    throw E_Exception(GEN_ERR, "Unsupported or unknown type : " + strType);  }  C_MpegReader* pReader;  // Create the converter  C_MpegReaderModule* pReaderModule = (C_MpegReaderModule*)                                C_Application::GetModuleManager()                                        ->GetModule("mpegreader",                                                    strReaderType);  if(pReaderModule)  {    pReader = pReaderModule->NewMpegReader(pBroadcast);    ASSERT(pReader);  }  else  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -