Skip to content

Commit

Permalink
IPTVTuningData: set the protocol based on the data URL schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Harrison committed Jun 28, 2015
1 parent 5a9f6b8 commit f2c04ca
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 70 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/channelscan/channelimporter.cpp
Expand Up @@ -538,7 +538,7 @@ ScanDTVTransportList ChannelImporter::InsertChannels(
QString::null,
chan.default_authority);

if (!transports[i].iptv_tuning.m_data_url.isEmpty())
if (!transports[i].iptv_tuning.GetDataURL().isEmpty())
ChannelUtil::CreateIPTVTuningData(chan.channel_id,
transports[i].iptv_tuning);
}
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/channelscan/iptvchannelfetcher.h
Expand Up @@ -39,8 +39,7 @@ class IPTVChannelInfo
uint programnumber) :
m_name(name), m_xmltvid(xmltvid), m_programNumber(programnumber),
m_tuning(data_url, data_bitrate,
fec_type, fec_url0, fec_bitrate0, fec_url1, fec_bitrate1,
IPTVTuningData::inValid)
fec_type, fec_url0, fec_bitrate0, fec_url1, fec_bitrate1)
{
}

Expand Down
36 changes: 1 addition & 35 deletions mythtv/libs/libmythtv/channelutil.cpp
Expand Up @@ -2014,49 +2014,15 @@ IPTVTuningData ChannelUtil::GetIPTVTuningData(uint chanid)
case IPTVTuningData::kSMPTE2022_2:
break; // will be handled by type of first FEC stream
}

if (data_url.toLower().startsWith("udp"))
protocol = IPTVTuningData::udp;

else if (data_url.toLower().startsWith("rtp"))
protocol = IPTVTuningData::rtp;

else if (data_url.toLower().startsWith("rtsp"))
protocol = IPTVTuningData::rtsp;

else if (data_url.toLower().startsWith("http") && ChannelUtil::IsHLSPlaylist(data_url))
protocol = IPTVTuningData::http_hls;

else if (data_url.toLower().startsWith("http"))
protocol = IPTVTuningData::http_ts;
}

IPTVTuningData tuning(data_url, bitrate[0], fec_type,
fec_url0, bitrate[1], fec_url1, bitrate[2],
protocol);
fec_url0, bitrate[1], fec_url1, bitrate[2]);
LOG(VB_GENERAL, LOG_INFO, QString("Loaded %1 for %2")
.arg(tuning.GetDeviceName()).arg(chanid));
return tuning;
}

bool ChannelUtil::IsHLSPlaylist(QString url)
{
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));
}

// TODO This should be modified to load a complete channelinfo object including
// all fields from the database
/**
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythtv/channelutil.h
Expand Up @@ -185,7 +185,6 @@ class MTV_PUBLIC ChannelUtil
static QString GetVideoFilters(uint sourceid, const QString &channum)
{ return GetChannelValueStr("videofilters", sourceid, channum); }
static IPTVTuningData GetIPTVTuningData(uint chanid);
static bool IsHLSPlaylist(QString url);

// Are there any other possibly useful sort orders?
// e.g. Sorting by sourceid would probably be better done by two distinct
Expand Down
64 changes: 54 additions & 10 deletions mythtv/libs/libmythtv/iptvtuningdata.h
Expand Up @@ -9,6 +9,8 @@
// MythTV headers
#include "mythtvexp.h"
#include "mythlogging.h"
#include "mythsingledownload.h"
#include "recorders/HLS/HLSReader.h"

class MTV_PUBLIC IPTVTuningData
{
Expand Down Expand Up @@ -42,20 +44,19 @@ class MTV_PUBLIC IPTVTuningData
http_hls
} IPTVProtocol;

IPTVTuningData() : m_fec_type(kNone)
IPTVTuningData() : m_fec_type(kNone), m_protocol(inValid)
{
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,
const IPTVProtocol protocol) :
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),
m_protocol(protocol)
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;
Expand All @@ -64,12 +65,11 @@ class MTV_PUBLIC IPTVTuningData
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) :
const QString &fec_url1, uint fec_bitrate1) :
m_data_url(data_url),
m_fec_type(kNone), m_fec_url0(fec_url0), m_fec_url1(fec_url1),
m_protocol(protocol)
m_fec_type(kNone), 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;
Expand Down Expand Up @@ -115,6 +115,12 @@ class MTV_PUBLIC IPTVTuningData
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; }
Expand Down Expand Up @@ -185,7 +191,45 @@ class MTV_PUBLIC IPTVTuningData
return (m_protocol == http_ts);
}

public:
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") && IsHLSPlaylist())
m_protocol = IPTVTuningData::http_hls;
else if (m_data_url.scheme() == "http")
m_protocol = IPTVTuningData::http_ts;
else
m_protocol = IPTVTuningData::inValid;
}

protected:
bool IsHLSPlaylist(void)
{
QString url = m_data_url.toString();
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;
Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/recorders/HLS/HLSReader.h
Expand Up @@ -23,14 +23,15 @@
#endif

#include "mythlogging.h"
#include "mythtvexp.h"

#include "HLSSegment.h"
#include "HLSStream.h"
#include "HLSStreamWorker.h"
#include "HLSPlaylistWorker.h"


class HLSReader
class MTV_PUBLIC HLSReader
{
friend class HLSStreamWorker;
friend class HLSPlaylistWorker;
Expand Down
5 changes: 2 additions & 3 deletions mythtv/libs/libmythtv/recorders/cetonstreamhandler.cpp
Expand Up @@ -106,8 +106,7 @@ void CetonStreamHandler::Return(CetonStreamHandler * & ref)
}

CetonStreamHandler::CetonStreamHandler(const QString &device) :
IPTVStreamHandler(IPTVTuningData(
"", 0, IPTVTuningData::kNone, "", 0, "", 0, IPTVTuningData::inValid)),
IPTVStreamHandler(IPTVTuningData("", 0, IPTVTuningData::kNone, "", 0, "", 0)),
_card(0),
_tuner(0),
_using_cablecard(false),
Expand Down Expand Up @@ -150,7 +149,7 @@ CetonStreamHandler::CetonStreamHandler(const QString &device) :
int rtspPort = 8554;
QString url = QString("rtsp://%1:%2/cetonmpeg%3")
.arg(_ip_address).arg(rtspPort).arg(_tuner);
m_tuning = IPTVTuningData(url, 0, IPTVTuningData::kNone, "", 0, "", 0, IPTVTuningData::rtsp);
m_tuning = IPTVTuningData(url, 0, IPTVTuningData::kNone, "", 0, "", 0);
m_use_rtp_streaming = true;

_valid = true;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/iptvstreamhandler.cpp
Expand Up @@ -165,7 +165,7 @@ void IPTVStreamHandler::run(void)
urltuned.setScheme("rtp");
urltuned.setPort(0);
tuning = IPTVTuningData(urltuned.toString(), 0, IPTVTuningData::kNone,
urltuned.toString(), 0, "", 0, IPTVTuningData::rtp);
urltuned.toString(), 0, "", 0);
}

bool error = false;
Expand Down
@@ -1,3 +1,3 @@
#include "test_iptvrecorder.h"

QTEST_APPLESS_MAIN(TestIPTVRecorder)
QTEST_MAIN(TestIPTVRecorder)
35 changes: 20 additions & 15 deletions mythtv/libs/libmythtv/test/test_iptvrecorder/test_iptvrecorder.h
Expand Up @@ -42,28 +42,29 @@ class TestIPTVRecorder: public QObject
IPTVTuningData tuning;

/* test url from #11949 without port, free.fr */
tuning.m_data_url = QUrl (QString("rtsp://mafreebox.freebox.fr/fbxtv_pub/stream?namespace=1&service=203&flavour=sd"));
tuning.m_protocol = IPTVTuningData::rtsp;
tuning.SetDataURL(QUrl(QString("rtsp://mafreebox.freebox.fr/fbxtv_pub/stream?namespace=1&service=203&flavour=sd")));
QVERIFY (tuning.IsValid());
QVERIFY (tuning.IsRTSP());

/* test url from #11949 with port, free.fr */
tuning.m_data_url = QUrl (QString("rtsp://mafreebox.freebox.fr:554/fbxtv_pub/stream?namespace=1&service=203&flavour=sd"));
tuning.m_protocol = IPTVTuningData::rtsp;
tuning.SetDataURL(QUrl(QString("rtsp://mafreebox.freebox.fr:554/fbxtv_pub/stream?namespace=1&service=203&flavour=sd")));
QVERIFY (tuning.IsValid());
QVERIFY (tuning.IsRTSP());

/* test url from #11852 with port, telekom.de */
tuning.m_data_url = QUrl (QString("rtp://@239.35.10.1:10000"));
tuning.m_protocol = IPTVTuningData::rtp;
tuning.SetDataURL(QUrl(QString("rtp://@239.35.10.1:10000")));
QVERIFY (tuning.IsValid());
QVERIFY (tuning.IsRTP());

/* test url from das-erste.de with port, telekom.de */
tuning.m_data_url = QUrl (QString("rtp://239.35.10.4:10000"));
tuning.m_protocol = IPTVTuningData::rtp;
tuning.SetDataURL(QUrl(QString("rtp://239.35.10.4:10000")));
QVERIFY (tuning.IsValid());
QVERIFY (tuning.IsRTP());

/* test url from #11847 with port, Dreambox */
tuning.m_data_url = QUrl (QString("http://yourdreambox:8001/1:0:1:488:3FE:22F1:EEEE0000:0:0:0:"));
tuning.m_protocol = IPTVTuningData::http_ts;
tuning.SetDataURL(QUrl(QString("http://yourdreambox:8001/1:0:1:488:3FE:22F1:EEEE0000:0:0:0:")));
QVERIFY (tuning.IsValid());
QVERIFY (tuning.IsHTTPTS());
}


Expand All @@ -76,14 +77,19 @@ class TestIPTVRecorder: public QObject
IPTVTuningData tuning;

/* test url from http://www.tldp.org/HOWTO/VideoLAN-HOWTO/x549.html */
tuning.m_data_url = QUrl (QString("udp:@239.255.12.42"));
tuning.SetDataURL(QUrl(QString("udp:@239.255.12.42")));
QVERIFY (tuning.IsValid());
QVERIFY (tuning.IsUDP());

/* test url from http://www.tldp.org/HOWTO/VideoLAN-HOWTO/x1245.html */
tuning.m_data_url = QUrl (QString("udp:@[ff08::1]"));
tuning.SetDataURL(QUrl(QString("udp:@[ff08::1]")));
QVERIFY (tuning.IsValid());
QVERIFY (tuning.IsUDP());

/* test url from http://www.tldp.org/HOWTO/VideoLAN-HOWTO/x1245.html */
tuning.m_data_url = QUrl (QString("udp:[ff08::1%eth0]"));
tuning.SetDataURL(QUrl(QString("udp:[ff08::1%eth0]")));
QVERIFY (tuning.IsValid());
QVERIFY (tuning.IsUDP());
}

/**
Expand Down Expand Up @@ -130,7 +136,6 @@ class TestIPTVRecorder: public QObject
QCOMPARE (chanmap["001"].m_name, QString ("La 1"));
QVERIFY (chanmap["001"].IsValid ());
QVERIFY (chanmap["001"].m_tuning.IsValid ());
QCOMPARE (chanmap["001"].m_tuning.m_data_url.toString(), QString ("udp://239.0.0.76:8208"));
QCOMPARE (chanmap["001"].m_tuning.GetDataURL().toString(), QString ("udp://239.0.0.76:8208"));

/* test playlist for Neutrino STBs */
Expand All @@ -140,7 +145,7 @@ class TestIPTVRecorder: public QObject
QCOMPARE (chanmap["1"].m_name, QString ("SVT1 HD Mitt"));
QCOMPARE (chanmap["1"].m_xmltvid, QString ("svt1hd.svt.se"));
QCOMPARE (chanmap["1"].m_programNumber, (uint) 1330);
QCOMPARE (chanmap["1"].m_tuning.m_data_url.toString(), QString ("http://192.168.0.234:8001/1:0:19:532:6:22F1:EEEE0000:0:0:0:"));
QCOMPARE (chanmap["1"].m_tuning.GetDataURL().toString(), QString ("http://192.168.0.234:8001/1:0:19:532:6:22F1:EEEE0000:0:0:0:"));

/* test playlist for FreeboxTV, last channel in playlist "wins" */
chanmap = IPTVChannelFetcher::ParsePlaylist (rawdataRTSP, NULL);
Expand Down

0 comments on commit f2c04ca

Please sign in to comment.