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

103 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)
2007-09-29 01:23:12 +02:00
{
2007-10-01 20:14:57 +02:00
debug("cSidScanner::cSidScanner()\n");
2007-09-29 01:23:12 +02:00
channel = cChannel();
sidFound = false;
nidFound = false;
tidFound = false;
2007-09-29 01:23:12 +02:00
Set(0x00, 0x00); // PAT
Set(0x10, 0x40); // NIT
2007-09-29 01:23:12 +02:00
}
2007-10-01 20:14:57 +02:00
void cSidScanner::SetStatus(bool On)
2007-09-29 01:23:12 +02:00
{
2007-10-01 20:14:57 +02:00
debug("cSidScanner::SetStatus(): %d\n", On);
2007-09-29 01:23:12 +02:00
cFilter::SetStatus(On);
}
2007-10-01 20:14:57 +02:00
void cSidScanner::SetChannel(const cChannel *Channel)
2007-09-29 01:23:12 +02:00
{
sidFound = false;
nidFound = false;
tidFound = false;
2007-09-29 01:23:12 +02:00
if (Channel) {
2010-03-04 16:34:21 +01:00
debug("cSidScanner::SetChannel(): %s\n", Channel->Parameters());
2007-09-29 01:23:12 +02:00
channel = *Channel;
}
else {
2007-10-01 20:14:57 +02:00
debug("cSidScanner::SetChannel()\n");
2007-09-29 01:23:12 +02:00
channel = cChannel();
}
}
2007-10-01 20:14:57 +02:00
void cSidScanner::Process(u_short Pid, u_char Tid, const u_char *Data, int Length)
2007-09-29 01:23:12 +02:00
{
int newSid = -1, newNid = -1, newTid = -1;
2007-10-01 20:14:57 +02:00
//debug("cSidScanner::Process()\n");
if (channel.GetChannelID().Valid()) {
if ((Pid == 0x00) && (Tid == 0x00)) {
debug("cSidScanner::Process(): Pid=%d Tid=%02X\n", Pid, Tid);
SI::PAT pat(Data, false);
if (!pat.CheckCRCAndParse())
return;
SI::PAT::Association assoc;
for (SI::Loop::Iterator it; pat.associationLoop.getNext(assoc, it); ) {
if (!assoc.isNITPid()) {
if (assoc.getServiceId() != channel.Sid()) {
debug("cSidScanner::Process(): Sid=%d\n", assoc.getServiceId());
newSid = assoc.getServiceId();
}
sidFound = true;
break;
}
}
}
else if ((Pid == 0x10) && (Tid == 0x40)) {
debug("cSidScanner::Process(): Pid=%d Tid=%02X\n", Pid, Tid);
SI::NIT nit(Data, false);
if (!nit.CheckCRCAndParse())
return;
SI::NIT::TransportStream ts;
for (SI::Loop::Iterator it; nit.transportStreamLoop.getNext(ts, it); ) {
if (ts.getTransportStreamId() != channel.Tid()) {
debug("cSidScanner::Process(): TSid=%d\n", ts.getTransportStreamId());
newTid = ts.getTransportStreamId();
2007-09-29 01:23:12 +02:00
}
tidFound = true;
break; // default to the first one
2007-09-29 01:23:12 +02:00
}
if (nit.getNetworkId() != channel.Nid()) {
debug("cSidScanner::Process(): Nid=%d\n", ts.getTransportStreamId());
newNid = nit.getNetworkId();
}
nidFound = true;
}
}
if ((newSid >= 0) || (newNid >= 0) || (newTid >= 0)) {
if (!Channels.Lock(true, 10))
return;
cChannel *IptvChannel = Channels.GetByChannelID(channel.GetChannelID());
if (IptvChannel)
IptvChannel->SetId((newNid < 0) ? IptvChannel->Nid() : newNid, (newTid < 0) ? IptvChannel->Tid() : newTid,
(newSid < 0) ? IptvChannel->Sid() : newSid, IptvChannel->Rid());
Channels.Unlock();
}
if (sidFound && nidFound && tidFound) {
SetChannel(NULL);
SetStatus(false);
2007-09-29 01:23:12 +02:00
}
}