2003-12-22 13:29:24 +01:00
|
|
|
/*
|
|
|
|
* pat.c: PAT section filter
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2019-03-11 13:21:17 +01:00
|
|
|
* $Id: pat.c 4.4 2019/03/11 13:20:27 kls Exp $
|
2003-12-22 13:29:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pat.h"
|
|
|
|
#include <malloc.h>
|
2004-01-04 12:30:00 +01:00
|
|
|
#include "channels.h"
|
2003-12-22 13:29:24 +01:00
|
|
|
#include "libsi/section.h"
|
|
|
|
#include "libsi/descriptor.h"
|
|
|
|
|
2014-02-18 13:12:39 +01:00
|
|
|
#define PMT_SCAN_TIMEOUT 1000 // ms
|
2003-12-22 13:29:24 +01:00
|
|
|
|
|
|
|
// --- cCaDescriptor ---------------------------------------------------------
|
|
|
|
|
|
|
|
class cCaDescriptor : public cListObject {
|
|
|
|
private:
|
|
|
|
int caSystem;
|
2014-01-01 12:37:22 +01:00
|
|
|
int caPid;
|
2009-08-15 22:19:42 +02:00
|
|
|
int esPid;
|
2003-12-22 13:29:24 +01:00
|
|
|
int length;
|
|
|
|
uchar *data;
|
|
|
|
public:
|
2009-08-15 22:19:42 +02:00
|
|
|
cCaDescriptor(int CaSystem, int CaPid, int EsPid, int Length, const uchar *Data);
|
2003-12-22 13:29:24 +01:00
|
|
|
virtual ~cCaDescriptor();
|
2004-01-04 12:30:00 +01:00
|
|
|
bool operator== (const cCaDescriptor &arg) const;
|
|
|
|
int CaSystem(void) { return caSystem; }
|
2014-01-01 12:37:22 +01:00
|
|
|
int CaPid(void) { return caPid; }
|
2009-08-15 22:19:42 +02:00
|
|
|
int EsPid(void) { return esPid; }
|
2003-12-22 13:29:24 +01:00
|
|
|
int Length(void) const { return length; }
|
|
|
|
const uchar *Data(void) const { return data; }
|
|
|
|
};
|
|
|
|
|
2009-08-15 22:19:42 +02:00
|
|
|
cCaDescriptor::cCaDescriptor(int CaSystem, int CaPid, int EsPid, int Length, const uchar *Data)
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
|
|
|
caSystem = CaSystem;
|
2014-01-01 12:37:22 +01:00
|
|
|
caPid = CaPid;
|
2009-08-15 22:19:42 +02:00
|
|
|
esPid = EsPid;
|
2003-12-22 13:29:24 +01:00
|
|
|
length = Length + 6;
|
|
|
|
data = MALLOC(uchar, length);
|
|
|
|
data[0] = SI::CaDescriptorTag;
|
|
|
|
data[1] = length - 2;
|
|
|
|
data[2] = (caSystem >> 8) & 0xFF;
|
|
|
|
data[3] = caSystem & 0xFF;
|
|
|
|
data[4] = ((CaPid >> 8) & 0x1F) | 0xE0;
|
|
|
|
data[5] = CaPid & 0xFF;
|
|
|
|
if (Length)
|
|
|
|
memcpy(&data[6], Data, Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
cCaDescriptor::~cCaDescriptor()
|
|
|
|
{
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
bool cCaDescriptor::operator== (const cCaDescriptor &arg) const
|
|
|
|
{
|
2009-08-15 22:19:42 +02:00
|
|
|
return esPid == arg.esPid && length == arg.length && memcmp(data, arg.data, length) == 0;
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
// --- cCaDescriptors --------------------------------------------------------
|
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
class cCaDescriptors : public cListObject {
|
2003-12-22 13:29:24 +01:00
|
|
|
private:
|
2004-01-04 12:30:00 +01:00
|
|
|
int source;
|
|
|
|
int transponder;
|
|
|
|
int serviceId;
|
2015-01-04 13:36:46 +01:00
|
|
|
int pmtPid; // needed for OctopusNet - otherwise irrelevant!
|
2004-01-04 12:30:00 +01:00
|
|
|
int numCaIds;
|
|
|
|
int caIds[MAXCAIDS + 1];
|
|
|
|
cList<cCaDescriptor> caDescriptors;
|
|
|
|
void AddCaId(int CaId);
|
2003-12-22 13:29:24 +01:00
|
|
|
public:
|
2015-01-04 13:36:46 +01:00
|
|
|
cCaDescriptors(int Source, int Transponder, int ServiceId, int PmtPid);
|
2004-01-04 12:30:00 +01:00
|
|
|
bool operator== (const cCaDescriptors &arg) const;
|
|
|
|
bool Is(int Source, int Transponder, int ServiceId);
|
|
|
|
bool Is(cCaDescriptors * CaDescriptors);
|
|
|
|
bool Empty(void) { return caDescriptors.Count() == 0; }
|
2009-08-15 22:19:42 +02:00
|
|
|
void AddCaDescriptor(SI::CaDescriptor *d, int EsPid);
|
2016-12-23 14:08:14 +01:00
|
|
|
void GetCaDescriptors(const int *CaSystemIds, cDynamicBuffer &Buffer, int EsPid);
|
2014-01-01 12:37:22 +01:00
|
|
|
int GetCaPids(const int *CaSystemIds, int BufSize, int *Pids);
|
2015-01-04 13:36:46 +01:00
|
|
|
const int GetPmtPid(void) { return pmtPid; };
|
2004-01-04 12:30:00 +01:00
|
|
|
const int *CaIds(void) { return caIds; }
|
2003-12-22 13:29:24 +01:00
|
|
|
};
|
|
|
|
|
2015-01-04 13:36:46 +01:00
|
|
|
cCaDescriptors::cCaDescriptors(int Source, int Transponder, int ServiceId, int PmtPid)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
|
|
|
source = Source;
|
|
|
|
transponder = Transponder;
|
|
|
|
serviceId = ServiceId;
|
2015-01-04 13:36:46 +01:00
|
|
|
pmtPid = PmtPid;
|
2004-01-04 12:30:00 +01:00
|
|
|
numCaIds = 0;
|
|
|
|
caIds[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cCaDescriptors::operator== (const cCaDescriptors &arg) const
|
|
|
|
{
|
2015-09-01 11:14:27 +02:00
|
|
|
const cCaDescriptor *ca1 = caDescriptors.First();
|
|
|
|
const cCaDescriptor *ca2 = arg.caDescriptors.First();
|
2004-01-04 12:30:00 +01:00
|
|
|
while (ca1 && ca2) {
|
|
|
|
if (!(*ca1 == *ca2))
|
|
|
|
return false;
|
|
|
|
ca1 = caDescriptors.Next(ca1);
|
|
|
|
ca2 = arg.caDescriptors.Next(ca2);
|
|
|
|
}
|
|
|
|
return !ca1 && !ca2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cCaDescriptors::Is(int Source, int Transponder, int ServiceId)
|
|
|
|
{
|
|
|
|
return source == Source && transponder == Transponder && serviceId == ServiceId;
|
|
|
|
}
|
|
|
|
|
2004-01-25 15:32:08 +01:00
|
|
|
bool cCaDescriptors::Is(cCaDescriptors *CaDescriptors)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
|
|
|
return Is(CaDescriptors->source, CaDescriptors->transponder, CaDescriptors->serviceId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cCaDescriptors::AddCaId(int CaId)
|
|
|
|
{
|
|
|
|
if (numCaIds < MAXCAIDS) {
|
|
|
|
for (int i = 0; i < numCaIds; i++) {
|
|
|
|
if (caIds[i] == CaId)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
caIds[numCaIds++] = CaId;
|
|
|
|
caIds[numCaIds] = 0;
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2009-08-15 22:19:42 +02:00
|
|
|
void cCaDescriptors::AddCaDescriptor(SI::CaDescriptor *d, int EsPid)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2009-08-15 22:19:42 +02:00
|
|
|
cCaDescriptor *nca = new cCaDescriptor(d->getCaType(), d->getCaPid(), EsPid, d->privateData.getLength(), d->privateData.getData());
|
2004-01-04 12:30:00 +01:00
|
|
|
for (cCaDescriptor *ca = caDescriptors.First(); ca; ca = caDescriptors.Next(ca)) {
|
|
|
|
if (*ca == *nca) {
|
|
|
|
delete nca;
|
2003-12-22 13:29:24 +01:00
|
|
|
return;
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
AddCaId(nca->CaSystem());
|
|
|
|
caDescriptors.Add(nca);
|
|
|
|
//#define DEBUG_CA_DESCRIPTORS 1
|
|
|
|
#ifdef DEBUG_CA_DESCRIPTORS
|
|
|
|
char buffer[1024];
|
|
|
|
char *q = buffer;
|
2009-08-15 22:19:42 +02:00
|
|
|
q += sprintf(q, "CAM: %04X %5d %5d %04X %04X -", source, transponder, serviceId, d->getCaType(), EsPid);
|
2004-01-04 12:30:00 +01:00
|
|
|
for (int i = 0; i < nca->Length(); i++)
|
|
|
|
q += sprintf(q, " %02X", nca->Data()[i]);
|
2010-01-01 15:44:52 +01:00
|
|
|
dsyslog("%s", buffer);
|
2004-01-04 12:30:00 +01:00
|
|
|
#endif
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2009-08-15 22:19:42 +02:00
|
|
|
// EsPid is to select the "type" of CaDescriptor to be returned
|
|
|
|
// >0 - CaDescriptor for the particular esPid
|
|
|
|
// =0 - common CaDescriptor
|
|
|
|
// <0 - all CaDescriptors regardless of type (old default)
|
|
|
|
|
2016-12-23 14:08:14 +01:00
|
|
|
void cCaDescriptors::GetCaDescriptors(const int *CaSystemIds, cDynamicBuffer &Buffer, int EsPid)
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
2016-12-23 14:08:14 +01:00
|
|
|
Buffer.Clear();
|
2003-12-22 13:29:24 +01:00
|
|
|
if (!CaSystemIds || !*CaSystemIds)
|
2016-12-23 14:08:14 +01:00
|
|
|
return;
|
|
|
|
for (cCaDescriptor *d = caDescriptors.First(); d; d = caDescriptors.Next(d)) {
|
|
|
|
if (EsPid < 0 || d->EsPid() == EsPid) {
|
|
|
|
const int *caids = CaSystemIds;
|
|
|
|
do {
|
|
|
|
if (*caids == 0xFFFF || d->CaSystem() == *caids)
|
|
|
|
Buffer.Append(d->Data(), d->Length());
|
|
|
|
} while (*++caids);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
2016-12-23 14:08:14 +01:00
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2014-01-01 12:37:22 +01:00
|
|
|
int cCaDescriptors::GetCaPids(const int *CaSystemIds, int BufSize, int *Pids)
|
|
|
|
{
|
|
|
|
if (!CaSystemIds || !*CaSystemIds)
|
|
|
|
return 0;
|
|
|
|
if (BufSize > 0 && Pids) {
|
|
|
|
int numPids = 0;
|
|
|
|
for (cCaDescriptor *d = caDescriptors.First(); d; d = caDescriptors.Next(d)) {
|
|
|
|
const int *caids = CaSystemIds;
|
|
|
|
do {
|
2014-01-04 11:17:24 +01:00
|
|
|
if (*caids == 0xFFFF || d->CaSystem() == *caids) {
|
2014-01-01 12:37:22 +01:00
|
|
|
if (numPids + 1 < BufSize) {
|
|
|
|
Pids[numPids++] = d->CaPid();
|
|
|
|
Pids[numPids] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} while (*++caids);
|
|
|
|
}
|
|
|
|
return numPids;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
// --- cCaDescriptorHandler --------------------------------------------------
|
|
|
|
|
|
|
|
class cCaDescriptorHandler : public cList<cCaDescriptors> {
|
|
|
|
private:
|
|
|
|
cMutex mutex;
|
|
|
|
public:
|
|
|
|
int AddCaDescriptors(cCaDescriptors *CaDescriptors);
|
|
|
|
// Returns 0 if this is an already known descriptor,
|
|
|
|
// 1 if it is an all new descriptor with actual contents,
|
|
|
|
// and 2 if an existing descriptor was changed.
|
2016-12-23 14:08:14 +01:00
|
|
|
void GetCaDescriptors(int Source, int Transponder, int ServiceId, const int *CaSystemIds, cDynamicBuffer &Buffer, int EsPid);
|
2014-01-01 12:37:22 +01:00
|
|
|
int GetCaPids(int Source, int Transponder, int ServiceId, const int *CaSystemIds, int BufSize, int *Pids);
|
2015-01-04 13:36:46 +01:00
|
|
|
int GetPmtPid(int Source, int Transponder, int ServiceId);
|
2004-01-04 12:30:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
int cCaDescriptorHandler::AddCaDescriptors(cCaDescriptors *CaDescriptors)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
for (cCaDescriptors *ca = First(); ca; ca = Next(ca)) {
|
|
|
|
if (ca->Is(CaDescriptors)) {
|
|
|
|
if (*ca == *CaDescriptors) {
|
|
|
|
delete CaDescriptors;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Del(ca);
|
|
|
|
Add(CaDescriptors);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Add(CaDescriptors);
|
|
|
|
return CaDescriptors->Empty() ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2016-12-23 14:08:14 +01:00
|
|
|
void cCaDescriptorHandler::GetCaDescriptors(int Source, int Transponder, int ServiceId, const int *CaSystemIds, cDynamicBuffer &Buffer, int EsPid)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
for (cCaDescriptors *ca = First(); ca; ca = Next(ca)) {
|
2016-12-23 14:08:14 +01:00
|
|
|
if (ca->Is(Source, Transponder, ServiceId)) {
|
|
|
|
ca->GetCaDescriptors(CaSystemIds, Buffer, EsPid);
|
|
|
|
break;
|
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-01 12:37:22 +01:00
|
|
|
int cCaDescriptorHandler::GetCaPids(int Source, int Transponder, int ServiceId, const int *CaSystemIds, int BufSize, int *Pids)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
for (cCaDescriptors *ca = First(); ca; ca = Next(ca)) {
|
|
|
|
if (ca->Is(Source, Transponder, ServiceId))
|
|
|
|
return ca->GetCaPids(CaSystemIds, BufSize, Pids);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-04 13:36:46 +01:00
|
|
|
int cCaDescriptorHandler::GetPmtPid(int Source, int Transponder, int ServiceId)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
for (cCaDescriptors *ca = First(); ca; ca = Next(ca)) {
|
|
|
|
if (ca->Is(Source, Transponder, ServiceId))
|
|
|
|
return ca->GetPmtPid();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
cCaDescriptorHandler CaDescriptorHandler;
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2016-12-23 14:08:14 +01:00
|
|
|
void GetCaDescriptors(int Source, int Transponder, int ServiceId, const int *CaSystemIds, cDynamicBuffer &Buffer, int EsPid)
|
2003-12-22 13:29:24 +01:00
|
|
|
{
|
2016-12-23 14:08:14 +01:00
|
|
|
CaDescriptorHandler.GetCaDescriptors(Source, Transponder, ServiceId, CaSystemIds, Buffer, EsPid);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
2014-01-01 12:37:22 +01:00
|
|
|
int GetCaPids(int Source, int Transponder, int ServiceId, const int *CaSystemIds, int BufSize, int *Pids)
|
|
|
|
{
|
|
|
|
return CaDescriptorHandler.GetCaPids(Source, Transponder, ServiceId, CaSystemIds, BufSize, Pids);
|
|
|
|
}
|
|
|
|
|
2015-01-04 13:36:46 +01:00
|
|
|
int GetPmtPid(int Source, int Transponder, int ServiceId)
|
|
|
|
{
|
|
|
|
return CaDescriptorHandler.GetPmtPid(Source, Transponder, ServiceId);
|
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
// --- cPatFilter ------------------------------------------------------------
|
|
|
|
|
2014-02-18 13:12:39 +01:00
|
|
|
//#define DEBUG_PAT_PMT
|
|
|
|
#ifdef DEBUG_PAT_PMT
|
|
|
|
#define DBGLOG(a...) { cString s = cString::sprintf(a); fprintf(stderr, "%s\n", *s); dsyslog("%s", *s); }
|
|
|
|
#else
|
|
|
|
#define DBGLOG(a...)
|
|
|
|
#endif
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
cPatFilter::cPatFilter(void)
|
|
|
|
{
|
2014-02-18 13:12:39 +01:00
|
|
|
Trigger(0);
|
2003-12-22 13:29:24 +01:00
|
|
|
Set(0x00, 0x00); // PAT
|
|
|
|
}
|
|
|
|
|
|
|
|
void cPatFilter::SetStatus(bool On)
|
|
|
|
{
|
2014-02-18 13:12:39 +01:00
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
DBGLOG("PAT filter set status %d", On);
|
2003-12-22 13:29:24 +01:00
|
|
|
cFilter::SetStatus(On);
|
2014-02-18 13:12:39 +01:00
|
|
|
Trigger();
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
|
2014-02-18 13:12:39 +01:00
|
|
|
void cPatFilter::Trigger(int Sid)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2014-02-18 13:12:39 +01:00
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
patVersion = -1;
|
|
|
|
pmtIndex = -1;
|
2004-01-04 12:30:00 +01:00
|
|
|
numPmtEntries = 0;
|
2014-02-18 13:12:39 +01:00
|
|
|
if (Sid >= 0) {
|
|
|
|
sid = Sid;
|
|
|
|
DBGLOG("PAT filter trigger SID %d", Sid);
|
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
|
2014-02-18 13:12:39 +01:00
|
|
|
bool cPatFilter::PmtVersionChanged(int PmtPid, int Sid, int Version, bool SetNewVersion)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2014-02-18 13:12:39 +01:00
|
|
|
int Id = MakePmtId(PmtPid, Sid);
|
2004-01-04 12:30:00 +01:00
|
|
|
for (int i = 0; i < numPmtEntries; i++) {
|
2014-02-18 13:12:39 +01:00
|
|
|
if (pmtId[i] == Id) {
|
|
|
|
if (pmtVersion[i] != Version) {
|
|
|
|
if (SetNewVersion)
|
|
|
|
pmtVersion[i] = Version;
|
|
|
|
else
|
|
|
|
DBGLOG("PMT %d %2d %5d %2d -> %2d", Transponder(), i, PmtPid, pmtVersion[i], Version);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 13:12:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cPatFilter::SwitchToNextPmtPid(void)
|
|
|
|
{
|
|
|
|
if (pmtIndex >= 0) {
|
|
|
|
Del(GetPmtPid(pmtIndex), SI::TableIdPMT);
|
|
|
|
pmtIndex = (pmtIndex + 1) % numPmtEntries;
|
|
|
|
Add(GetPmtPid(pmtIndex), SI::TableIdPMT);
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cPatFilter::Process(u_short Pid, u_char Tid, const u_char *Data, int Length)
|
|
|
|
{
|
2014-02-18 13:12:39 +01:00
|
|
|
cMutexLock MutexLock(&mutex);
|
2003-12-22 13:29:24 +01:00
|
|
|
if (Pid == 0x00) {
|
2014-02-18 13:12:39 +01:00
|
|
|
if (Tid == SI::TableIdPAT) {
|
|
|
|
SI::PAT pat(Data, false);
|
|
|
|
if (!pat.CheckCRCAndParse())
|
|
|
|
return;
|
|
|
|
if (pat.getVersionNumber() != patVersion) {
|
2014-02-19 08:57:43 +01:00
|
|
|
DBGLOG("PAT %d %d -> %d", Transponder(), patVersion, pat.getVersionNumber());
|
2014-02-18 13:12:39 +01:00
|
|
|
if (pmtIndex >= 0) {
|
|
|
|
Del(GetPmtPid(pmtIndex), SI::TableIdPMT);
|
|
|
|
pmtIndex = -1;
|
|
|
|
}
|
|
|
|
numPmtEntries = 0;
|
2003-12-22 13:29:24 +01:00
|
|
|
SI::PAT::Association assoc;
|
2004-10-16 10:14:19 +02:00
|
|
|
for (SI::Loop::Iterator it; pat.associationLoop.getNext(assoc, it); ) {
|
2014-02-18 13:12:39 +01:00
|
|
|
if (!assoc.isNITPid() && numPmtEntries < MAXPMTENTRIES) {
|
|
|
|
DBGLOG(" PMT pid %2d %5d SID %5d", numPmtEntries, assoc.getPid(), assoc.getServiceId());
|
|
|
|
pmtId[numPmtEntries] = MakePmtId(assoc.getPid(), assoc.getServiceId());
|
|
|
|
pmtVersion[numPmtEntries] = -1;
|
|
|
|
if (sid == assoc.getServiceId()) {
|
|
|
|
pmtIndex = numPmtEntries;
|
|
|
|
DBGLOG("sid = %d pmtIndex = %d", sid, pmtIndex);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
2014-02-18 13:12:39 +01:00
|
|
|
numPmtEntries++;
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 13:12:39 +01:00
|
|
|
if (numPmtEntries > 0 && pmtIndex < 0)
|
2003-12-22 13:29:24 +01:00
|
|
|
pmtIndex = 0;
|
2019-03-11 13:21:17 +01:00
|
|
|
if (pmtIndex >= 0)
|
|
|
|
Add(GetPmtPid(pmtIndex), SI::TableIdPMT);
|
2014-02-18 13:12:39 +01:00
|
|
|
patVersion = pat.getVersionNumber();
|
|
|
|
timer.Set(PMT_SCAN_TIMEOUT);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-18 13:12:39 +01:00
|
|
|
else if (Tid == SI::TableIdPMT && Source() && Transponder()) {
|
|
|
|
timer.Set(PMT_SCAN_TIMEOUT);
|
2003-12-22 13:29:24 +01:00
|
|
|
SI::PMT pmt(Data, false);
|
|
|
|
if (!pmt.CheckCRCAndParse())
|
|
|
|
return;
|
2014-02-18 13:12:39 +01:00
|
|
|
if (!PmtVersionChanged(Pid, pmt.getTableIdExtension(), pmt.getVersionNumber())) {
|
|
|
|
SwitchToNextPmtPid();
|
2004-01-04 12:30:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-09-01 11:14:27 +02:00
|
|
|
cStateKey StateKey;
|
|
|
|
cChannels *Channels = cChannels::GetChannelsWrite(StateKey, 10);
|
|
|
|
if (!Channels)
|
2004-01-04 12:30:00 +01:00
|
|
|
return;
|
2015-09-01 11:14:27 +02:00
|
|
|
bool ChannelsModified = false;
|
2014-02-18 13:12:39 +01:00
|
|
|
PmtVersionChanged(Pid, pmt.getTableIdExtension(), pmt.getVersionNumber(), true);
|
|
|
|
SwitchToNextPmtPid();
|
2015-09-01 11:14:27 +02:00
|
|
|
cChannel *Channel = Channels->GetByServiceID(Source(), Transponder(), pmt.getServiceId());
|
2004-01-04 12:30:00 +01:00
|
|
|
if (Channel) {
|
|
|
|
SI::CaDescriptor *d;
|
2015-01-04 13:36:46 +01:00
|
|
|
cCaDescriptors *CaDescriptors = new cCaDescriptors(Channel->Source(), Channel->Transponder(), Channel->Sid(), Pid);
|
2004-01-04 12:30:00 +01:00
|
|
|
// Scan the common loop:
|
|
|
|
for (SI::Loop::Iterator it; (d = (SI::CaDescriptor*)pmt.commonDescriptors.getNext(it, SI::CaDescriptorTag)); ) {
|
2009-08-15 22:19:42 +02:00
|
|
|
CaDescriptors->AddCaDescriptor(d, 0);
|
2004-01-04 12:30:00 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
// Scan the stream-specific loop:
|
|
|
|
SI::PMT::Stream stream;
|
|
|
|
int Vpid = 0;
|
2008-08-15 14:49:34 +02:00
|
|
|
int Ppid = 0;
|
|
|
|
int Vtype = 0;
|
2005-08-06 12:29:38 +02:00
|
|
|
int Apids[MAXAPIDS + 1] = { 0 }; // these lists are zero-terminated
|
2010-06-13 11:14:26 +02:00
|
|
|
int Atypes[MAXAPIDS + 1] = { 0 };
|
2005-01-30 12:11:56 +01:00
|
|
|
int Dpids[MAXDPIDS + 1] = { 0 };
|
2010-06-05 13:50:56 +02:00
|
|
|
int Dtypes[MAXDPIDS + 1] = { 0 };
|
2007-10-12 14:52:30 +02:00
|
|
|
int Spids[MAXSPIDS + 1] = { 0 };
|
2009-08-16 15:32:39 +02:00
|
|
|
uchar SubtitlingTypes[MAXSPIDS + 1] = { 0 };
|
|
|
|
uint16_t CompositionPageIds[MAXSPIDS + 1] = { 0 };
|
|
|
|
uint16_t AncillaryPageIds[MAXSPIDS + 1] = { 0 };
|
2005-09-04 14:48:39 +02:00
|
|
|
char ALangs[MAXAPIDS][MAXLANGCODE2] = { "" };
|
|
|
|
char DLangs[MAXDPIDS][MAXLANGCODE2] = { "" };
|
2007-10-12 14:52:30 +02:00
|
|
|
char SLangs[MAXSPIDS][MAXLANGCODE2] = { "" };
|
2004-01-04 12:30:00 +01:00
|
|
|
int Tpid = 0;
|
|
|
|
int NumApids = 0;
|
|
|
|
int NumDpids = 0;
|
2007-10-12 14:52:30 +02:00
|
|
|
int NumSpids = 0;
|
2004-10-16 10:14:19 +02:00
|
|
|
for (SI::Loop::Iterator it; pmt.streamLoop.getNext(stream, it); ) {
|
2009-12-24 13:25:40 +01:00
|
|
|
bool ProcessCaDescriptors = false;
|
2009-08-15 22:19:42 +02:00
|
|
|
int esPid = stream.getPid();
|
2004-01-04 12:30:00 +01:00
|
|
|
switch (stream.getStreamType()) {
|
|
|
|
case 1: // STREAMTYPE_11172_VIDEO
|
|
|
|
case 2: // STREAMTYPE_13818_VIDEO
|
2012-11-25 14:21:15 +01:00
|
|
|
case 0x1B: // H.264
|
2016-12-22 12:22:11 +01:00
|
|
|
case 0x24: // H.265
|
2009-08-15 22:19:42 +02:00
|
|
|
Vpid = esPid;
|
2008-08-15 14:49:34 +02:00
|
|
|
Ppid = pmt.getPCRPid();
|
|
|
|
Vtype = stream.getStreamType();
|
2009-12-24 13:25:40 +01:00
|
|
|
ProcessCaDescriptors = true;
|
2004-01-04 12:30:00 +01:00
|
|
|
break;
|
|
|
|
case 3: // STREAMTYPE_11172_AUDIO
|
|
|
|
case 4: // STREAMTYPE_13818_AUDIO
|
2012-03-02 10:56:49 +01:00
|
|
|
case 0x0F: // ISO/IEC 13818-7 Audio with ADTS transport syntax
|
2010-05-16 13:36:55 +02:00
|
|
|
case 0x11: // ISO/IEC 14496-3 Audio with LATM transport syntax
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2004-01-25 15:32:08 +01:00
|
|
|
if (NumApids < MAXAPIDS) {
|
2009-08-15 22:19:42 +02:00
|
|
|
Apids[NumApids] = esPid;
|
2010-05-16 13:36:55 +02:00
|
|
|
Atypes[NumApids] = stream.getStreamType();
|
2004-01-25 15:32:08 +01:00
|
|
|
SI::Descriptor *d;
|
|
|
|
for (SI::Loop::Iterator it; (d = stream.streamDescriptors.getNext(it)); ) {
|
|
|
|
switch (d->getDescriptorTag()) {
|
|
|
|
case SI::ISO639LanguageDescriptorTag: {
|
|
|
|
SI::ISO639LanguageDescriptor *ld = (SI::ISO639LanguageDescriptor *)d;
|
2005-09-04 14:48:39 +02:00
|
|
|
SI::ISO639LanguageDescriptor::Language l;
|
|
|
|
char *s = ALangs[NumApids];
|
|
|
|
int n = 0;
|
|
|
|
for (SI::Loop::Iterator it; ld->languageLoop.getNext(l, it); ) {
|
|
|
|
if (*ld->languageCode != '-') { // some use "---" to indicate "none"
|
|
|
|
if (n > 0)
|
|
|
|
*s++ = '+';
|
|
|
|
strn0cpy(s, I18nNormalizeLanguageCode(l.languageCode), MAXLANGCODE1);
|
|
|
|
s += strlen(s);
|
|
|
|
if (n++ > 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-01-25 15:32:08 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
NumApids++;
|
|
|
|
}
|
2009-12-24 13:25:40 +01:00
|
|
|
ProcessCaDescriptors = true;
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5: // STREAMTYPE_13818_PRIVATE
|
|
|
|
case 6: // STREAMTYPE_13818_PES_PRIVATE
|
|
|
|
//XXX case 8: // STREAMTYPE_13818_DSMCC
|
|
|
|
{
|
2004-01-25 15:32:08 +01:00
|
|
|
int dpid = 0;
|
2010-06-05 13:50:56 +02:00
|
|
|
int dtype = 0;
|
2005-09-04 14:48:39 +02:00
|
|
|
char lang[MAXLANGCODE1] = { 0 };
|
2004-01-04 12:30:00 +01:00
|
|
|
SI::Descriptor *d;
|
|
|
|
for (SI::Loop::Iterator it; (d = stream.streamDescriptors.getNext(it)); ) {
|
|
|
|
switch (d->getDescriptorTag()) {
|
|
|
|
case SI::AC3DescriptorTag:
|
2010-03-27 15:19:06 +01:00
|
|
|
case SI::EnhancedAC3DescriptorTag:
|
2009-08-15 22:19:42 +02:00
|
|
|
dpid = esPid;
|
2010-06-05 13:50:56 +02:00
|
|
|
dtype = d->getDescriptorTag();
|
2009-12-24 13:25:40 +01:00
|
|
|
ProcessCaDescriptors = true;
|
2004-01-04 12:30:00 +01:00
|
|
|
break;
|
2007-10-12 14:52:30 +02:00
|
|
|
case SI::SubtitlingDescriptorTag:
|
|
|
|
if (NumSpids < MAXSPIDS) {
|
2009-08-15 22:19:42 +02:00
|
|
|
Spids[NumSpids] = esPid;
|
2007-10-12 14:52:30 +02:00
|
|
|
SI::SubtitlingDescriptor *sd = (SI::SubtitlingDescriptor *)d;
|
|
|
|
SI::SubtitlingDescriptor::Subtitling sub;
|
|
|
|
char *s = SLangs[NumSpids];
|
|
|
|
int n = 0;
|
|
|
|
for (SI::Loop::Iterator it; sd->subtitlingLoop.getNext(sub, it); ) {
|
|
|
|
if (sub.languageCode[0]) {
|
2009-08-16 15:32:39 +02:00
|
|
|
SubtitlingTypes[NumSpids] = sub.getSubtitlingType();
|
|
|
|
CompositionPageIds[NumSpids] = sub.getCompositionPageId();
|
|
|
|
AncillaryPageIds[NumSpids] = sub.getAncillaryPageId();
|
2007-10-12 14:52:30 +02:00
|
|
|
if (n > 0)
|
|
|
|
*s++ = '+';
|
|
|
|
strn0cpy(s, I18nNormalizeLanguageCode(sub.languageCode), MAXLANGCODE1);
|
|
|
|
s += strlen(s);
|
|
|
|
if (n++ > 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NumSpids++;
|
|
|
|
}
|
|
|
|
break;
|
2004-01-04 12:30:00 +01:00
|
|
|
case SI::TeletextDescriptorTag:
|
2009-08-15 22:19:42 +02:00
|
|
|
Tpid = esPid;
|
2004-01-04 12:30:00 +01:00
|
|
|
break;
|
2004-01-25 15:32:08 +01:00
|
|
|
case SI::ISO639LanguageDescriptorTag: {
|
|
|
|
SI::ISO639LanguageDescriptor *ld = (SI::ISO639LanguageDescriptor *)d;
|
2005-09-04 14:48:39 +02:00
|
|
|
strn0cpy(lang, I18nNormalizeLanguageCode(ld->languageCode), MAXLANGCODE1);
|
2004-01-25 15:32:08 +01:00
|
|
|
}
|
|
|
|
break;
|
2004-01-04 12:30:00 +01:00
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
delete d;
|
|
|
|
}
|
2004-01-25 15:32:08 +01:00
|
|
|
if (dpid) {
|
2005-01-16 14:40:47 +01:00
|
|
|
if (NumDpids < MAXDPIDS) {
|
2004-01-25 15:32:08 +01:00
|
|
|
Dpids[NumDpids] = dpid;
|
2010-06-05 13:50:56 +02:00
|
|
|
Dtypes[NumDpids] = dtype;
|
2005-09-04 14:48:39 +02:00
|
|
|
strn0cpy(DLangs[NumDpids], lang, MAXLANGCODE1);
|
2004-01-25 15:32:08 +01:00
|
|
|
NumDpids++;
|
|
|
|
}
|
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2010-03-06 12:01:17 +01:00
|
|
|
break;
|
2012-04-15 10:52:34 +02:00
|
|
|
case 0x80: // STREAMTYPE_USER_PRIVATE
|
|
|
|
if (Setup.StandardCompliance == STANDARD_ANSISCTE) { // DigiCipher II VIDEO (ANSI/SCTE 57)
|
|
|
|
Vpid = esPid;
|
|
|
|
Ppid = pmt.getPCRPid();
|
|
|
|
Vtype = 0x02; // compression based upon MPEG-2
|
|
|
|
ProcessCaDescriptors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
case 0x81: // STREAMTYPE_USER_PRIVATE
|
|
|
|
if (Setup.StandardCompliance == STANDARD_ANSISCTE) { // ATSC A/53 AUDIO (ANSI/SCTE 57)
|
|
|
|
char lang[MAXLANGCODE1] = { 0 };
|
|
|
|
SI::Descriptor *d;
|
|
|
|
for (SI::Loop::Iterator it; (d = stream.streamDescriptors.getNext(it)); ) {
|
|
|
|
switch (d->getDescriptorTag()) {
|
|
|
|
case SI::ISO639LanguageDescriptorTag: {
|
|
|
|
SI::ISO639LanguageDescriptor *ld = (SI::ISO639LanguageDescriptor *)d;
|
|
|
|
strn0cpy(lang, I18nNormalizeLanguageCode(ld->languageCode), MAXLANGCODE1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
if (NumDpids < MAXDPIDS) {
|
|
|
|
Dpids[NumDpids] = esPid;
|
|
|
|
Dtypes[NumDpids] = SI::AC3DescriptorTag;
|
|
|
|
strn0cpy(DLangs[NumDpids], lang, MAXLANGCODE1);
|
|
|
|
NumDpids++;
|
2011-04-17 13:48:20 +02:00
|
|
|
}
|
2012-04-15 10:52:34 +02:00
|
|
|
ProcessCaDescriptors = true;
|
|
|
|
break;
|
2011-04-17 13:48:20 +02:00
|
|
|
}
|
2012-04-15 10:52:34 +02:00
|
|
|
// fall through
|
|
|
|
case 0x82: // STREAMTYPE_USER_PRIVATE
|
|
|
|
if (Setup.StandardCompliance == STANDARD_ANSISCTE) { // STANDARD SUBTITLE (ANSI/SCTE 27)
|
|
|
|
//TODO
|
|
|
|
break;
|
2011-04-17 13:48:20 +02:00
|
|
|
}
|
2012-04-15 10:52:34 +02:00
|
|
|
// fall through
|
|
|
|
case 0x83 ... 0xFF: // STREAMTYPE_USER_PRIVATE
|
2010-11-01 15:47:59 +01:00
|
|
|
{
|
2010-11-07 13:47:16 +01:00
|
|
|
char lang[MAXLANGCODE1] = { 0 };
|
|
|
|
bool IsAc3 = false;
|
2010-11-01 15:47:59 +01:00
|
|
|
SI::Descriptor *d;
|
|
|
|
for (SI::Loop::Iterator it; (d = stream.streamDescriptors.getNext(it)); ) {
|
|
|
|
switch (d->getDescriptorTag()) {
|
|
|
|
case SI::RegistrationDescriptorTag: {
|
|
|
|
SI::RegistrationDescriptor *rd = (SI::RegistrationDescriptor *)d;
|
|
|
|
// http://www.smpte-ra.org/mpegreg/mpegreg.html
|
|
|
|
switch (rd->getFormatIdentifier()) {
|
|
|
|
case 0x41432D33: // 'AC-3'
|
|
|
|
IsAc3 = true;
|
|
|
|
break;
|
|
|
|
default:
|
2011-04-17 13:48:20 +02:00
|
|
|
//printf("Format identifier: 0x%08X (pid: %d)\n", rd->getFormatIdentifier(), esPid);
|
2010-11-01 15:47:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SI::ISO639LanguageDescriptorTag: {
|
|
|
|
SI::ISO639LanguageDescriptor *ld = (SI::ISO639LanguageDescriptor *)d;
|
|
|
|
strn0cpy(lang, I18nNormalizeLanguageCode(ld->languageCode), MAXLANGCODE1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
if (IsAc3) {
|
2010-03-06 12:01:17 +01:00
|
|
|
if (NumDpids < MAXDPIDS) {
|
2011-04-17 13:48:20 +02:00
|
|
|
Dpids[NumDpids] = esPid;
|
|
|
|
Dtypes[NumDpids] = SI::AC3DescriptorTag;
|
|
|
|
strn0cpy(DLangs[NumDpids], lang, MAXLANGCODE1);
|
|
|
|
NumDpids++;
|
|
|
|
}
|
2010-03-06 12:01:17 +01:00
|
|
|
ProcessCaDescriptors = true;
|
|
|
|
}
|
2010-11-01 15:47:59 +01:00
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
break;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: ;//printf("PID: %5d %5d %2d %3d %3d\n", pmt.getServiceId(), stream.getPid(), stream.getStreamType(), pmt.getVersionNumber(), Channel->Number());
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2009-12-24 13:25:40 +01:00
|
|
|
if (ProcessCaDescriptors) {
|
|
|
|
for (SI::Loop::Iterator it; (d = (SI::CaDescriptor*)stream.streamDescriptors.getNext(it, SI::CaDescriptorTag)); ) {
|
|
|
|
CaDescriptors->AddCaDescriptor(d, esPid);
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2004-01-05 12:08:09 +01:00
|
|
|
if (Setup.UpdateChannels >= 2) {
|
2015-09-01 11:14:27 +02:00
|
|
|
ChannelsModified |= Channel->SetPids(Vpid, Ppid, Vtype, Apids, Atypes, ALangs, Dpids, Dtypes, DLangs, Spids, SLangs, Tpid);
|
|
|
|
ChannelsModified |= Channel->SetCaIds(CaDescriptors->CaIds());
|
|
|
|
ChannelsModified |= Channel->SetSubtitlingDescriptors(SubtitlingTypes, CompositionPageIds, AncillaryPageIds);
|
2004-01-05 12:08:09 +01:00
|
|
|
}
|
2015-09-01 11:14:27 +02:00
|
|
|
ChannelsModified |= Channel->SetCaDescriptors(CaDescriptorHandler.AddCaDescriptors(CaDescriptors));
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2015-09-01 11:14:27 +02:00
|
|
|
StateKey.Remove(ChannelsModified);
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|
2014-02-18 13:12:39 +01:00
|
|
|
if (timer.TimedOut()) {
|
|
|
|
if (pmtIndex >= 0)
|
|
|
|
DBGLOG("PMT timeout %d", pmtIndex);
|
|
|
|
SwitchToNextPmtPid();
|
|
|
|
timer.Set(PMT_SCAN_TIMEOUT);
|
|
|
|
}
|
2003-12-22 13:29:24 +01:00
|
|
|
}
|