MediaRenderer::MediaRenderer() { LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Begin"); // ---------------------------------------------------------------------- // Initialize Configuration class (XML file for frontend) // ---------------------------------------------------------------------- SetConfiguration( new XmlConfiguration( "config.xml" )); // ---------------------------------------------------------------------- // Create mini HTTP Server // ---------------------------------------------------------------------- int nPort = g_pConfig->GetValue( "UPnP/MythFrontend/ServicePort", 6547 ); m_pHttpServer = new HttpServer(); if (!m_pHttpServer) return; if (!m_pHttpServer->listen(QHostAddress(gCoreContext->MythHostAddressAny()), nPort)) { LOG(VB_GENERAL, LOG_ERR, "MediaRenderer::HttpServer Create Error"); delete m_pHttpServer; m_pHttpServer = NULL; return; } // ---------------------------------------------------------------------- // Initialize UPnp Stack // ---------------------------------------------------------------------- if (Initialize( nPort, m_pHttpServer )) { // ------------------------------------------------------------------ // Create device Description // ------------------------------------------------------------------ LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Creating UPnp Description"); UPnpDevice &device = g_UPnpDeviceDesc.m_rootDevice; device.m_sDeviceType = "urn:schemas-upnp-org:device:MediaRenderer:1"; device.m_sFriendlyName = "MythTv AV Renderer"; device.m_sManufacturer = "MythTV"; device.m_sManufacturerURL = "http://www.mythtv.org"; device.m_sModelDescription = "MythTV AV Media Renderer"; device.m_sModelName = "MythTV AV Media Renderer"; device.m_sModelURL = "http://www.mythtv.org"; device.m_sUPC = ""; device.m_sPresentationURL = "/"; // ------------------------------------------------------------------ // Register any HttpServerExtensions... // ------------------------------------------------------------------ LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering MythFrontendStatus service."); m_pHttpServer->RegisterExtension( new MythFrontendStatus(m_pHttpServer->m_sSharePath)); QString sSinkProtocols = "http-get:*:image/gif:*," "http-get:*:image/jpeg:*," "http-get:*:image/png:*," "http-get:*:video/avi:*," "http-get:*:audio/mpeg:*," "http-get:*:audio/wav:*," "http-get:*:video/mpeg:*," "http-get:*:video/nupplevideo:*," "http-get:*:video/x-ms-wmv:*"; // ------------------------------------------------------------------ // Register the MythFEXML protocol... // ------------------------------------------------------------------ LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering MythFEXML Service."); m_pHttpServer->RegisterExtension( new MythFEXML( RootDevice(), m_pHttpServer->m_sSharePath)); #if 0 LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering AVTransport Service."); m_pUPnpAVT = new UPnpAVTransport( RootDevice() ); m_pHttpServer->RegisterExtension( m_pUPnpAVT ); #endif LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering CMGR Service."); // HttpServer will be responsible for deleting UPnpCMGR m_pUPnpCMGR = new UPnpCMGR(RootDevice(), m_pHttpServer->m_sSharePath, "", sSinkProtocols ); m_pHttpServer->RegisterExtension( m_pUPnpCMGR ); #if 0 LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering RenderingControl Service."); m_pUPnpRCTL= new UPnpRCTL( RootDevice() ); m_pHttpServer->RegisterExtension( m_pUPnpRCTL ); #endif UPNPSubscription *subscription = NULL; if (getenv("MYTHTV_UPNPSCANNER")) { LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Registering subscription service."); subscription = new UPNPSubscription(m_pHttpServer->m_sSharePath, nPort); m_pHttpServer->RegisterExtension(subscription); } Start(); // Start scanning for UPnP media servers if (subscription) UPNPScanner::Enable(true, subscription); // ensure the frontend is aware of all backends (slave and master) and // other frontends SSDP::Instance()->PerformSearch("ssdp:all"); } else { LOG(VB_GENERAL, LOG_ERR, "MediaRenderer::Unable to Initialize UPnp Stack"); } LOG(VB_UPNP, LOG_INFO, "MediaRenderer::End"); }
void MediaServer::Init(bool bIsMaster, bool bDisableUPnp /* = FALSE */) { VERBOSE(VB_UPNP, "MediaServer:Init:Begin"); int nPort = g_pConfig->GetValue( "BackendStatusPort", 6544 ); if (!m_pHttpServer) { m_pHttpServer = new HttpServer(); m_pHttpServer->m_sSharePath = m_sSharePath; m_pHttpServer->RegisterExtension(new HttpConfig()); } if (!m_pHttpServer->isListening()) { if (!m_pHttpServer->listen(QHostAddress::Any, nPort)) { VERBOSE(VB_IMPORTANT, "MediaServer::HttpServer Create Error"); delete m_pHttpServer; m_pHttpServer = NULL; return; } } QString sFileName = g_pConfig->GetValue( "upnpDescXmlPath", m_sSharePath ); QString sDeviceType; if ( bIsMaster ) sFileName += "devicemaster.xml"; else sFileName += "deviceslave.xml"; // ------------------------------------------------------------------ // Make sure our device Description is loaded. // ------------------------------------------------------------------ VERBOSE(VB_UPNP, "MediaServer::Loading UPnp Description " + sFileName ); g_UPnpDeviceDesc.Load( sFileName ); // ------------------------------------------------------------------ // Register Http Server Extensions... // ------------------------------------------------------------------ VERBOSE(VB_UPNP, "MediaServer::Registering Http Server Extensions." ); m_pHttpServer->RegisterExtension( new InternetContent ( m_sSharePath )); m_pHttpServer->RegisterExtension( new MythServiceHost ( m_sSharePath )); m_pHttpServer->RegisterExtension( new GuideServiceHost ( m_sSharePath )); m_pHttpServer->RegisterExtension( new ContentServiceHost( m_sSharePath )); m_pHttpServer->RegisterExtension( new DvrServiceHost ( m_sSharePath )); m_pHttpServer->RegisterExtension( new ChannelServiceHost( m_sSharePath )); m_pHttpServer->RegisterExtension( new VideoServiceHost ( m_sSharePath )); QString sIP = g_pConfig->GetValue( "BackendServerIP" , "" ); if (sIP.isEmpty()) { VERBOSE(VB_IMPORTANT, "MediaServer:: No BackendServerIP Address defined - " "Disabling UPnP"); return; } // ------------------------------------------------------------------ // Register Service Types with Scripting Engine // // -=>NOTE: We need to know the actual type at compile time for this // to work, so it needs to be done here. I'm still looking // into ways that we may encapsulate this in the service // classes. // ------------------------------------------------------------------ QScriptEngine* pEngine = m_pHttpServer->ScriptEngine(); pEngine->globalObject().setProperty("Myth" , pEngine->scriptValueFromQMetaObject< ScriptableMyth >() ); pEngine->globalObject().setProperty("Guide" , pEngine->scriptValueFromQMetaObject< ScriptableGuide >() ); pEngine->globalObject().setProperty("Content", pEngine->scriptValueFromQMetaObject< Content >() ); pEngine->globalObject().setProperty("Dvr" , pEngine->scriptValueFromQMetaObject< ScriptableDvr >() ); pEngine->globalObject().setProperty("Channel", pEngine->scriptValueFromQMetaObject< ScriptableChannel >() ); pEngine->globalObject().setProperty("Video" , pEngine->scriptValueFromQMetaObject< ScriptableVideo >() ); // ------------------------------------------------------------------ if (sIP == "localhost" || sIP.startsWith("127.")) { VERBOSE(VB_IMPORTANT, "MediaServer:: Loopback address specified - " + sIP + ". Disabling UPnP"); return; } if (bDisableUPnp) { VERBOSE(VB_IMPORTANT, "*** The UPNP service has been DISABLED with the " "--noupnp option ***"); return; } // ---------------------------------------------------------------------- // BackendServerIP is only one IP address at this time... Doing Split anyway // ---------------------------------------------------------------------- QStringList sIPAddrList = sIP.split(';', QString::SkipEmptyParts); // ---------------------------------------------------------------------- // Initialize UPnp Stack // ---------------------------------------------------------------------- if (Initialize( sIPAddrList, nPort, m_pHttpServer )) { // ------------------------------------------------------------------ // Register any HttpServerExtensions... Only The Master Backend // ------------------------------------------------------------------ if (bIsMaster) { QString sSourceProtocols = "http-get:*:image/gif:*," "http-get:*:image/jpeg:*," "http-get:*:image/png:*," "http-get:*:video/avi:*," "http-get:*:audio/mpeg:*," "http-get:*:audio/wav:*," "http-get:*:video/mpeg:*," "http-get:*:video/nupplevideo:*," "http-get:*:video/x-ms-wmv:*"; VERBOSE(VB_UPNP, "MediaServer::Registering MSRR Service." ); m_pHttpServer->RegisterExtension( new UPnpMSRR( RootDevice(), m_sSharePath ) ); VERBOSE(VB_UPNP, "MediaServer::Registering CMGR Service." ); m_pUPnpCMGR = new UPnpCMGR( RootDevice(), m_sSharePath, sSourceProtocols ); m_pHttpServer->RegisterExtension( m_pUPnpCMGR ); VERBOSE(VB_UPNP, "MediaServer::Registering CDS Service." ); m_pUPnpCDS = new UPnpCDS ( RootDevice(), m_sSharePath ); m_pHttpServer->RegisterExtension( m_pUPnpCDS ); // ---------------------------------------------------------------- // Register CDS Extensions // ---------------------------------------------------------------- VERBOSE(VB_UPNP, "MediaServer::Registering UPnpCDSTv Extension"); RegisterExtension(new UPnpCDSTv()); VERBOSE(VB_UPNP, "MediaServer::Registering UPnpCDSMusic Extension"); RegisterExtension(new UPnpCDSMusic()); VERBOSE(VB_UPNP, "MediaServer::Registering UPnpCDSVideo Extension"); RegisterExtension(new UPnpCDSVideo()); } // VERBOSE(VB_UPNP, QString( "MediaServer::Adding Context Listener" )); // gCoreContext->addListener( this ); Start(); } VERBOSE(VB_UPNP, "MediaServer:Init:End"); }