MythTV master
mediarenderer.cpp
Go to the documentation of this file.
1
2// Program Name: mediarenderer.cpp
3//
4// Purpose - uPnp Media Renderer main Class
5//
6// Created By : David Blain Created On : Jan. 15, 2007
7// Modified By : Modified On:
8//
10
11#include "libmythbase/mythconfig.h"
12
13#if CONFIG_QTSCRIPT
14#include <QScriptEngine>
15#endif
16#include <QTextStream>
17
18// MythTV
19#include "libmythbase/compat.h"
23#include "libmythbase/mythversion.h"
26#include "libmythupnp/ssdp.h"
28
29// MythFrontend
30#include "mediarenderer.h"
31#include "mythfexml.h"
33#include "services/frontend.h"
34#include "upnpscanner.h"
35
38//
39// UPnp MediaRenderer Class implementaion
40//
43
45//
47
49{
50 LOG(VB_UPNP, LOG_INFO, "MediaRenderer(): Begin");
51
52 int nPort = XmlConfiguration().GetValue("UPnP/MythFrontend/ServicePort", 6547);
53 // frontend upnp server is now ServicePort + 4 (default 6551)
54 nPort += 4;
55
56 auto *pHttpServer = new HttpServer();
57
58 if (!pHttpServer)
59 return;
60
61 if (!pHttpServer->listen(nPort))
62 {
63 LOG(VB_GENERAL, LOG_ERR, "MediaRenderer: HttpServer Create Error");
64 delete pHttpServer;
65 pHttpServer = nullptr;
66 return;
67 }
68
69 // ------------------------------------------------------------------
70 // Register any HttpServerExtensions...
71 // ------------------------------------------------------------------
72
73 auto *pHtmlServer =
74 new HtmlServerExtension(pHttpServer->GetSharePath() + "html",
75 "frontend_");
76 pHttpServer->RegisterExtension(pHtmlServer);
77 pHttpServer->RegisterExtension(new FrontendServiceHost(pHttpServer->GetSharePath()));
78
79 // ------------------------------------------------------------------
80 // Register Service Types with Scripting Engine
81 //
82 // -=>NOTE: We need to know the actual type at compile time for this
83 // to work, so it needs to be done here. I'm still looking
84 // into ways that we may encapsulate this in the service
85 // classes. - dblain
86 // ------------------------------------------------------------------
87
88#if CONFIG_QTSCRIPT
89 QScriptEngine* pEngine = pHtmlServer->ScriptEngine();
90
91 pEngine->globalObject().setProperty("Frontend" ,
92 pEngine->scriptValueFromQMetaObject< ScriptableFrontend >() );
93#endif
94
95 // ----------------------------------------------------------------------
96 // Initialize UPnp Stack
97 // ----------------------------------------------------------------------
98
99 if (Initialize( nPort, pHttpServer ))
100 {
101 // ------------------------------------------------------------------
102 // Create device Description
103 // ------------------------------------------------------------------
104
105 LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Creating UPnp Description");
106
108
109 device.m_sDeviceType = "urn:schemas-upnp-org:device:MediaRenderer:1";
110 device.m_sFriendlyName = "MythTV AV Renderer";
111 device.m_sManufacturer = "MythTV";
112 device.m_sManufacturerURL = "http://www.mythtv.org";
113 device.m_sModelDescription = "MythTV AV Media Renderer";
114 device.m_sModelName = "MythTV AV Media Renderer";
115 device.m_sModelURL = "http://www.mythtv.org";
116 device.m_sUPC = "";
117 device.m_sPresentationURL = "/";
118
119 QString sSinkProtocols = GetSinkProtocolInfos().join(",");
120
121 // ------------------------------------------------------------------
122 // Register the MythFEXML protocol...
123 // ------------------------------------------------------------------
124 LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Registering MythFEXML Extension.");
127
128#if 0
129 LOG(VB_UPNP, LOG_INFO,
130 "MediaRenderer::Registering AVTransport Service.");
131 m_pUPnpAVT = new UPnpAVTransport( RootDevice() );
132 m_pHttpServer->RegisterExtension( m_pUPnpAVT );
133#endif
134
135 LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Registering ConnectionManager Service.");
136 // HttpServer will be responsible for deleting UPnpCMGR
137 m_pUPnpCMGR = new UPnpCMGR(
138 RootDevice(), m_pHttpServer->GetSharePath(), "", sSinkProtocols);
140
141#if 0
142 LOG(VB_UPNP, LOG_INFO,
143 "MediaRenderer::Registering RenderingControl Service.");
144 m_pUPnpRCTL= new UPnpRCTL( RootDevice() );
145 m_pHttpServer->RegisterExtension( m_pUPnpRCTL );
146#endif
147
148 UPNPSubscription *subscription = nullptr;
149 if (qEnvironmentVariableIsSet("MYTHTV_UPNPSCANNER"))
150 {
151 LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Registering UPnP Subscription Extension.");
152 subscription = new UPNPSubscription(m_pHttpServer->GetSharePath(), nPort);
153 m_pHttpServer->RegisterExtension(subscription);
154 }
155
156 Start();
157
158 // Start scanning for UPnP media servers
159 if (subscription)
160 UPNPScanner::Enable(true, subscription);
161
162 // ensure the frontend is aware of all backends (slave and master) and
163 // other frontends
164 SSDP::Instance()->PerformSearch("ssdp:all");
165 }
166 else
167 {
168 LOG(VB_GENERAL, LOG_ERR,
169 "MediaRenderer: Unable to Initialize UPnp Stack");
170 }
171
172 LOG(VB_UPNP, LOG_INFO, "MediaRenderer(): End");
173}
174
176//
178
180{
181 UPNPScanner::Enable(false);
182 delete m_pHttpServer;
183}
QString GetSharePath(void) const
Definition: httpserver.h:124
void RegisterExtension(HttpServerExtension *pExtension)
Definition: httpserver.cpp:309
UPnpCMGR * m_pUPnpCMGR
Definition: mediarenderer.h:34
~MediaRenderer() override
static SSDP * Instance()
Definition: ssdp.cpp:102
void PerformSearch(const QString &sST, std::chrono::seconds timeout=2s)
Definition: ssdp.cpp:251
static void Enable(bool enable, UPNPSubscription *sub=nullptr)
Creates or destroys the global UPNPScanner instance.
UPnpDevice m_rootDevice
Definition: upnpdevice.h:158
QString m_sModelDescription
Definition: upnpdevice.h:113
QString m_sDeviceType
Definition: upnpdevice.h:109
QString m_sModelName
Definition: upnpdevice.h:114
QString m_sPresentationURL
Definition: upnpdevice.h:119
QString m_sModelURL
Definition: upnpdevice.h:116
QString m_sManufacturerURL
Definition: upnpdevice.h:112
QString m_sUPC
Definition: upnpdevice.h:118
QString m_sManufacturer
Definition: upnpdevice.h:111
QString m_sFriendlyName
Definition: upnpdevice.h:110
static UPnpDevice * RootDevice()
Definition: upnp.h:124
HttpServer * m_pHttpServer
Definition: upnp.h:102
virtual void Start()
Definition: upnp.cpp:144
bool Initialize(int nServicePort, HttpServer *pHttpServer)
Definition: upnp.cpp:74
static UPnpDeviceDesc g_UPnpDeviceDesc
Definition: upnp.h:107
QString GetValue(const QString &setting)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QStringList GetSinkProtocolInfos()
Return a QStringList containing the supported Sink Protocols.
Definition: upnputil.cpp:123