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#include <QTextStream>
14
15// MythTV
16#include "libmythbase/compat.h"
20#include "libmythbase/mythversion.h"
22#include "libmythupnp/ssdp.h"
24
25// MythFrontend
26#include "mediarenderer.h"
27#include "mythfexml.h"
29#include "services/frontend.h"
30#include "upnpscanner.h"
31
34//
35// UPnp MediaRenderer Class implementaion
36//
39
41//
43
45{
46 LOG(VB_UPNP, LOG_INFO, "MediaRenderer(): Begin");
47
48 int nPort = XmlConfiguration().GetValue("UPnP/MythFrontend/ServicePort", 6547);
49 // frontend upnp server is now ServicePort + 4 (default 6551)
50 nPort += 4;
51
52 auto *pHttpServer = new HttpServer();
53
54 if (!pHttpServer)
55 return;
56
57 if (!pHttpServer->listen(nPort))
58 {
59 LOG(VB_GENERAL, LOG_ERR, "MediaRenderer: HttpServer Create Error");
60 delete pHttpServer;
61 pHttpServer = nullptr;
62 return;
63 }
64
65 // ------------------------------------------------------------------
66 // Register any HttpServerExtensions...
67 // ------------------------------------------------------------------
68
69 pHttpServer->RegisterExtension(new FrontendServiceHost(pHttpServer->GetSharePath()));
70
71 // ----------------------------------------------------------------------
72 // Initialize UPnp Stack
73 // ----------------------------------------------------------------------
74
75 if (Initialize( nPort, pHttpServer ))
76 {
77 // ------------------------------------------------------------------
78 // Create device Description
79 // ------------------------------------------------------------------
80
81 LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Creating UPnp Description");
82
84
85 device.m_sDeviceType = "urn:schemas-upnp-org:device:MediaRenderer:1";
86 device.m_sFriendlyName = "MythTV AV Renderer";
87 device.m_sManufacturer = "MythTV";
88 device.m_sManufacturerURL = "http://www.mythtv.org";
89 device.m_sModelDescription = "MythTV AV Media Renderer";
90 device.m_sModelName = "MythTV AV Media Renderer";
91 device.m_sModelURL = "http://www.mythtv.org";
92 device.m_sUPC = "";
93 device.m_sPresentationURL = "/";
94
95 QString sSinkProtocols = GetSinkProtocolInfos().join(",");
96
97 // ------------------------------------------------------------------
98 // Register the MythFEXML protocol...
99 // ------------------------------------------------------------------
100 LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Registering MythFEXML Extension.");
103
104#if 0
105 LOG(VB_UPNP, LOG_INFO,
106 "MediaRenderer::Registering AVTransport Service.");
107 m_pUPnpAVT = new UPnpAVTransport( RootDevice() );
108 m_pHttpServer->RegisterExtension( m_pUPnpAVT );
109#endif
110
111 LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Registering ConnectionManager Service.");
112 // HttpServer will be responsible for deleting UPnpCMGR
113 m_pUPnpCMGR = new UPnpCMGR(
114 RootDevice(), m_pHttpServer->GetSharePath(), "", sSinkProtocols);
116
117#if 0
118 LOG(VB_UPNP, LOG_INFO,
119 "MediaRenderer::Registering RenderingControl Service.");
120 m_pUPnpRCTL= new UPnpRCTL( RootDevice() );
121 m_pHttpServer->RegisterExtension( m_pUPnpRCTL );
122#endif
123
124 UPNPSubscription *subscription = nullptr;
125 if (qEnvironmentVariableIsSet("MYTHTV_UPNPSCANNER"))
126 {
127 LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Registering UPnP Subscription Extension.");
128 subscription = new UPNPSubscription(m_pHttpServer->GetSharePath(), nPort);
129 m_pHttpServer->RegisterExtension(subscription);
130 }
131
132 Start();
133
134 // Start scanning for UPnP media servers
135 if (subscription)
136 UPNPScanner::Enable(true, subscription);
137
138 // ensure the frontend is aware of all backends (slave and master) and
139 // other frontends
140 SSDP::Instance()->PerformSearch("ssdp:all");
141 }
142 else
143 {
144 LOG(VB_GENERAL, LOG_ERR,
145 "MediaRenderer: Unable to Initialize UPnp Stack");
146 }
147
148 LOG(VB_UPNP, LOG_INFO, "MediaRenderer(): End");
149}
150
152//
154
156{
157 UPNPScanner::Enable(false);
158 delete m_pHttpServer;
159}
QString GetSharePath(void) const
Definition: httpserver.h:128
void RegisterExtension(HttpServerExtension *pExtension)
Definition: httpserver.cpp:313
UPnpCMGR * m_pUPnpCMGR
Definition: mediarenderer.h:34
~MediaRenderer() override
static SSDP * Instance()
Definition: ssdp.cpp:57
void PerformSearch(const QString &sST, std::chrono::seconds timeout=2s)
Send a SSDP discover multicast datagram.
Definition: ssdp.cpp:159
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:65
HttpServer * m_pHttpServer
Definition: upnp.h:43
virtual void Start()
Definition: upnp.cpp:145
bool Initialize(int nServicePort, HttpServer *pHttpServer)
Definition: upnp.cpp:75
static UPnpDeviceDesc g_UPnpDeviceDesc
Definition: upnp.h:48
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