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

📄 localinput.cpp

📁 很好的流媒体服务器程序,linux或window下做流媒体的可以参考很不错哦
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** localinput.cpp: Local streams*-------------------------------------------------------------------------------* (c)1999-2001 VideoLAN* $Id: localinput.cpp,v 1.13.4.1 2003/06/04 19:06:14 alexis 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"#define MAX_FILES_NUMBER 4096//------------------------------------------------------------------------------// 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_Settings m_cSettings;  C_Application* pApp = C_Application::GetApp();  ASSERT(pApp);  // Build the program list  for(int ui = 1;       ui <= pApp->GetSetting(GetName()+".ProgramCount", "0").ToInt(); ui++)  {    C_String strName = pApp->GetSetting(GetName()+"."+C_String(ui)		                + ".Name",  C_String("Pgrm") + ui);    C_String* pStr = new C_String(strName);    m_vProgramNames.Add(pStr);    Log(m_hLog, LOG_NOTE, "Added program '" + *pStr+"'");  }}//------------------------------------------------------------------------------// 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){  C_Application* pApp = C_Application::GetApp();  ASSERT(pApp);  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 strId = GetName() + "." + uiId;  C_String strType = pApp->GetSetting(strId + ".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 +                                   pApp->GetSetting(strId+".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 +                       pApp->GetSetting(strId+".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 +                       pApp->GetSetting(strId+".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 = pApp->GetSetting(strId+".Device", "");    pBroadcast->SetOption("device", strDevice);    C_String strDvdTitle = pApp->GetSetting(strId+".dvdtitle","");    pBroadcast->SetOption("dvdtitle", strDvdTitle);    C_String strDvdChapter = pApp->GetSetting(strId+".dvdchapter","");    pBroadcast->SetOption("dvdchapter", strDvdChapter);    // 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  {    throw E_Exception(GEN_ERR,                      "Module mpegreader:" + strConverterType +                      " not present");  }

⌨️ 快捷键说明

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