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

📄 localinput.cpp

📁 很好的流媒体服务器程序,linux或window下做流媒体的可以参考很不错哦
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  C_MpegConverter* pConverter;  // Create the converter  C_MpegConverterModule* pConverterModule = (C_MpegConverterModule*)                                C_Application::GetModuleManager()                                        ->GetModule("mpegconverter",                                                    strConverterType);  if(pConverterModule)  {    C_MpegConverterConfig cConfig;    cConfig.m_hLog = m_hLog;    cConfig.m_pBroadcast = pBroadcast;    cConfig.m_pReader = pReader;    cConfig.m_pTsProvider = pTsProvider;    cConfig.m_pHandler = pBuffer;    cConfig.m_iInitFill = pBuffer->Capacity();    cConfig.m_pEventHandler = m_pEventHandler;    pConverter = pConverterModule->NewMpegConverter(cConfig);    ASSERT(pConverter);  }  else  {    throw E_Exception(GEN_ERR,                      "Module mpegconverter:" + strConverterType +                      " not present");  }  pReader->SetConverter(pConverter);  // Create the streamer  C_TsStreamer* pStreamer = new C_TsStreamer(m_hLog, pBroadcast,                                             pTsProvider, pBuffer,                                             m_pEventHandler, true, true);  ASSERT(pStreamer);  m_cConverters.Add(pBroadcast, pConverter);  m_cStreamers.Add(pBroadcast, pStreamer);  try  {    pConverter->Create();    pStreamer->Create();  }  catch(E_Exception e)  {    pConverter->Stop();    pStreamer->Stop();    // Unregister the 2 thread and delete them    m_cConverters.Delete(pBroadcast);    m_cStreamers.Delete(pBroadcast);    throw E_Exception(GEN_ERR, "unable to start streaming of program "+                      pBroadcast->GetProgram()->GetName(), e);  }}//------------------------------------------------------------------------------// Resume the reception of the given program//------------------------------------------------------------------------------void C_LocalInput::OnResumeStreaming(C_Broadcast* pBroadcast){  ASSERT(pBroadcast);  // Find the converter that receive the pgrm  C_MpegConverter* pConverter = m_cConverters.Get(pBroadcast);  ASSERT(pConverter);  // Resume the thread  try  {    pConverter->Resume();  }  catch(E_Exception e)  {    throw E_Exception(GEN_ERR, "Unable to resume streaming of program "+                      pBroadcast->GetProgram()->GetName(), e);  }}//------------------------------------------------------------------------------// Suspend the reception of the given program//------------------------------------------------------------------------------void C_LocalInput::OnSuspendStreaming(C_Broadcast* pBroadcast){  ASSERT(pBroadcast);  // Find the converter that receive the pgrm  C_MpegConverter* pConverter = m_cConverters.Get(pBroadcast);  ASSERT(pConverter);  C_String strPgrmName = pBroadcast->GetProgram()->GetName();  // Suspend the thread  try  {    pConverter->Suspend();  }  catch(E_Exception e)  {    throw E_Exception(GEN_ERR, "Unable to resume streaming of program "+                      pBroadcast->GetProgram()->GetName(), e);  }}//------------------------------------------------------------------------------// Stop the reception of the given program//------------------------------------------------------------------------------void C_LocalInput::OnStopStreaming(C_Broadcast* pBroadcast){  ASSERT(pBroadcast);  // Find the reader and the streamer that receive the pgrm  C_MpegConverter* pConverter = m_cConverters.Remove(pBroadcast);  ASSERT(pConverter);  C_TsStreamer* pStreamer = m_cStreamers.Remove(pBroadcast);  ASSERT(pStreamer);  // Stop the threads  try  {    pConverter->Stop();    delete pConverter;    pStreamer->Stop();    delete pStreamer;  }  catch(E_Exception e)  {    throw E_Exception(GEN_ERR, "Unable to stop streaming of program "+                      pBroadcast->GetProgram()->GetName(), e);  }}//------------------------------------------------------------------------------////------------------------------------------------------------------------------void C_LocalInput::OnUpdateProgram(C_String strProgram,                                     C_String strFileName, C_String strType){  C_Application* pApp = C_Application::GetApp();  ASSERT(pApp);  C_String strPgrmCount = pApp->GetSetting("Input.ProgramCount", "0");  unsigned int uiPgrmCount = strPgrmCount.ToInt();  unsigned int uiId = m_vProgramNames.Find(strProgram) + 1;  if (uiId>0)  {    Log(m_hLog, LOG_WARN, "The program already exists in the list for this input");  }  if(uiPgrmCount)  {      uiPgrmCount++;      C_String strKey = C_String(uiPgrmCount)+ ".Name";      pApp->SetSettings(strKey,strProgram);      strKey = C_String(uiPgrmCount)+ ".FileName";      pApp->SetSettings(strKey, strFileName);      strKey = C_String(uiPgrmCount)+ ".Type";      pApp->SetSettings(strKey, strType);      strKey = C_String("Input.ProgramCount");      C_String strPgrmCount=C_String(uiPgrmCount);      pApp->SetSettings(strKey, strPgrmCount);      // add to m_vProgramNames      C_String strName = pApp->GetSetting(C_String(uiPgrmCount) + ".Name",                                                C_String("Pgrm") + uiPgrmCount);      C_String* pStr = new C_String(strName);      m_vProgramNames.Add(pStr);  }  else  {    throw E_Exception(GEN_ERR, "No files defined in vls.cfg");  }}//------------------------------------------------------------------------------////------------------------------------------------------------------------------void C_LocalInput::OnDeleteProgram(C_String strProgram){  C_Application* pApp = C_Application::GetApp();  ASSERT(pApp);  // Get the type of the program  unsigned int uiId = m_vProgramNames.Find(strProgram) + 1;  if (uiId>0)  {    // Delete settings from m_cSettings    C_String strPgrmCount = pApp->GetSetting("Input.ProgramCount", "0");    unsigned int uiPgrmCount = strPgrmCount.ToInt();    if(uiPgrmCount)    {      C_String strDelKey = C_String(uiId)+ ".Name";      pApp->DeleteSetting(strDelKey);      if (pApp->GetSetting(C_String(uiId)+".FileName", "") != "" )      {        strDelKey = C_String(uiId)+ ".FileName";        pApp->DeleteSetting(strDelKey);      }      if (pApp->GetSetting(C_String(uiId)+".Device", "") != "" )      {        strDelKey = C_String(uiId)+ ".Device";        pApp->DeleteSetting(strDelKey);      }      strDelKey = C_String(uiId)+ ".Type";      pApp->DeleteSetting(strDelKey);      // Move all other settings one item down      for(unsigned int ui = uiId; ui <= uiPgrmCount; ui++)      {        C_String strProgram = pApp->GetSetting(C_String(ui+1) + ".Name",C_String("Pgrm") + ui+1);        C_String strFileName = pApp->GetSetting(C_String(ui+1)+".FileName", "");        C_String strType = pApp->GetSetting(C_String(ui+1) + ".Type", "Mpeg2-TS");        C_String strDevice = pApp->GetSetting(C_String(ui+1)+".Device", "");        // update settings        C_String strKey = C_String(ui)+ ".Name";        pApp->SetSettings(strKey,strProgram);        strKey = C_String(ui)+ ".FileName";        pApp->SetSettings(strKey, strFileName);        strKey = C_String(ui)+ ".Device";        pApp->SetSettings(strKey, strDevice);        strKey = C_String(ui)+ ".Type";        pApp->SetSettings(strKey, strType);      }      // Lower program count      uiPgrmCount--;      strDelKey = C_String("Input.ProgramCount");      C_String strProgramCount=C_String(uiPgrmCount);      pApp->SetSettings(strDelKey, strPgrmCount);      //pApp->SetSettings(strDelKey, C_String(uiPgrmCount));      m_vProgramNames.Delete(uiId);      // ** DEBUG **      Log(m_hLog, LOG_NOTE, "Debugging inputs m_cSettings list.");      C_String strPgrmCount = pApp->GetSetting("Input.ProgramCount", "0");      unsigned int uiPgrmCount = strPgrmCount.ToInt();      for(unsigned int ui = 1; ui <= uiPgrmCount; ui++)      {        C_String strProgram = pApp->GetSetting(C_String(ui) + ".Name",C_String("Pgrm") + ui);        C_String strFileName = pApp->GetSetting(C_String(ui)+".FileName", "");        C_String strDevice = pApp->GetSetting(C_String(ui)+".Device", "");        C_String strType = pApp->GetSetting(C_String(ui) + ".Type", "Mpeg2-TS").ToLower();        Log(m_hLog, LOG_NOTE, "Program: \"" + strProgram +"\"");        Log(m_hLog, LOG_NOTE, "  FileName: \"" + strFileName+"\"");        Log(m_hLog, LOG_NOTE, "  Device: \"" + strDevice+"\"");        Log(m_hLog, LOG_NOTE, "  Type: \"" + strType+"\"");      }    }    else    {      throw E_Exception(GEN_ERR,"Deleting program information from input failed");    }  }  else  {    throw E_Exception(GEN_ERR, "The program is not known by this input.");  }}

⌨️ 快捷键说明

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