1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00
vdr-plugin-iptv/sidscanner.c

105 lines
3.5 KiB
C
Raw Permalink Normal View History

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
Set(0x10, 0x40); // NIT
2007-09-29 01:23:12 +02:00
}
cSidScanner::~cSidScanner()
{
2015-03-08 13:33:18 +01:00
debug1("%s", __PRETTY_FUNCTION__);
}
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
{
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);
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());
newSid = assoc.getServiceId();
}
2013-02-23 14:31:11 +01:00
sidFoundM = true;
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);
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());
newTid = ts.getTransportStreamId();
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());
newNid = ts.getOriginalNetworkId();
nidFoundM = true;
2007-09-29 01:23:12 +02:00
}
break; // default to the first one
2007-09-29 01:23:12 +02: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());
newNid = nit.getNetworkId();
nidFoundM = true;
}
}
}
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);
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) {
SetChannel(tChannelID::InvalidID);
SetStatus(false);
2007-09-29 01:23:12 +02:00
}
}