2004-01-04 12:30:00 +01:00
|
|
|
/*
|
|
|
|
* sdt.c: SDT section filter
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2020-06-16 14:50:07 +02:00
|
|
|
* $Id: sdt.c 4.8 2020/06/16 14:50:07 kls Exp $
|
2004-01-04 12:30:00 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sdt.h"
|
|
|
|
#include "channels.h"
|
2004-01-05 12:08:09 +01:00
|
|
|
#include "config.h"
|
2004-01-04 12:30:00 +01:00
|
|
|
#include "libsi/section.h"
|
|
|
|
#include "libsi/descriptor.h"
|
|
|
|
|
2015-03-17 12:27:18 +01:00
|
|
|
// Set to 'true' for debug output:
|
|
|
|
static bool DebugSdt = false;
|
|
|
|
|
|
|
|
#define dbgsdt(a...) if (DebugSdt) fprintf(stderr, a)
|
|
|
|
|
2004-01-05 14:30:31 +01:00
|
|
|
// --- cSdtFilter ------------------------------------------------------------
|
2004-01-04 12:30:00 +01:00
|
|
|
|
2004-01-05 14:30:31 +01:00
|
|
|
cSdtFilter::cSdtFilter(cPatFilter *PatFilter)
|
|
|
|
{
|
2014-03-10 14:50:58 +01:00
|
|
|
source = cSource::stNone;
|
2020-05-04 08:50:20 +02:00
|
|
|
lastSource = cSource::stNone;
|
|
|
|
lastTransponder = 0;
|
|
|
|
lastNid = 0;
|
|
|
|
lastTid = 0;
|
2004-01-05 14:30:31 +01:00
|
|
|
patFilter = PatFilter;
|
2020-05-04 08:50:20 +02:00
|
|
|
transponderState = tsUnknown;
|
|
|
|
Set(0x11, 0x42); // SDT actual TS
|
2004-01-05 14:30:31 +01:00
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
|
2004-01-05 14:30:31 +01:00
|
|
|
void cSdtFilter::SetStatus(bool On)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2014-03-10 14:50:58 +01:00
|
|
|
cMutexLock MutexLock(&mutex);
|
2004-01-05 14:30:31 +01:00
|
|
|
cFilter::SetStatus(On);
|
|
|
|
sectionSyncer.Reset();
|
2014-03-10 14:50:58 +01:00
|
|
|
if (!On)
|
|
|
|
source = cSource::stNone;
|
2020-05-04 08:50:20 +02:00
|
|
|
transponderState = tsUnknown;
|
2014-03-10 14:50:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cSdtFilter::Trigger(int Source)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
source = Source;
|
2004-01-05 14:30:31 +01:00
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
|
2004-01-05 14:30:31 +01:00
|
|
|
void cSdtFilter::Process(u_short Pid, u_char Tid, const u_char *Data, int Length)
|
|
|
|
{
|
2014-03-10 14:50:58 +01:00
|
|
|
cMutexLock MutexLock(&mutex);
|
2004-01-05 14:30:31 +01:00
|
|
|
SI::SDT sdt(Data, false);
|
|
|
|
if (!sdt.CheckCRCAndParse())
|
|
|
|
return;
|
2020-05-04 08:50:20 +02:00
|
|
|
if (transponderState == tsUnknown) {
|
|
|
|
// The transponder can be verified with any section, no sync required:
|
|
|
|
int Nid = sdt.getOriginalNetworkId();
|
|
|
|
int Tid = sdt.getTransportStreamId();
|
|
|
|
if (Source() != lastSource || !ISTRANSPONDER(Transponder(), lastTransponder)) {
|
|
|
|
// We expect a change in NID/TID:
|
|
|
|
if (Nid && Tid && Nid == lastNid && Tid == lastTid) {
|
|
|
|
transponderState = tsWrong;
|
|
|
|
dsyslog("SDT: channel %d NID/TID (%d/%d) not found, got %d/%d", Channel()->Number(), Channel()->Nid(), Channel()->Tid(), Nid, Tid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// NID/TID is acceptable:
|
|
|
|
lastSource = Source();
|
|
|
|
lastTransponder = Transponder();
|
|
|
|
lastNid = Nid;
|
|
|
|
lastTid = Tid;
|
|
|
|
if (Nid == Channel()->Nid() && Tid == Channel()->Tid()) {
|
|
|
|
// NID/TID correspond with the channel data:
|
|
|
|
transponderState = tsVerified;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// NID/TID differ from the channel data, but we accept it, since this *is* the data for this transponder:
|
|
|
|
transponderState = tsAccepted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(source && Transponder()))
|
|
|
|
return;
|
2004-01-05 14:30:31 +01:00
|
|
|
if (!sectionSyncer.Sync(sdt.getVersionNumber(), sdt.getSectionNumber(), sdt.getLastSectionNumber()))
|
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) {
|
2015-03-17 15:10:57 +01:00
|
|
|
sectionSyncer.Repeat(); // let's not miss any section of the SDT
|
2004-01-04 12:30:00 +01:00
|
|
|
return;
|
2015-03-17 12:27:18 +01:00
|
|
|
}
|
|
|
|
dbgsdt("SDT: %2d %2d %2d %s %d\n", sdt.getVersionNumber(), sdt.getSectionNumber(), sdt.getLastSectionNumber(), *cSource::ToString(source), Transponder());
|
2015-09-01 11:14:27 +02:00
|
|
|
bool ChannelsModified = false;
|
2004-01-04 12:30:00 +01:00
|
|
|
SI::SDT::Service SiSdtService;
|
2004-10-16 10:14:19 +02:00
|
|
|
for (SI::Loop::Iterator it; sdt.serviceLoop.getNext(SiSdtService, it); ) {
|
2015-09-01 11:14:27 +02:00
|
|
|
cChannel *Channel = Channels->GetByChannelID(tChannelID(source, sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId()));
|
|
|
|
if (!Channel)
|
|
|
|
Channel = Channels->GetByChannelID(tChannelID(source, 0, Transponder(), SiSdtService.getServiceId()));
|
|
|
|
if (Channel)
|
|
|
|
Channel->SetSeen();
|
2004-01-04 12:30:00 +01:00
|
|
|
|
2004-07-18 11:02:50 +02:00
|
|
|
cLinkChannels *LinkChannels = NULL;
|
2004-01-04 12:30:00 +01:00
|
|
|
SI::Descriptor *d;
|
|
|
|
for (SI::Loop::Iterator it2; (d = SiSdtService.serviceDescriptors.getNext(it2)); ) {
|
|
|
|
switch (d->getDescriptorTag()) {
|
|
|
|
case SI::ServiceDescriptorTag: {
|
|
|
|
SI::ServiceDescriptor *sd = (SI::ServiceDescriptor *)d;
|
|
|
|
switch (sd->getServiceType()) {
|
|
|
|
case 0x01: // digital television service
|
2004-01-16 15:09:22 +01:00
|
|
|
case 0x02: // digital radio sound service
|
2004-07-18 11:02:50 +02:00
|
|
|
case 0x04: // NVOD reference service
|
|
|
|
case 0x05: // NVOD time-shifted service
|
2020-06-16 14:50:07 +02:00
|
|
|
case 0x0A: // advanced codec digital radio sound service
|
2010-05-16 14:25:58 +02:00
|
|
|
case 0x16: // digital SD television service
|
2008-04-12 13:39:12 +02:00
|
|
|
case 0x19: // digital HD television service
|
2020-06-16 14:41:32 +02:00
|
|
|
case 0x1F: // HEVC digital television service
|
|
|
|
case 0x20: // HEVC UHD digital television service
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2007-06-10 13:02:43 +02:00
|
|
|
char NameBuf[Utf8BufSize(1024)];
|
|
|
|
char ShortNameBuf[Utf8BufSize(1024)];
|
|
|
|
char ProviderNameBuf[Utf8BufSize(1024)];
|
2004-06-06 14:53:21 +02:00
|
|
|
sd->serviceName.getText(NameBuf, ShortNameBuf, sizeof(NameBuf), sizeof(ShortNameBuf));
|
2004-03-07 11:13:54 +01:00
|
|
|
char *pn = compactspace(NameBuf);
|
|
|
|
char *ps = compactspace(ShortNameBuf);
|
2014-03-10 14:50:58 +01:00
|
|
|
if (!*ps && cSource::IsCable(source)) {
|
2005-05-14 09:47:06 +02:00
|
|
|
// Some cable providers don't mark short channel names according to the
|
2009-12-13 11:57:44 +01:00
|
|
|
// standard, but rather go their own way and use "name>short name":
|
2005-08-27 09:29:30 +02:00
|
|
|
char *p = strchr(pn, '>'); // fix for UPC Wien
|
2005-05-14 09:47:06 +02:00
|
|
|
if (p && p > pn) {
|
|
|
|
*p++ = 0;
|
2005-08-27 09:29:30 +02:00
|
|
|
strcpy(ShortNameBuf, skipspace(p));
|
2005-05-14 09:47:06 +02:00
|
|
|
}
|
|
|
|
}
|
2009-12-24 10:49:16 +01:00
|
|
|
// Avoid ',' in short name (would cause trouble in channels.conf):
|
|
|
|
for (char *p = ShortNameBuf; *p; p++) {
|
|
|
|
if (*p == ',')
|
|
|
|
*p = '.';
|
|
|
|
}
|
2004-10-31 12:53:00 +01:00
|
|
|
sd->providerName.getText(ProviderNameBuf, sizeof(ProviderNameBuf));
|
|
|
|
char *pp = compactspace(ProviderNameBuf);
|
2015-09-01 11:14:27 +02:00
|
|
|
if (Channel) {
|
|
|
|
ChannelsModified |= Channel->SetId(Channels, sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId());
|
2006-04-15 14:18:25 +02:00
|
|
|
if (Setup.UpdateChannels == 1 || Setup.UpdateChannels >= 3)
|
2015-09-01 11:14:27 +02:00
|
|
|
ChannelsModified |= Channel->SetName(pn, ps, pp);
|
2004-01-04 12:30:00 +01:00
|
|
|
// Using SiSdtService.getFreeCaMode() is no good, because some
|
|
|
|
// tv stations set this flag even for non-encrypted channels :-(
|
|
|
|
// The special value 0xFFFF was supposed to mean "unknown encryption"
|
|
|
|
// and would have been overwritten with real CA values later:
|
2015-09-01 11:14:27 +02:00
|
|
|
// Channel->SetCa(SiSdtService.getFreeCaMode() ? 0xFFFF : 0);
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2006-04-15 14:18:25 +02:00
|
|
|
else if (*pn && Setup.UpdateChannels >= 4) {
|
2015-09-01 11:14:27 +02:00
|
|
|
dbgsdt(" %5d %5d %5d %s/%s %d %s\n", sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId(), *cSource::ToString(this->Channel()->Source()), *cSource::ToString(source), this->Channel()->Transponder(), pn);
|
|
|
|
Channel = Channels->NewChannel(this->Channel(), pn, ps, pp, sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId());
|
|
|
|
Channel->SetSource(source); // in case this comes from a satellite with a slightly different position
|
|
|
|
ChannelsModified = true;
|
2014-02-18 13:12:39 +01:00
|
|
|
patFilter->Trigger(SiSdtService.getServiceId());
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
2009-12-06 12:57:45 +01:00
|
|
|
default: ;
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// Using the CaIdentifierDescriptor is no good, because some tv stations
|
|
|
|
// just don't use it. The actual CA values are collected in pat.c:
|
|
|
|
/*
|
|
|
|
case SI::CaIdentifierDescriptorTag: {
|
|
|
|
SI::CaIdentifierDescriptor *cid = (SI::CaIdentifierDescriptor *)d;
|
2015-09-01 11:14:27 +02:00
|
|
|
if (Channel) {
|
2004-01-04 12:30:00 +01:00
|
|
|
for (SI::Loop::Iterator it; cid->identifiers.hasNext(it); )
|
2015-09-01 11:14:27 +02:00
|
|
|
Channel->SetCa(Channels, cid->identifiers.getNext(it));
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
case SI::NVODReferenceDescriptorTag: {
|
|
|
|
SI::NVODReferenceDescriptor *nrd = (SI::NVODReferenceDescriptor *)d;
|
2004-10-16 10:14:19 +02:00
|
|
|
SI::NVODReferenceDescriptor::Service Service;
|
|
|
|
for (SI::Loop::Iterator it; nrd->serviceLoop.getNext(Service, it); ) {
|
2015-09-01 11:14:27 +02:00
|
|
|
cChannel *link = Channels->GetByChannelID(tChannelID(source, Service.getOriginalNetworkId(), Service.getTransportStream(), Service.getServiceId()));
|
2006-04-15 14:18:25 +02:00
|
|
|
if (!link && Setup.UpdateChannels >= 4) {
|
2015-09-01 11:14:27 +02:00
|
|
|
link = Channels->NewChannel(this->Channel(), "NVOD", "", "", Service.getOriginalNetworkId(), Service.getTransportStream(), Service.getServiceId());
|
2014-02-18 13:12:39 +01:00
|
|
|
patFilter->Trigger(Service.getServiceId());
|
2015-09-01 11:14:27 +02:00
|
|
|
ChannelsModified = true;
|
2004-07-18 11:02:50 +02:00
|
|
|
}
|
|
|
|
if (link) {
|
|
|
|
if (!LinkChannels)
|
|
|
|
LinkChannels = new cLinkChannels;
|
|
|
|
LinkChannels->Add(new cLinkChannel(link));
|
2015-09-01 11:14:27 +02:00
|
|
|
ChannelsModified = true;
|
2004-07-18 11:02:50 +02:00
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
delete d;
|
|
|
|
}
|
2004-07-18 11:02:50 +02:00
|
|
|
if (LinkChannels) {
|
2015-09-01 11:14:27 +02:00
|
|
|
if (Channel)
|
|
|
|
ChannelsModified |= Channel->SetLinkChannels(LinkChannels);
|
2004-07-18 11:02:50 +02:00
|
|
|
else
|
|
|
|
delete LinkChannels;
|
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2015-01-04 14:37:36 +01:00
|
|
|
if (sdt.getSectionNumber() == sdt.getLastSectionNumber()) {
|
2015-03-17 12:27:18 +01:00
|
|
|
if (Setup.UpdateChannels == 1 || Setup.UpdateChannels >= 3) {
|
2015-09-01 11:14:27 +02:00
|
|
|
ChannelsModified |= Channels->MarkObsoleteChannels(source, sdt.getOriginalNetworkId(), sdt.getTransportStreamId());
|
2015-03-17 12:27:18 +01:00
|
|
|
if (source != Source())
|
2015-09-01 11:14:27 +02:00
|
|
|
ChannelsModified |= Channels->MarkObsoleteChannels(Source(), sdt.getOriginalNetworkId(), sdt.getTransportStreamId());
|
2015-03-17 12:27:18 +01:00
|
|
|
}
|
2015-01-04 14:37:36 +01:00
|
|
|
}
|
2015-09-01 11:14:27 +02:00
|
|
|
StateKey.Remove(ChannelsModified);
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|