2007-09-29 01:23:12 +02:00
|
|
|
/*
|
2007-10-01 20:14:57 +02:00
|
|
|
* sidscanner.c: IPTV plugin for the Video Disk Recorder
|
2007-09-29 01:23:12 +02:00
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libsi/section.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
2007-10-01 20:14:57 +02:00
|
|
|
#include "sidscanner.h"
|
2007-09-29 01:23:12 +02:00
|
|
|
|
2007-10-01 20:14:57 +02:00
|
|
|
cSidScanner::cSidScanner(void)
|
2013-02-23 14:31:11 +01:00
|
|
|
: channelIdM(tChannelID::InvalidID),
|
|
|
|
sidFoundM(false),
|
|
|
|
nidFoundM(false),
|
2013-02-25 23:34:45 +01:00
|
|
|
tidFoundM(false),
|
|
|
|
isActiveM(false)
|
2007-09-29 01:23:12 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2007-09-29 01:23:12 +02:00
|
|
|
Set(0x00, 0x00); // PAT
|
2010-07-02 14:54:32 +02:00
|
|
|
Set(0x10, 0x40); // NIT
|
2007-09-29 01:23:12 +02:00
|
|
|
}
|
|
|
|
|
2010-11-29 20:09:17 +01:00
|
|
|
cSidScanner::~cSidScanner()
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2010-11-29 20:09:17 +01:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
void cSidScanner::SetChannel(const tChannelID &channelIdP)
|
2007-09-29 01:23:12 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s (%s)", __PRETTY_FUNCTION__, *channelIdP.ToString());
|
2013-02-23 14:31:11 +01:00
|
|
|
channelIdM = channelIdP;
|
|
|
|
sidFoundM = false;
|
|
|
|
nidFoundM = false;
|
|
|
|
tidFoundM = false;
|
2007-09-29 01:23:12 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
void cSidScanner::Process(u_short pidP, u_char tidP, const u_char *dataP, int lengthP)
|
2007-09-29 01:23:12 +02:00
|
|
|
{
|
2010-07-02 14:54:32 +02:00
|
|
|
int newSid = -1, newNid = -1, newTid = -1;
|
|
|
|
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d, %02X, , %d)", __PRETTY_FUNCTION__, pidP, tidP, lengthP);
|
2013-02-25 23:34:45 +01:00
|
|
|
if (!isActiveM)
|
|
|
|
return;
|
2013-02-23 14:31:11 +01:00
|
|
|
if (channelIdM.Valid()) {
|
|
|
|
if ((pidP == 0x00) && (tidP == 0x00)) {
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d, %02X, , %d) pat", __PRETTY_FUNCTION__, pidP, tidP, lengthP);
|
2013-02-23 14:31:11 +01:00
|
|
|
SI::PAT pat(dataP, false);
|
2010-07-02 14:54:32 +02:00
|
|
|
if (!pat.CheckCRCAndParse())
|
|
|
|
return;
|
|
|
|
SI::PAT::Association assoc;
|
|
|
|
for (SI::Loop::Iterator it; pat.associationLoop.getNext(assoc, it); ) {
|
|
|
|
if (!assoc.isNITPid()) {
|
2013-02-23 14:31:11 +01:00
|
|
|
if (assoc.getServiceId() != channelIdM.Sid()) {
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s (%d, %02X, , %d) sid=%d", __PRETTY_FUNCTION__, pidP, tidP, lengthP, assoc.getServiceId());
|
2010-07-02 14:54:32 +02:00
|
|
|
newSid = assoc.getServiceId();
|
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
sidFoundM = true;
|
2010-07-02 14:54:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
else if ((pidP == 0x10) && (tidP == 0x40)) {
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s (%d, %02X, , %d)", __PRETTY_FUNCTION__, pidP, tidP, lengthP);
|
2013-02-23 14:31:11 +01:00
|
|
|
SI::NIT nit(dataP, false);
|
2010-07-02 14:54:32 +02:00
|
|
|
if (!nit.CheckCRCAndParse())
|
|
|
|
return;
|
|
|
|
SI::NIT::TransportStream ts;
|
|
|
|
for (SI::Loop::Iterator it; nit.transportStreamLoop.getNext(ts, it); ) {
|
2013-02-23 14:31:11 +01:00
|
|
|
if (ts.getTransportStreamId() != channelIdM.Tid()) {
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s (%d, %02X, , %d) tsid=%d", __PRETTY_FUNCTION__, pidP, tidP, lengthP, ts.getTransportStreamId());
|
2010-07-02 14:54:32 +02:00
|
|
|
newTid = ts.getTransportStreamId();
|
2014-01-02 20:35:38 +01:00
|
|
|
tidFoundM = true;
|
|
|
|
}
|
|
|
|
if (ts.getOriginalNetworkId() != channelIdM.Nid()) {
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s (%d, %02X, , %d) onid=%d", __PRETTY_FUNCTION__, pidP, tidP, lengthP, ts.getOriginalNetworkId());
|
2014-01-02 20:35:38 +01:00
|
|
|
newNid = ts.getOriginalNetworkId();
|
|
|
|
nidFoundM = true;
|
2007-09-29 01:23:12 +02:00
|
|
|
}
|
2010-07-02 14:54:32 +02:00
|
|
|
break; // default to the first one
|
2007-09-29 01:23:12 +02:00
|
|
|
}
|
2014-01-02 20:35:38 +01:00
|
|
|
// fallback for network id if not found already
|
|
|
|
if (!nidFoundM && (nit.getNetworkId() != channelIdM.Nid())) {
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s (%d, %02X, , %d) nid=%d", __PRETTY_FUNCTION__, pidP, tidP, lengthP, nit.getNetworkId());
|
2010-07-02 14:54:32 +02:00
|
|
|
newNid = nit.getNetworkId();
|
2014-01-02 20:35:38 +01:00
|
|
|
nidFoundM = true;
|
2010-07-02 14:54:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((newSid >= 0) || (newNid >= 0) || (newTid >= 0)) {
|
|
|
|
if (!Channels.Lock(true, 10))
|
|
|
|
return;
|
2013-02-23 14:31:11 +01:00
|
|
|
cChannel *IptvChannel = Channels.GetByChannelID(channelIdM);
|
2010-07-02 14:54:32 +02:00
|
|
|
if (IptvChannel)
|
|
|
|
IptvChannel->SetId((newNid < 0) ? IptvChannel->Nid() : newNid, (newTid < 0) ? IptvChannel->Tid() : newTid,
|
|
|
|
(newSid < 0) ? IptvChannel->Sid() : newSid, IptvChannel->Rid());
|
|
|
|
Channels.Unlock();
|
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
if (sidFoundM && nidFoundM && tidFoundM) {
|
2010-11-29 20:09:17 +01:00
|
|
|
SetChannel(tChannelID::InvalidID);
|
2010-07-02 14:54:32 +02:00
|
|
|
SetStatus(false);
|
2007-09-29 01:23:12 +02:00
|
|
|
}
|
|
|
|
}
|