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

99 lines
3.1 KiB
C
Raw 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
{
2013-02-23 16:12:46 +01:00
debug("cSidScanner::%s()", __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()
{
2013-02-23 16:12:46 +01:00
debug("cSidScanner::%s()", __FUNCTION__);
}
2013-02-23 14:31:11 +01:00
void cSidScanner::SetChannel(const tChannelID &channelIdP)
2007-09-29 01:23:12 +02:00
{
2013-02-23 16:12:46 +01:00
debug("cSidScanner::%s(%s)", __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;
2013-02-23 16:12:46 +01:00
//debug("cSidScanner::%s()", __FUNCTION__);
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)) {
2013-02-23 16:12:46 +01:00
debug("cSidScanner::%s(%d, %02X)", __FUNCTION__, pidP, tidP);
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()) {
2013-02-23 16:12:46 +01:00
debug("cSidScanner::%s(): sid=%d", __FUNCTION__, 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)) {
2013-02-23 16:12:46 +01:00
debug("cSidScanner::%s(%d, %02X)", __FUNCTION__, pidP, tidP);
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()) {
2013-02-23 16:12:46 +01:00
debug("cSidScanner::%s(): tsid=%d", __FUNCTION__, ts.getTransportStreamId());
newTid = ts.getTransportStreamId();
2007-09-29 01:23:12 +02:00
}
2013-02-23 14:31:11 +01:00
tidFoundM = true;
break; // default to the first one
2007-09-29 01:23:12 +02:00
}
2013-02-23 14:31:11 +01:00
if (nit.getNetworkId() != channelIdM.Nid()) {
2013-02-23 16:12:46 +01:00
debug("cSidScanner::%s(): nid=%d\n", __FUNCTION__, ts.getTransportStreamId());
newNid = nit.getNetworkId();
}
2013-02-23 14:31:11 +01:00
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
}
}