Permalink
Browse files

Add IPTV Channel URLs to DB.

  • Loading branch information...
daniel-kristjansson committed Mar 9, 2012
1 parent 612fdb6 commit f3e37ed3cc1835eb791e1e06d3cf3b19fa7801d7
@@ -114,7 +114,7 @@ package MythTV;
# schema version supported in the main code. We need to check that the schema
# version in the database is as expected by the bindings, which are expected
# to be kept in sync with the main code.
our $SCHEMA_VERSION = "1299";
our $SCHEMA_VERSION = "1300";
# NUMPROGRAMLINES is defined in mythtv/libs/libmythtv/programinfo.h and is
# the number of items in a ProgramInfo QStringList group used by
@@ -5,7 +5,7 @@
"""
OWN_VERSION = (0,25,-1,3)
SCHEMA_VERSION = 1299
SCHEMA_VERSION = 1300
NVSCHEMA_VERSION = 1007
MUSICSCHEMA_VERSION = 1018
PROTO_VERSION = '72'
@@ -57,7 +57,7 @@
* mythtv/bindings/php/MythBackend.php
#endif
#define MYTH_DATABASE_VERSION "1299"
#define MYTH_DATABASE_VERSION "1300"
MBASE_PUBLIC const char *GetMythSourceVersion();
@@ -31,6 +31,7 @@
using namespace std;
#include "analogsignalmonitor.h"
#include "iptvchannelfetcher.h"
#include "dvbsignalmonitor.h"
#include "scanwizardconfig.h"
#include "channelscan_sm.h"
@@ -45,7 +46,7 @@ using namespace std;
#define LOC QString("ChScan: ")
ChannelScanner::ChannelScanner() :
scanMonitor(NULL), channel(NULL), sigmonScanner(NULL),
scanMonitor(NULL), channel(NULL), sigmonScanner(NULL), iptvScanner(NULL),
freeToAirOnly(false), serviceRequirements(kRequireAV)
{
}
@@ -75,6 +76,13 @@ void ChannelScanner::Teardown(void)
channel = NULL;
}
if (iptvScanner)
{
iptvScanner->Stop();
delete iptvScanner;
iptvScanner = NULL;
}
if (scanMonitor)
{
scanMonitor->deleteLater();
@@ -264,6 +272,27 @@ DTVConfParser::return_t ChannelScanner::ImportDVBUtils(
return ret;
}
bool ChannelScanner::ImportM3U(
uint cardid, const QString &inputname, uint sourceid)
{
(void) cardid;
(void) inputname;
(void) sourceid;
if (!scanMonitor)
scanMonitor = new ScanMonitor(this);
// Create an IPTV scan object
iptvScanner = new IPTVChannelFetcher(
cardid, inputname, sourceid, scanMonitor);
MonitorProgress(false, false, false, false);
iptvScanner->Scan();
return true;
}
void ChannelScanner::PreScanCommon(
int scantype,
uint cardid,
@@ -37,6 +37,7 @@
#include "channelscantypes.h"
class ScanMonitor;
class IPTVChannelFetcher;
class ChannelScanSM;
class ChannelBase;
@@ -73,6 +74,9 @@ class MTV_PUBLIC ChannelScanner
virtual DTVConfParser::return_t ImportDVBUtils(
uint sourceid, int cardtype, const QString &file);
virtual bool ImportM3U(uint cardid, const QString &inputname,
uint sourceid);
protected:
virtual void Teardown(void);
@@ -94,6 +98,7 @@ class MTV_PUBLIC ChannelScanner
// Low level channel scanners
ChannelScanSM *sigmonScanner;
IPTVChannelFetcher *iptvScanner;
/// imported channels
DTVChannelList channels;
@@ -68,7 +68,7 @@ void ChannelScannerCLI::HandleEvent(const ScannerEvent *scanEvent)
Teardown();
if (!transports.empty())
if (sigmonScanner && !transports.empty())
Process(transports);
done = true;
@@ -115,8 +115,11 @@ void ChannelScannerGUI::HandleEvent(const ScannerEvent *scanEvent)
Teardown();
int ret = scanEvent->intValue();
if (!transports.empty() || (MythDialog::Rejected != ret))
if (sigmonScanner &&
(!transports.empty() || (MythDialog::Rejected != ret)))
{
Process(transports);
}
}
else if (scanEvent->type() == ScannerEvent::AppendTextToLog)
{
@@ -1731,6 +1731,64 @@ void ChannelUtil::UpdateInsertInfoFromDB(ChannelInsertInfo &chan)
}
}
bool ChannelUtil::UpdateIPTVTuningData(
uint channel_id, const IPTVTuningData &tuning)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"DELETE FROM iptv_channel "
"WHERE chanid=:CHANID");
query.bindValue(":CHANID", channel_id);
if (!query.exec())
{
MythDB::DBError("UpdateIPTVTuningData -- delete", query);
return false;
}
query.prepare(
"INSERT INTO iptv_channel (chanid, url, type, bitrate) "
"VALUES (:CHANID, :URL, :TYPE, :BITRATE)");
query.bindValue(":CHANID", channel_id);
query.bindValue(":URL", tuning.GetDataURL().toString());
query.bindValue(":TYPE", tuning.GetFECTypeString(0));
query.bindValue(":BITRATE", tuning.GetBitrate(0));
if (!query.exec())
{
MythDB::DBError("UpdateIPTVTuningData -- data", query);
return false;
}
if (tuning.GetFECURL0().port() >= 0)
{
query.bindValue(":URL", tuning.GetFECURL0().toString());
query.bindValue(":TYPE", tuning.GetFECTypeString(1));
query.bindValue(":BITRATE", tuning.GetBitrate(1));
if (!query.exec())
{
MythDB::DBError("UpdateIPTVTuningData -- fec 0", query);
return false;
}
}
if (tuning.GetFECURL1().port() >= 0)
{
query.bindValue(":URL", tuning.GetFECURL1().toString());
query.bindValue(":TYPE", tuning.GetFECTypeString(2));
query.bindValue(":BITRATE", tuning.GetBitrate(2));
if (!query.exec())
{
MythDB::DBError("UpdateIPTVTuningData -- fec 1", query);
return false;
}
}
return true;
}
bool ChannelUtil::DeleteChannel(uint channel_id)
{
MSqlQuery query(MSqlQuery::InitCon());
@@ -1745,6 +1803,17 @@ bool ChannelUtil::DeleteChannel(uint channel_id)
return false;
}
query.prepare(
"DELETE FROM iptv_channel "
"WHERE chanid = :ID");
query.bindValue(":ID", channel_id);
if (!query.exec())
{
MythDB::DBError("Delete Channel 2", query);
return false;
}
return true;
}
@@ -1970,6 +2039,71 @@ bool ChannelUtil::GetExtendedChannelData(
dvb_transportid, dvb_networkid, dtv_si_std);
}
IPTVTuningData ChannelUtil::GetIPTVTuningData(uint chanid)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"SELECT type+0, url, bitrate "
"FROM iptv_channel "
"WHERE chanid = :CHANID "
"ORDER BY type+0");
query.bindValue(":CHANID", chanid);
if (!query.exec())
{
MythDB::DBError("GetChannelData -- iptv", query);
return IPTVTuningData();
}
QString data_url, fec_url0, fec_url1;
IPTVTuningData::FECType fec_type = IPTVTuningData::kNone;
uint bitrate[3] = { 0, 0, 0, };
while (query.next())
{
IPTVTuningData::IPTVType type = (IPTVTuningData::IPTVType)
query.value(0).toUInt();
switch (type)
{
case IPTVTuningData::kData:
data_url = query.value(1).toString();
bitrate[0] = query.value(2).toUInt();
break;
case IPTVTuningData::kRFC2733_1:
case IPTVTuningData::kRFC5109_1:
case IPTVTuningData::kSMPTE2022_1:
fec_url0 = query.value(1).toString();
bitrate[1] = query.value(2).toUInt();
break;
case IPTVTuningData::kRFC2733_2:
case IPTVTuningData::kRFC5109_2:
case IPTVTuningData::kSMPTE2022_2:
fec_url1 = query.value(1).toString();
bitrate[2] = query.value(2).toUInt();
break;
}
switch (type)
{
case IPTVTuningData::kData:
break;
case IPTVTuningData::kRFC2733_1:
fec_type = IPTVTuningData::kRFC2733;
break;
case IPTVTuningData::kRFC5109_1:
fec_type = IPTVTuningData::kRFC5109;
break;
case IPTVTuningData::kSMPTE2022_1:
fec_type = IPTVTuningData::kSMPTE2022;
break;
}
}
IPTVTuningData tuning(data_url, bitrate[0], fec_type,
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;
}
DBChanList ChannelUtil::GetChannelsInternal(
uint sourceid, bool vis_only, bool include_disconnected,
const QString &grp, uint changrpid)
@@ -17,6 +17,7 @@ using namespace std;
#include "mythtvexp.h"
#include "dtvmultiplex.h"
#include "dbchannelinfo.h"
#include "iptvtuningdata.h"
class NetworkInformationTable;
@@ -134,6 +135,15 @@ class MTV_PUBLIC ChannelUtil
QString xmltvid = QString::null,
QString default_authority = QString::null);
static bool CreateIPTVTuningData(
uint channel_id, const IPTVTuningData &tuning)
{
return UpdateIPTVTuningData(channel_id, tuning);
}
static bool UpdateIPTVTuningData(
uint channel_id, const IPTVTuningData &tuning);
static void UpdateInsertInfoFromDB(ChannelInsertInfo &chan);
static bool DeleteChannel(uint channel_id);
@@ -181,6 +191,7 @@ class MTV_PUBLIC ChannelUtil
{ return GetChannelValueInt("serviceid", sourceid, channum); }
static QString GetVideoFilters(uint sourceid, const QString &channum)
{ return GetChannelValueStr("videofilters", sourceid, channum); }
static IPTVTuningData GetIPTVTuningData(uint chanid);
static DBChanList GetChannels(
uint sourceid, bool visible_only,
@@ -6284,6 +6284,28 @@ NULL
return false;
}
if (dbver == "1299")
{
const char *updates[] = {
"ALTER TABLE channel ADD COLUMN iptvid SMALLINT(6) UNSIGNED;",
"CREATE TABLE iptv_channel ("
" iptvid SMALLINT(6) UNSIGNED NOT NULL auto_increment,"
" chanid INT(10) UNSIGNED NOT NULL,"
" url TEXT NOT NULL,"
" type set('data', "
" 'rfc2733-1','rfc2733-2', "
" 'rfc5109-1','rfc5109-2', "
" 'smpte2022-1','smpte2022-2'),"
" bitrate INT(10) UNSIGNED NOT NULL,"
" PRIMARY KEY (iptvid)"
") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
NULL
};
if (!performActualUpdate(updates, "1300", dbver))
return false;
}
return true;
}
@@ -287,8 +287,19 @@ bool DTVChannel::SetChannelByString(const QString &channum)
bool ok = true;
if ((*it)->externalChanger.isEmpty())
{
if ((*it)->name.contains("composite", Qt::CaseInsensitive) ||
(*it)->name.contains("s-video", Qt::CaseInsensitive))
if (IsIPTV())
{
int chanid = ChannelUtil::GetChanID((*it)->sourceid, channum);
IPTVTuningData tuning = ChannelUtil::GetIPTVTuningData(chanid);
if (!Tune(tuning))
{
LOG(VB_GENERAL, LOG_ERR, loc + "Tuning to IPTV URL");
ClearDTVInfo();
ok = false;
}
}
else if ((*it)->name.contains("composite", Qt::CaseInsensitive) ||
(*it)->name.contains("s-video", Qt::CaseInsensitive))
{
LOG(VB_GENERAL, LOG_WARNING, loc + "You have not set "
"an external channel changing"
@@ -22,7 +22,7 @@ using namespace std;
// MythTV headers
#include "dtvconfparserhelpers.h" // for DTVTunerType
#include "channelbase.h"
#include "channelutil.h" // for pid_cache_t
#include "channelutil.h" // for pid_cache_t, IPTVTuningData
class ProgramAssociationTable;
class ProgramMapTable;
@@ -49,6 +49,8 @@ class DTVChannel : public ChannelBase
/// are in the same MPTS stream on the same input. But generally you
/// will need to implement this when adding support for new hardware.
virtual bool Tune(const DTVMultiplex &tuning, QString inputname) = 0;
/// \brief Performs IPTV Tuning. Only implemented by IPTVChannel.
virtual bool Tune(const IPTVTuningData&) { return false; }
/// \brief Enters power saving mode if the card supports it
virtual bool EnterPowerSavingMode(void)
{
@@ -119,6 +121,8 @@ class DTVChannel : public ChannelBase
virtual bool IsPIDTuningSupported(void) const { return false; }
virtual bool IsIPTV(void) const { return false; }
bool HasGeneratedPAT(void) const { return genPAT != NULL; }
bool HasGeneratedPMT(void) const { return genPMT != NULL; }
const ProgramAssociationTable *GetGeneratedPAT(void) const {return genPAT;}
Oops, something went wrong.

0 comments on commit f3e37ed

Please sign in to comment.