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.
|
|
|
|
*
|
2004-01-17 17:32:22 +01:00
|
|
|
* $Id: sdt.c 1.7 2004/01/17 17:27:49 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"
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
patFilter = PatFilter;
|
|
|
|
Set(0x11, 0x42); // SDT
|
|
|
|
}
|
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
|
|
|
{
|
2004-01-05 14:30:31 +01:00
|
|
|
cFilter::SetStatus(On);
|
|
|
|
sectionSyncer.Reset();
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if (!(Source() && Transponder()))
|
|
|
|
return;
|
|
|
|
SI::SDT sdt(Data, false);
|
|
|
|
if (!sdt.CheckCRCAndParse())
|
|
|
|
return;
|
|
|
|
if (!sectionSyncer.Sync(sdt.getVersionNumber(), sdt.getSectionNumber(), sdt.getLastSectionNumber()))
|
2004-01-04 12:30:00 +01:00
|
|
|
return;
|
|
|
|
if (!Channels.Lock(true, 10))
|
|
|
|
return;
|
|
|
|
SI::SDT::Service SiSdtService;
|
2004-01-05 14:30:31 +01:00
|
|
|
for (SI::Loop::Iterator it; sdt.serviceLoop.hasNext(it); ) {
|
|
|
|
SiSdtService = sdt.serviceLoop.getNext(it);
|
2004-01-04 12:30:00 +01:00
|
|
|
|
2004-01-11 15:54:37 +01:00
|
|
|
cChannel *channel = Channels.GetByChannelID(tChannelID(Source(), sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId()));
|
|
|
|
if (!channel)
|
|
|
|
channel = Channels.GetByChannelID(tChannelID(Source(), 0, Transponder(), SiSdtService.getServiceId()));
|
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-01-04 12:30:00 +01:00
|
|
|
//XXX TODO case 0x04: // NVOD reference service
|
|
|
|
//XXX TODO case 0x05: // NVOD time-shifted service
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
char *p = sd->serviceName.getText(buffer);
|
|
|
|
char NameBuf[1024];
|
|
|
|
char ShortNameBuf[1024];
|
|
|
|
char *pn = NameBuf;
|
|
|
|
char *ps = ShortNameBuf;
|
|
|
|
int IsShortName = 0;
|
|
|
|
while (*p) {
|
|
|
|
if ((uchar)*p == 0x86)
|
|
|
|
IsShortName++;
|
|
|
|
else if ((uchar)*p == 0x87)
|
|
|
|
IsShortName--;
|
|
|
|
else {
|
|
|
|
*pn++ = *p;
|
|
|
|
if (IsShortName)
|
|
|
|
*ps++ = *p;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
*pn = *ps = 0;
|
|
|
|
pn = NameBuf;
|
2004-01-17 11:31:12 +01:00
|
|
|
if (*NameBuf && *ShortNameBuf && strcmp(NameBuf, ShortNameBuf) != 0) {
|
2004-01-04 12:30:00 +01:00
|
|
|
*ps++ = ',';
|
|
|
|
strcpy(ps, NameBuf);
|
|
|
|
pn = ShortNameBuf;
|
|
|
|
}
|
2004-01-17 17:32:22 +01:00
|
|
|
pn = compactspace(pn);
|
|
|
|
ps = compactspace(ps);
|
2004-01-11 15:54:37 +01:00
|
|
|
if (channel) {
|
|
|
|
channel->SetId(sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId());
|
2004-01-05 12:08:09 +01:00
|
|
|
if (Setup.UpdateChannels >= 1)
|
2004-01-11 15:54:37 +01:00
|
|
|
channel->SetName(pn);
|
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:
|
2004-01-11 15:54:37 +01:00
|
|
|
// channel->SetCa(SiSdtService.getFreeCaMode() ? 0xFFFF : 0);
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2004-01-05 12:08:09 +01:00
|
|
|
else if (*pn && Setup.UpdateChannels >= 3) {
|
2004-01-11 15:54:37 +01:00
|
|
|
channel = Channels.NewChannel(Channel(), pn, sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId());
|
2004-01-05 14:30:31 +01:00
|
|
|
patFilter->Trigger();
|
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;
|
2004-01-11 15:54:37 +01:00
|
|
|
if (channel) {
|
2004-01-04 12:30:00 +01:00
|
|
|
for (SI::Loop::Iterator it; cid->identifiers.hasNext(it); )
|
2004-01-11 15:54:37 +01:00
|
|
|
channel->SetCa(cid->identifiers.getNext(it));
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
case SI::NVODReferenceDescriptorTag: {
|
|
|
|
SI::NVODReferenceDescriptor *nrd = (SI::NVODReferenceDescriptor *)d;
|
|
|
|
for (SI::Loop::Iterator it; nrd->serviceLoop.hasNext(it); ) {
|
|
|
|
SI::NVODReferenceDescriptor::Service Service = nrd->serviceLoop.getNext(it);
|
|
|
|
//printf(" %04X-%04X-%04X\n", Service.getOriginalNetworkId(), Service.getTransportStream(), Service.getServiceId());//XXX TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Channels.Unlock();
|
|
|
|
}
|