vdr  2.0.6
sdt.c
Go to the documentation of this file.
1 /*
2  * sdt.c: SDT section filter
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: sdt.c 2.5.1.2 2014/03/11 09:30:59 kls Exp $
8  */
9 
10 #include "sdt.h"
11 #include "channels.h"
12 #include "config.h"
13 #include "libsi/section.h"
14 #include "libsi/descriptor.h"
15 
16 // --- cSdtFilter ------------------------------------------------------------
17 
19 {
21  patFilter = PatFilter;
22  Set(0x11, 0x42); // SDT
23 }
24 
25 void cSdtFilter::SetStatus(bool On)
26 {
27  cMutexLock MutexLock(&mutex);
30  if (!On)
32 }
33 
34 void cSdtFilter::Trigger(int Source)
35 {
36  cMutexLock MutexLock(&mutex);
37  source = Source;
38 }
39 
40 void cSdtFilter::Process(u_short Pid, u_char Tid, const u_char *Data, int Length)
41 {
42  cMutexLock MutexLock(&mutex);
43  if (!(source && Transponder()))
44  return;
45  SI::SDT sdt(Data, false);
46  if (!sdt.CheckCRCAndParse())
47  return;
49  return;
50  if (!Channels.Lock(true, 10))
51  return;
52  SI::SDT::Service SiSdtService;
53  for (SI::Loop::Iterator it; sdt.serviceLoop.getNext(SiSdtService, it); ) {
55  if (!channel)
56  channel = Channels.GetByChannelID(tChannelID(source, 0, Transponder(), SiSdtService.getServiceId()));
57 
58  cLinkChannels *LinkChannels = NULL;
59  SI::Descriptor *d;
60  for (SI::Loop::Iterator it2; (d = SiSdtService.serviceDescriptors.getNext(it2)); ) {
61  switch (d->getDescriptorTag()) {
64  switch (sd->getServiceType()) {
65  case 0x01: // digital television service
66  case 0x02: // digital radio sound service
67  case 0x04: // NVOD reference service
68  case 0x05: // NVOD time-shifted service
69  case 0x16: // digital SD television service
70  case 0x19: // digital HD television service
71  {
72  char NameBuf[Utf8BufSize(1024)];
73  char ShortNameBuf[Utf8BufSize(1024)];
74  char ProviderNameBuf[Utf8BufSize(1024)];
75  sd->serviceName.getText(NameBuf, ShortNameBuf, sizeof(NameBuf), sizeof(ShortNameBuf));
76  char *pn = compactspace(NameBuf);
77  char *ps = compactspace(ShortNameBuf);
78  if (!*ps && cSource::IsCable(source)) {
79  // Some cable providers don't mark short channel names according to the
80  // standard, but rather go their own way and use "name>short name":
81  char *p = strchr(pn, '>'); // fix for UPC Wien
82  if (p && p > pn) {
83  *p++ = 0;
84  strcpy(ShortNameBuf, skipspace(p));
85  }
86  }
87  // Avoid ',' in short name (would cause trouble in channels.conf):
88  for (char *p = ShortNameBuf; *p; p++) {
89  if (*p == ',')
90  *p = '.';
91  }
92  sd->providerName.getText(ProviderNameBuf, sizeof(ProviderNameBuf));
93  char *pp = compactspace(ProviderNameBuf);
94  if (channel) {
95  channel->SetId(sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId());
96  if (Setup.UpdateChannels == 1 || Setup.UpdateChannels >= 3)
97  channel->SetName(pn, ps, pp);
98  // Using SiSdtService.getFreeCaMode() is no good, because some
99  // tv stations set this flag even for non-encrypted channels :-(
100  // The special value 0xFFFF was supposed to mean "unknown encryption"
101  // and would have been overwritten with real CA values later:
102  // channel->SetCa(SiSdtService.getFreeCaMode() ? 0xFFFF : 0);
103  }
104  else if (*pn && Setup.UpdateChannels >= 4) {
105  channel = Channels.NewChannel(Channel(), pn, ps, pp, sdt.getOriginalNetworkId(), sdt.getTransportStreamId(), SiSdtService.getServiceId());
106  patFilter->Trigger(SiSdtService.getServiceId());
107  }
108  }
109  default: ;
110  }
111  }
112  break;
113  // Using the CaIdentifierDescriptor is no good, because some tv stations
114  // just don't use it. The actual CA values are collected in pat.c:
115  /*
116  case SI::CaIdentifierDescriptorTag: {
117  SI::CaIdentifierDescriptor *cid = (SI::CaIdentifierDescriptor *)d;
118  if (channel) {
119  for (SI::Loop::Iterator it; cid->identifiers.hasNext(it); )
120  channel->SetCa(cid->identifiers.getNext(it));
121  }
122  }
123  break;
124  */
128  for (SI::Loop::Iterator it; nrd->serviceLoop.getNext(Service, it); ) {
130  if (!link && Setup.UpdateChannels >= 4) {
131  link = Channels.NewChannel(Channel(), "NVOD", "", "", Service.getOriginalNetworkId(), Service.getTransportStream(), Service.getServiceId());
132  patFilter->Trigger(Service.getServiceId());
133  }
134  if (link) {
135  if (!LinkChannels)
136  LinkChannels = new cLinkChannels;
137  LinkChannels->Add(new cLinkChannel(link));
138  }
139  }
140  }
141  break;
142  default: ;
143  }
144  delete d;
145  }
146  if (LinkChannels) {
147  if (channel)
148  channel->SetLinkChannels(LinkChannels);
149  else
150  delete LinkChannels;
151  }
152  }
153  Channels.Unlock();
154 }
void SetId(int Nid, int Tid, int Sid, int Rid=0)
Definition: channels.c:231
StructureLoop< Service > serviceLoop
Definition: descriptor.h:281
cChannels Channels
Definition: channels.c:792
char * getText()
Definition: si.c:221
void Add(cListObject *Object, cListObject *After=NULL)
Definition: tools.c:1945
cPatFilter * patFilter
Definition: sdt.h:21
int getServiceType() const
Definition: descriptor.c:521
StructureLoop< Service > serviceLoop
Definition: section.h:143
const cChannel * Channel(void)
Returns the channel of the data delivered to this filter.
Definition: filter.c:99
int getServiceId() const
Definition: section.c:132
DescriptorTag getDescriptorTag() const
Definition: si.c:100
cMutex mutex
Definition: sdt.h:18
cSectionSyncer sectionSyncer
Definition: sdt.h:19
void Unlock(void)
Definition: thread.c:170
int getSectionNumber() const
Definition: si.c:88
void Trigger(int Sid=-1)
Definition: pat.c:252
bool Sync(uchar Version, int Number, int LastNumber)
Definition: filter.c:26
void Trigger(int Source)
Definition: sdt.c:34
cChannel * NewChannel(const cChannel *Transponder, const char *Name, const char *ShortName, const char *Provider, int Nid, int Tid, int Sid, int Rid=0)
Definition: channels.c:1011
void SetName(const char *Name, const char *ShortName, const char *Provider)
Definition: channels.c:250
int source
Definition: sdt.h:20
int Source(void)
Returns the source of the data delivered to this filter.
Definition: filter.c:89
cSetup Setup
Definition: config.c:372
DescriptorLoop serviceDescriptors
Definition: section.h:135
bool Lock(bool Write, int TimeoutMs=0)
Definition: thread.c:155
cChannel * GetByChannelID(tChannelID ChannelID, bool TryWithoutRid=false, bool TryWithoutPolarization=false)
Definition: channels.c:919
bool CheckCRCAndParse()
Definition: si.c:65
int getOriginalNetworkId() const
Definition: section.c:128
virtual void SetStatus(bool On)
Turns this filter on or off, depending on the value of On.
Definition: filter.c:104
void SetLinkChannels(cLinkChannels *LinkChannels)
Definition: channels.c:442
Definition: pat.h:19
virtual void SetStatus(bool On)
Turns this filter on or off, depending on the value of On.
Definition: sdt.c:25
int getTransportStreamId() const
Definition: section.c:124
int getVersionNumber() const
Definition: si.c:84
virtual void Process(u_short Pid, u_char Tid, const u_char *Data, int Length)
Processes the data delivered to this filter.
Definition: sdt.c:40
static bool IsCable(int Code)
Definition: sources.h:41
unsigned char u_char
Definition: headers.h:24
int getLastSectionNumber() const
Definition: si.c:92
int UpdateChannels
Definition: config.h:306
char * skipspace(const char *s)
Definition: tools.h:194
int Transponder(void)
Returns the transponder of the data delivered to this filter.
Definition: filter.c:94
void Set(u_short Pid, u_char Tid, u_char Mask=0xFF)
Sets the given filter data by calling Add() with Sticky = true.
Definition: filter.c:137
char * compactspace(char *s)
Definition: tools.c:188
void Reset(void)
Definition: filter.c:20
cSdtFilter(cPatFilter *PatFilter)
Definition: sdt.c:18
Descriptor * getNext(Iterator &it)
Definition: si.c:112
#define Utf8BufSize(s)
Definition: tools.h:131