MythTV master
upnputil.cpp
Go to the documentation of this file.
1
2// Program Name: upnputil.cpp
3// Created : Jan. 15, 2007
4//
5// Purpose : Global Helper Methods...
6//
7// Copyright (c) 2007 David Blain <dblain@mythtv.org>
8//
9// Licensed under the GPL v2 or later, see LICENSE for details
10//
12#include "upnputil.h"
13
14// Qt headers
15#include <QUuid>
16#include <QStringList>
17
18// MythTV headers
21
22#include "httprequest.h"
23#include "upnphelpers.h"
24
26//
28
29QString LookupUDN( const QString &sDeviceType )
30{
31 QStringList sList = sDeviceType.split(':', Qt::SkipEmptyParts);
32 QString sLoc = "LookupUDN(" + sDeviceType + ')';
33
34 if (sList.size() <= 2)
35 {
36 LOG(VB_GENERAL, LOG_ERR, sLoc + "- bad device type '" +
37 sDeviceType + "', not enough tokens");
38 return {};
39 }
40
41 sList.removeLast();
42 auto config = XmlConfiguration(); // read-write
43 QString sName = "UPnP/UDN/" + sList.last();
44 QString sUDN = config.GetValue(sName, "");
45
46 LOG(VB_UPNP, LOG_INFO, sLoc + " sName=" + sName + ", sUDN=" + sUDN);
47
48 // Generate new UUID if current is missing or broken
49 if (sUDN.isEmpty() || sUDN.startsWith("{"))
50 {
51 sUDN = QUuid::createUuid().toString();
52 // QUuid returns the uuid enclosed with braces {} which is not
53 // DLNA compliant, we need to remove them
54 sUDN = sUDN.mid(1, 36);
55
56 config.SetValue(sName, sUDN);
57 config.Save();
58 }
59
60 return sUDN;
61}
62
70{
71 QStringList mimeTypes = HTTPRequest::GetSupportedMimeTypes();
72
73 QString protocolStr("http-get:*:%1:%2");
74 QStringList protocolList;
75 QStringList::Iterator it;
76 for (it = mimeTypes.begin(); it < mimeTypes.end(); ++it)
77 {
78 // HACK
80 if (*it == "video/mpeg")
81 {
82 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_PAL;" + flags);
83 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_NTSC;" + flags);
84 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_SD_DTS;" + flags);
85 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AVC_TS_NA_ISO;" + flags);
86 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_HD_NA_ISO;" + flags);
87 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_SD_NA_ISO;" + flags);
88 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AVC_TS_EU_ISO;" + flags);
89 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_SD_EU_ISO;" + flags);
90 }
91 else if (*it == "audio/mpeg")
92 {
93 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MP3;" + flags); // Technically we don't actually serve these
94 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MP3X;" + flags);
95 }
96 else if (*it == "audio/mp4")
97 {
98 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AAC_ISO_320;" + flags);
99 }
100 else if (*it == "audio/vnd.dolby.dd-raw")
101 {
102 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AC3;" + flags);
103 }
104 else if (*it == "audio/x-ms-wma")
105 {
106 protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=WMAFULL;" + flags);
107 }
108 else
109 {
110 protocolList << protocolStr.arg(*it, "*");
111 }
112 }
113
114 return protocolList;
115}
116
124{
125 QStringList mimeTypes = HTTPRequest::GetSupportedMimeTypes();
126
127 QStringList protocolList;
128 QStringList::Iterator it;
129 for (it = mimeTypes.begin(); it < mimeTypes.end(); ++it)
130 {
131 protocolList << QString("http-get:*:%1:*").arg(*it);
132 }
133
134 return protocolList;
135}
136
static QStringList GetSupportedMimeTypes()
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QString FlagsString(uint32_t flags)
Convert an integer composed of DNLA_Flags to a properly formatted string for use in XML.
@ kv1_5_flag
Definition: upnphelpers.h:262
@ ktm_b
Definition: upnphelpers.h:256
@ ktm_s
Definition: upnphelpers.h:254
QStringList GetSinkProtocolInfos()
Return a QStringList containing the supported Sink Protocols.
Definition: upnputil.cpp:123
QStringList GetSourceProtocolInfos()
Return a QStringList containing the supported Source Protocols.
Definition: upnputil.cpp:69
QString LookupUDN(const QString &sDeviceType)
Definition: upnputil.cpp:29