00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "mediaserver.h"
00012 #include "mythxml.h"
00013
00014 #include "upnpcdstv.h"
00015 #include "upnpcdsmusic.h"
00016 #include "upnpcdsvideo.h"
00017
00020
00021
00022
00025
00027
00029
00030 MediaServer::MediaServer( bool bIsMaster, bool bDisableUPnp )
00031 {
00032 VERBOSE(VB_UPNP, QString("MediaServer::Begin"));
00033
00034
00035
00036
00037
00038 SetConfiguration( new DBConfiguration() );
00039
00040
00041
00042
00043
00044 int nPort = g_pConfig->GetValue( "BackendStatusPort", 6544 );
00045 QString sIP = g_pConfig->GetValue( "BackendServerIP" , "" );
00046
00047 if (sIP.isEmpty())
00048 {
00049 VERBOSE(VB_IMPORTANT,
00050 "MediaServer:: No BackendServerIP Address defined");
00051 m_pHttpServer = NULL;
00052 return;
00053 }
00054
00055
00056 m_pHttpServer = new HttpServer( nPort );
00057
00058 if (!m_pHttpServer->ok())
00059 {
00060 VERBOSE(VB_IMPORTANT, "MediaServer::HttpServer Create Error");
00061
00062 delete m_pHttpServer;
00063 m_pHttpServer = NULL;
00064 return;
00065 }
00066
00067 m_sSharePath = gContext->GetShareDir();
00068 m_pHttpServer->m_sSharePath = m_sSharePath;
00069
00070 QString sFileName = g_pConfig->GetValue( "upnpDescXmlPath",
00071 m_sSharePath );
00072 QString sDeviceType;
00073
00074 if ( bIsMaster )
00075 {
00076 sFileName += "devicemaster.xml";
00077 sDeviceType = "urn:schemas-mythtv-org:device:MasterMediaServer:1";
00078 }
00079 else
00080 {
00081 sFileName += "deviceslave.xml";
00082 sDeviceType = "urn:schemas-mythtv-org:device:SlaveMediaServer:1";
00083 }
00084
00085
00086
00087
00088
00089 VERBOSE(VB_UPNP, "MediaServer::Loading UPnp Description " + sFileName );
00090
00091 g_UPnpDeviceDesc.Load( sFileName );
00092
00093 UPnpDevice *pMythDevice = UPnpDeviceDesc::FindDevice( RootDevice(),
00094 sDeviceType );
00095
00096
00097
00098
00099
00100 VERBOSE(VB_UPNP, "MediaServer::Registering MythXML Service." );
00101
00102 m_pHttpServer->RegisterExtension( new MythXML( pMythDevice ));
00103
00104 if (sIP == "localhost" || sIP.startsWith("127."))
00105 {
00106 VERBOSE(VB_IMPORTANT, "MediaServer:: Loopback address specified - "
00107 + sIP + ". Disabling UPnP");
00108 return;
00109 }
00110
00111 if (bDisableUPnp)
00112 {
00113 VERBOSE(VB_IMPORTANT, "*** The UPNP service has been DISABLED with the "
00114 "--noupnp option ***");
00115 return;
00116 }
00117
00118
00119
00120
00121
00122 QStringList sIPAddrList = QStringList::split( ";", sIP );
00123
00124
00125
00126
00127
00128 if (Initialize( sIPAddrList, nPort, m_pHttpServer ))
00129 {
00130
00131
00132
00133
00134
00135 if (bIsMaster)
00136 {
00137 QString sSourceProtocols = "http-get:*:image/gif:*,"
00138 "http-get:*:image/jpeg:*,"
00139 "http-get:*:image/png:*,"
00140 "http-get:*:video/avi:*,"
00141 "http-get:*:audio/mpeg:*,"
00142 "http-get:*:audio/wav:*,"
00143 "http-get:*:video/mpeg:*,"
00144 "http-get:*:video/nupplevideo:*,"
00145 "http-get:*:video/x-ms-wmv:*";
00146
00147 VERBOSE(VB_UPNP, "MediaServer::Registering MSRR Service." );
00148
00149 m_pHttpServer->RegisterExtension( new UPnpMSRR( RootDevice(),
00150 m_sSharePath ) );
00151
00152 VERBOSE(VB_UPNP, "MediaServer::Registering CMGR Service." );
00153
00154 m_pUPnpCMGR = new UPnpCMGR( RootDevice(),
00155 m_sSharePath, sSourceProtocols );
00156 m_pHttpServer->RegisterExtension( m_pUPnpCMGR );
00157
00158 VERBOSE(VB_UPNP, "MediaServer::Registering CDS Service." );
00159
00160 m_pUPnpCDS = new UPnpCDS ( RootDevice(), m_sSharePath );
00161 m_pHttpServer->RegisterExtension( m_pUPnpCDS );
00162
00163
00164
00165
00166
00167 VERBOSE(VB_UPNP, "MediaServer::Registering UPnpCDSTv Extension");
00168
00169 RegisterExtension(new UPnpCDSTv());
00170
00171 VERBOSE(VB_UPNP, "MediaServer::Registering UPnpCDSMusic Extension");
00172
00173 RegisterExtension(new UPnpCDSMusic());
00174
00175 VERBOSE(VB_UPNP, "MediaServer::Registering UPnpCDSVideo Extension");
00176
00177 RegisterExtension(new UPnpCDSVideo());
00178
00179 upnpMedia = new UPnpMedia(true,true);
00180
00181 }
00182
00183
00184
00185
00186
00187 Start();
00188
00189 }
00190
00191 VERBOSE(VB_UPNP, QString( "MediaServer::End" ));
00192 }
00193
00195
00197
00198 MediaServer::~MediaServer()
00199 {
00200
00201
00202
00203
00204 if (m_pHttpServer)
00205 delete m_pHttpServer;
00206 }
00207
00209
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00224
00226
00227 void MediaServer::RegisterExtension( UPnpCDSExtension *pExtension )
00228 {
00229 m_pUPnpCDS->RegisterExtension( pExtension );
00230 }
00231
00233
00235
00236 void MediaServer::UnregisterExtension( UPnpCDSExtension *pExtension )
00237 {
00238 m_pUPnpCDS->UnregisterExtension( pExtension );
00239 }