-
Notifications
You must be signed in to change notification settings - Fork 341
/
iptvtuningdata.h
270 lines (235 loc) · 7.38 KB
/
iptvtuningdata.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// -*- Mode: c++ -*-
#ifndef _IPTV_TUNING_DATA_H_
#define _IPTV_TUNING_DATA_H_
// Qt headers
#include <QString>
#include <QUrl>
// MythTV headers
#include "mythtvexp.h"
#include "mythlogging.h"
#include "mythsingledownload.h"
#include "recorders/HLS/HLSReader.h"
class MTV_PUBLIC IPTVTuningData
{
public:
typedef enum FECType
{
kNone,
kRFC2733,
kRFC5109,
kSMPTE2022,
} FECType;
typedef enum IPTVType
{
kData = 1,
kRFC2733_1,
kRFC2733_2,
kRFC5109_1,
kRFC5109_2,
kSMPTE2022_1,
kSMPTE2022_2,
} IPTVType;
typedef enum IPTVProtocol
{
inValid = 0,
udp,
rtp,
rtsp,
http_ts,
http_hls
} IPTVProtocol;
IPTVTuningData() : m_fec_type(kNone), m_protocol(inValid)
{
memset(&m_bitrate, 0, sizeof(m_bitrate));
}
IPTVTuningData(const QString &data_url, IPTVProtocol protocol) :
m_data_url(data_url), m_fec_type(kNone), m_protocol(protocol)
{
memset(&m_bitrate, 0, sizeof(m_bitrate));
}
IPTVTuningData(const QString &data_url, uint data_bitrate,
const FECType fec_type,
const QString &fec_url0, uint fec_bitrate0,
const QString &fec_url1, uint fec_bitrate1) :
m_data_url(data_url),
m_fec_type(fec_type), m_fec_url0(fec_url0), m_fec_url1(fec_url1)
{
GuessProtocol();
m_bitrate[0] = data_bitrate;
m_bitrate[1] = fec_bitrate0;
m_bitrate[2] = fec_bitrate1;
}
IPTVTuningData(const QString &data_url, uint data_bitrate,
const QString &fec_type,
const QString &fec_url0, uint fec_bitrate0,
const QString &fec_url1, uint fec_bitrate1,
const IPTVProtocol protocol) :
m_data_url(data_url),
m_fec_type(kNone), m_fec_url0(fec_url0), m_fec_url1(fec_url1),
m_protocol(protocol)
{
m_bitrate[0] = data_bitrate;
m_bitrate[1] = fec_bitrate0;
m_bitrate[2] = fec_bitrate1;
if (fec_type.toLower() == "rfc2733")
m_fec_type = kRFC2733;
else if (fec_type.toLower() == "rfc5109")
m_fec_type = kRFC5109;
else if (fec_type.toLower() == "smpte2022")
m_fec_type = kSMPTE2022;
else
{
m_fec_url0.clear();
m_fec_url1.clear();
}
}
QString GetDeviceKey(void) const
{
const QUrl u = GetDataURL();
if (IsHLS())
return QString("%1(%2)").arg(u.toString()).arg(GetBitrate(0));
if (IsHTTPTS() || IsRTSP())
return QString("%1").arg(u.toString());
return QString("%1:%2:%3")
.arg(u.host()).arg(u.userInfo()).arg(u.port()).toLower();
}
QString GetDeviceName(void) const
{
return QString("[data]%1[fectype]%2[fec0]%3[fec1]%4%5")
.arg(GetDataURL().toString())
.arg(GetFECTypeString(1))
.arg(GetFECURL1().toString())
.arg(GetFECURL1().toString())
.arg(GetBitrate(0) ? QString("-%1").arg(GetBitrate(0)) : "");
}
bool operator==(const IPTVTuningData &other) const
{
return GetDeviceName() == other.GetDeviceName();
}
bool operator!=(const IPTVTuningData &other) const
{
return GetDeviceName() != other.GetDeviceName();
}
void SetDataURL(const QUrl &url)
{
m_data_url = url;
GuessProtocol();
}
QUrl GetDataURL(void) const { return m_data_url; }
QUrl GetFECURL0(void) const { return m_fec_url0; }
QUrl GetFECURL1(void) const { return m_fec_url1; }
QUrl GetURL(uint i) const
{
if (0 == i)
return GetDataURL();
else if (1 == i)
return GetFECURL0();
else if (2 == i)
return GetFECURL1();
else
return QUrl();
}
uint GetBitrate(uint i) const { return m_bitrate[i]; }
FECType GetFECType(void) const { return m_fec_type; }
QString GetFECTypeString(uint i) const
{
if (0 == i)
return "data";
switch (m_fec_type)
{
case kNone: return QString();
case kRFC2733: return QString("rfc2733-%1").arg(i);
case kRFC5109: return QString("rfc5109-%1").arg(i);
case kSMPTE2022: return QString("smpte2022-%1").arg(i);
}
return QString();
}
uint GetURLCount(void) const { return 3; }
bool IsValid(void) const
{
bool ret = (m_data_url.isValid() && (IsUDP() || IsRTP() || IsRTSP() || IsHLS() || IsHTTPTS()));
LOG(VB_CHANNEL, LOG_DEBUG, QString("IPTVTuningdata (%1): IsValid = %2")
.arg(m_data_url.toString())
.arg(ret ? "true" : "false"));
return ret;
}
bool IsUDP(void) const
{
return (m_protocol == udp);
}
bool IsRTP(void) const
{
return (m_protocol == rtp);
}
bool IsRTSP(void) const
{
return (m_protocol == rtsp);
}
bool IsHLS() const
{
return (m_protocol == http_hls);
}
bool IsHTTPTS() const
{
return (m_protocol == http_ts);
}
void GuessProtocol(void)
{
if (!m_data_url.isValid())
m_protocol = IPTVTuningData::inValid;
else if (m_data_url.scheme() == "udp")
m_protocol = IPTVTuningData::udp;
else if (m_data_url.scheme() == "rtp")
m_protocol = IPTVTuningData::rtp;
else if (m_data_url.scheme() == "rtsp")
m_protocol = IPTVTuningData::rtsp;
else if (((m_data_url.scheme() == "http") || (m_data_url.scheme() == "https")) && IsHLSPlaylist())
m_protocol = IPTVTuningData::http_hls;
else if ((m_data_url.scheme() == "http") || (m_data_url.scheme() == "https"))
m_protocol = IPTVTuningData::http_ts;
else
m_protocol = IPTVTuningData::inValid;
}
protected:
bool IsHLSPlaylist(void) const
{
if (!qApp)
{
LOG(VB_GENERAL, LOG_ERR, QString("IsHLSPlaylist - No QApplication!!"));
return false;
}
QString url = m_data_url.toString();
// check url is valid for a playlist before downloading (see trac ticket #12856)
if(url.endsWith(".m3u8", Qt::CaseInsensitive) ||
url.endsWith(".m3u", Qt::CaseInsensitive))
{
LOG(VB_RECORD, LOG_INFO, QString("IsHLSPlaylist url ends with either .m3u8 or .m3u %1").arg(url));
}
else
{
// not a valid playlist so just return false
LOG(VB_RECORD, LOG_INFO, QString("IsHLSPlaylist url does not end with either .m3u8 or .m3u %1").arg(url));
return false;
}
QByteArray buffer;
MythSingleDownload downloader;
downloader.DownloadURL(url, &buffer, 5000, 0, 10000);
if (!buffer.size())
{
LOG(VB_GENERAL, LOG_ERR, QString("IsHLSPlaylist - Open Failed: %1\n\t\t\t%2")
.arg(downloader.ErrorString()).arg(url));
return false;
}
QTextStream text(&buffer);
text.setCodec("UTF-8");
return (HLSReader::IsValidPlaylist(text));
}
protected:
QUrl m_data_url;
FECType m_fec_type;
QUrl m_fec_url0;
QUrl m_fec_url1;
uint m_bitrate[3];
IPTVProtocol m_protocol;
};
#endif // _IPTV_TUNING_DATA_H_