MythTV  master
dvbtables.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2005, Daniel Thor Kristjansson
3 #ifndef DVB_TABLES_H
4 #define DVB_TABLES_H
5 
6 #include <QString>
7 #include <cstdint> // uint32_t
8 
9 #include "dvbdescriptors.h"
10 #include "mpegtables.h"
11 #include "mythtvexp.h"
12 
13 MTV_PUBLIC QDateTime dvbdate2qt(const unsigned char *buf);
14 MTV_PUBLIC time_t dvbdate2unix(const unsigned char *buf);
15 uint32_t dvbdate2key(const unsigned char *buf);
16 
22 {
23  public:
25  : PSIPTable(table)
26  {
28  Parse();
29  }
30  explicit NetworkInformationTable(const PSIPTable& table)
31  : PSIPTable(table)
32  {
34  Parse();
35  }
36  ~NetworkInformationTable() override { ; }
37 
38  // table_id 8 0.0 0x40/0x41
39  // section_syntax_indicator 1 1.0 1
40  // reserved_future_use 1 1.1 1
41  // reserved 2 1.2 3
42  // section_length 12 1.4 0
43  // reserved 2 5.0 3
44  // version_number 5 5.2 0
45  // current_next_indicator 1 5.7 1
46  // section_number 8 6.0 0x00
47  // last_section_number 8 7.0 0x00
48 
50  uint NetworkID(void) const { return TableIDExtension(); }
51 
52  // reserved_future_use 4 8.0 0xf
55  { return ((psipdata()[0]<<8) | psipdata()[1]) & 0xfff; }
56 
59  const unsigned char* NetworkDescriptors(void) const
60  { return psipdata() + 2; }
61 
62  // reserved_future_use 4 0.0+ndl 0xf
65  { return ((m_tscPtr[0]<<8) | m_tscPtr[1]) & 0xfff; }
67  { return m_ptrs.size() - 1; }
68  // for(i=0; i<N; i++) {
70  uint TSID(uint i) const { return (m_ptrs[i][0]<<8) | m_ptrs[i][1]; }
73  { return (m_ptrs[i][2]<<8) | m_ptrs[i][3]; }
74  // reserved_future_use 4 4.0+p
77  { return ((m_ptrs[i][4]<<8) | m_ptrs[i][5]) & 0xfff; }
80  const unsigned char* TransportDescriptors(uint i) const
81  { return m_ptrs[i]+6; }
82  // }
83 
85  bool Mutate(void);
86 
87  void Parse(void) const;
88  QString toString(void) const override; // PSIPTable
89  QString NetworkName(void) const;
90 
91  private:
92  mutable QString m_cachedNetworkName;
93  mutable const unsigned char* m_tscPtr {nullptr};
94  mutable vector<const unsigned char*> m_ptrs; // used to parse
95 };
96 
102 {
103  public:
105  : PSIPTable(table)
106  {
108  Parse();
109  }
110  explicit ServiceDescriptionTable(const PSIPTable& table) : PSIPTable(table)
111  {
113  Parse();
114  }
115  ~ServiceDescriptionTable() override { ; }
116 
117  // table_id 8 0.0 0x42/0x46
118  // section_syntax_indicator 1 1.0 1
119  // reserved_future_use 1 1.1 1
120  // reserved 2 1.2 3
121  // section_length 12 1.4 0
122  // reserved 2 5.0 3
123  // version_number 5 5.2 0
124  // current_next_indicator 1 5.7 1
125  // section_number 8 6.0 0x00
126  // last_section_number 8 7.0 0x00
127 
129  uint TSID() const { return TableIDExtension(); }
130 
133  { return (psipdata()[0]<<8) | psipdata()[1]; }
134 
136  uint ServiceCount() const { return m_ptrs.size()-1; }
137 
138  // reserved_future_use 8 10.0
139  // for (i=0;i<N;i++) {
141  uint ServiceID(uint i) const { return (m_ptrs[i][0]<<8) | (m_ptrs[i][1]); }
142  // reserved_future_use 6 2.0+p
143  // EIT_schedule_flag 1 2.6+p
144  bool HasEITSchedule(uint i) const { return bool(m_ptrs[i][2] & 0x2); }
145  // EIT_present_following 1 2.7+p
147  { return bool(m_ptrs[i][2] & 0x1); }
149  uint RunningStatus(uint i) const { return (m_ptrs[i][3] & 0xE0) >> 5; }
151  bool IsEncrypted(uint i) const { return bool(m_ptrs[i][3] & 0x10); }
154  { return ((m_ptrs[i][3]<<8) | (m_ptrs[i][4])) & 0xfff; }
157  const unsigned char* ServiceDescriptors(uint i) const
158  { return m_ptrs[i]+5; }
159  // }
160  ServiceDescriptor *GetServiceDescriptor(uint i) const;
161  ServiceRelocatedDescriptor *GetServiceRelocatedDescriptor(uint i) const;
162 
164  bool Mutate(void);
165 
166  void Parse(void) const;
167  QString toString(void) const override; // PSIPTable
168 
169  private:
170  mutable vector<const unsigned char*> m_ptrs; // used to parse
171 };
172 
181 {
182  public:
183  explicit BouquetAssociationTable(const PSIPTable& table) : PSIPTable(table)
184  {
186  Parse();
187  }
188  ~BouquetAssociationTable() override { ; }
189 
190  // table_id 8 0.0 0x4a
191  // section_syntax_indicator 1 1.0 1
192  // reserved_future_use 1 1.1 1
193  // reserved 2 1.2 3
194  // section_length 12 1.4 0
195  // Bouquet ID 16 3.0 0
196  uint BouquetID() const { return TableIDExtension(); }
197 
198  // reserved 2 5.0 3
199  // version_number 5 5.2 0
200  // current_next_indicator 1 5.7 1
201  // section_number 8 6.0 0x00
202  // last_section_number 8 7.0 0x00
203  // reserved 4 8 0x0d
205  { return ((psipdata()[0]<<8) | psipdata()[1]) & 0xfff; }
206 
207  // Bouquet descriptors len 12 8.4
208  // for (i=0;i<N;i++)
209  // Descriptor();
210  const unsigned char* BouquetDescriptors(void) const
211  { return psipdata() + 2; }
212  // reserved 4 10+N.0
213 
214  // Transport stream loop len 12
216  { return ((m_tscPtr[0]<<8) | m_tscPtr[1]) & 0xfff; }
218  { return m_ptrs.size() - 1; }
219 
220  // for (i=0;i<N;i++) {
221  // transport_stream_id 16
222  uint TSID(uint i) const { return (m_ptrs[i][0] << 8) | m_ptrs[i][1]; }
223  // original_network_id 16
225  { return (m_ptrs[i][2] << 8) | m_ptrs[i][3]; }
226  // reserved 4
227  // transport descriptor len 12
229  { return ((m_ptrs[i][4]<<8) | m_ptrs[i][5]) & 0xfff; }
232  const unsigned char* TransportDescriptors(uint i) const
233  { return m_ptrs[i]+6; }
234  // }
235 
236  void Parse(void) const;
237  QString toString(void) const override; // PSIPTable
238 
239  private:
240  mutable const unsigned char* m_tscPtr {nullptr};
241  mutable vector<const unsigned char*> m_ptrs;
242 };
243 
245 {
246  explicit DiscontinuityInformationTable(const PSIPTable& table) : PSIPTable(table)
247  { ; }
248  // table_id 8
249  // section_syntax_indicator 1
250  // reserved_future_use 1
251  // reserved 2
252  // section_length 12
253  // transition_flag 1
254  // reserved_future_use 7
255 };
256 
258 {
259  explicit SelectionInformationTable(const PSIPTable& table) : PSIPTable(table)
260  { ; }
261  // table_id 8
262  // section_syntax_indicator 1
263  // DVB_reserved_future_use 1
264  // ISO_reserved 2
265  // section_length 12
266  // DVB_reserved_future_use 16
267  // ISO_reserved 2
268  // version_number 5
269  // current_next_indicator 1
270  // section_number 8
271  // last_section_number 8
272  // DVB_reserved_for_future_use 4
273  // transmission_info_loop_length 12
274  // for (i =0;i<N;i++) { descriptor() }
275  // for (i=0;i<N;i++)
276  // {
277  // service_id 16
278  // DVB_reserved_future_use 1
279  // running_status 3
280  // service_loop_length 12
281  // for(j=0;j<N;j++) { descriptor() }
282  // }
283  // CRC_32 32 rpchof
284 };
285 
287 {
288  public:
289  explicit DVBEventInformationTable(const PSIPTable& table) : PSIPTable(table)
290  {
291  // table_id 8 0.0 0xC7
292  assert(IsEIT(TableID()));
293  // section_syntax_indicator 1 1.0 1
294  // private_indicator 1 1.1 1
295  // reserved 2 1.2 3
296  // section_length 12 1.4
297  // reserved 2 5.0 3
298  // version_number 5 5.2
299  // current_next_indicator 1 5.7 1
300  // section_number 8 6.0
301  // last_section_number 8 7.0
302  Parse();
303  }
304 
305  // service_id 16 3.0
306  uint ServiceID(void) const { return TableIDExtension(); }
307 
308  // transport_stream_id 16 8.0
309  uint TSID(void) const
310  { return (psipdata()[0]<<8) | psipdata()[1]; }
311 
312  // original_network_id 16 10.0
314  { return (psipdata()[2]<<8) | psipdata()[3]; }
315 
316  // segment_last_section_num 8 12.0
318  { return psipdata()[4]; }
319  // last_table_id 8 13.0
320  uint LastTableID(void) const
321  { return psipdata()[5]; }
322 
323  uint EventCount() const { return m_ptrs.size()-1; }
324 
325  // for(i=0;i<N;i++) {
326  // event_id 16 0.0+x
327  uint EventID(uint i) const
328  { return (m_ptrs[i][0]<<8) | m_ptrs[i][1]; }
329  // start_time 40 2.0+x
330  const unsigned char *StartTime(uint i) const
331  { return m_ptrs[i]+2; }
332  QDateTime StartTimeUTC(uint i) const
333  { return dvbdate2qt(StartTime(i)); }
334  time_t StartTimeUnixUTC(uint i) const
335  { return dvbdate2unix(StartTime(i)); }
336  time_t EndTimeUnixUTC(uint i) const
337  { return StartTimeUnixUTC(i) + DurationInSeconds(i); }
338  uint32_t StartTimeKey(uint i) const
339  { return dvbdate2key(StartTime(i)); }
340  // duration 24 7.0+x
341  const unsigned char *Duration(uint i) const
342  { return m_ptrs[i]+7; }
344  {
345  return ((byteBCD2int(Duration(i)[0]) * 3600) +
346  (byteBCD2int(Duration(i)[1]) * 60) +
347  (byteBCD2int(Duration(i)[2])));
348  }
349  // running_status 3 10.0+x
350  uint RunningStatus(uint i) const { return m_ptrs[i][10] >> 5; }
351  // free_CA_mode 1 10.3+x
352  bool IsScrambled(uint i) const { return bool(m_ptrs[i][10] & 0x10); }
353  // descriptors_loop_len 12 10.4+x
355  { return ((m_ptrs[i][10]<<8) | (m_ptrs[i][11])) & 0xfff; }
356  // for(i=0;i<N;i++) y 12.0+x
357  // { descriptor() }
358  const unsigned char* Descriptors(uint i) const
359  { return m_ptrs[i] + 12; }
360  // }
361  //CRC_32 32 rpchof
362 
363  void Parse(void) const;
364 
365  static bool IsEIT(uint table_id);
366 
367  private:
368  mutable vector<const unsigned char*> m_ptrs; // used to parse
369 };
370 
375 {
376  public:
377  explicit TimeDateTable(const PSIPTable& table)
378  : PSIPTable(table)
379  {
381  }
382  ~TimeDateTable() override { ; }
383 
384  // table_id 8 0.0 0x70
385  // section_syntax_indicator 1 1.0 0
386  // reserved_future_use 1 1.1 1
387  // reserved 2 1.2 3
388  // section_length 12 1.4 40
389  // UTC_time 40 3.0 0
390  const unsigned char *UTCdata(void) const
391  { return pesdata() + 3; }
392 
393  QDateTime UTC(void) const { return dvbdate2qt(UTCdata()); }
394  time_t UTCUnix(void) const { return dvbdate2unix(UTCdata()); }
395 };
396 
397 #endif // DVB_TABLES_H
uint BouquetID() const
Definition: dvbtables.h:196
const unsigned char * pesdata() const
Definition: pespacket.h:157
QDateTime UTC(void) const
Definition: dvbtables.h:393
const unsigned char * NetworkDescriptors(void) const
for(i=0; i<N; i++) x 10.0 { descriptor() }
Definition: dvbtables.h:59
const unsigned char * psipdata(void) const
Definition: mpegtables.h:532
const unsigned char * TransportDescriptors(uint i) const
for(j=0;j<N;j++) x 6.0+p { descriptor() }
Definition: dvbtables.h:232
uint TSID(void) const
Definition: dvbtables.h:309
uint TransportDescriptorsLength(uint i) const
Definition: dvbtables.h:228
MTV_PUBLIC QDateTime dvbdate2qt(const unsigned char *buf)
Definition: dvbtables.cpp:304
bool HasEITPresentFollowing(uint i) const
Definition: dvbtables.h:146
bool IsEncrypted(uint i) const
free_CA_mode 1 3.3+p
Definition: dvbtables.h:151
uint BouquetDescriptorsLength(void) const
Definition: dvbtables.h:204
This table tells the decoder on which PIDs to find A/V data.
Definition: dvbtables.h:101
MTV_PUBLIC time_t dvbdate2unix(const unsigned char *buf)
Definition: dvbtables.cpp:349
~ServiceDescriptionTable() override
Definition: dvbtables.h:115
uint TableIDExtension(void) const
Definition: mpegtables.h:506
TimeDateTable(const PSIPTable &table)
Definition: dvbtables.h:377
time_t UTCUnix(void) const
Definition: dvbtables.h:394
uint ServiceID(uint i) const
service_id 16 0.0+p
Definition: dvbtables.h:141
uint ServiceDescriptorsLength(uint i) const
desc_loop_length 12 3.4+p
Definition: dvbtables.h:153
~NetworkInformationTable() override
Definition: dvbtables.h:36
This table gives the current DVB stream time.
Definition: dvbtables.h:374
const unsigned char * Descriptors(uint i) const
Definition: dvbtables.h:358
bool
Definition: pxsup2dast.c:30
uint TSID(uint i) const
Definition: dvbtables.h:222
bool IsScrambled(uint i) const
Definition: dvbtables.h:352
BouquetAssociationTable(const PSIPTable &table)
Definition: dvbtables.h:183
uint TSID() const
transport_stream_id 16 3.0 0x0000
Definition: dvbtables.h:129
uint NetworkID(void) const
network_id 16 3.0 0x0000
Definition: dvbtables.h:50
NetworkInformationTable(const PSIPTable &table)
Definition: dvbtables.h:30
const unsigned char * ServiceDescriptors(uint i) const
for (j=0;j<N;j++) x 5.0+p { descriptor() }
Definition: dvbtables.h:157
const unsigned char * TransportDescriptors(uint i) const
for(j=0;j<N;j++) x 6.0+p { descriptor() }
Definition: dvbtables.h:80
uint RunningStatus(uint i) const
running_status 3 3.0+p
Definition: dvbtables.h:149
QDateTime StartTimeUTC(uint i) const
Definition: dvbtables.h:332
ServiceDescriptionTable(const PSIPTable &table)
Definition: dvbtables.h:110
uint EventCount() const
Definition: dvbtables.h:323
SelectionInformationTable(const PSIPTable &table)
Definition: dvbtables.h:259
uint OriginalNetworkID() const
original_network_id 16 8.0
Definition: dvbtables.h:132
ServiceDescriptionTable(const ServiceDescriptionTable &table)
Definition: dvbtables.h:104
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
Definition: mpegtables.h:386
vector< const unsigned char * > m_ptrs
Definition: dvbtables.h:170
const unsigned char * BouquetDescriptors(void) const
Definition: dvbtables.h:210
uint ServiceID(void) const
Definition: dvbtables.h:306
#define MTV_PUBLIC
Definition: mythtvexp.h:15
static int x2
Definition: mythsocket.cpp:61
vector< const unsigned char * > m_ptrs
Definition: dvbtables.h:241
uint DescriptorsLength(uint i) const
Definition: dvbtables.h:354
const unsigned char * UTCdata(void) const
Definition: dvbtables.h:390
uint ServiceCount() const
Number of services.
Definition: dvbtables.h:136
uint TransportStreamDataLength(void) const
trans_stream_loop_len 12 0.4+ndl
Definition: dvbtables.h:64
uint OriginalNetworkID(void) const
Definition: dvbtables.h:313
const unsigned char * StartTime(uint i) const
Definition: dvbtables.h:330
uint TransportStreamDataLength(void) const
Definition: dvbtables.h:215
unsigned int uint
Definition: compat.h:140
uint32_t StartTimeKey(uint i) const
Definition: dvbtables.h:338
uint OriginalNetworkID(uint i) const
Definition: dvbtables.h:224
bool HasEITSchedule(uint i) const
Definition: dvbtables.h:144
QString m_cachedNetworkName
Definition: dvbtables.h:92
vector< const unsigned char * > m_ptrs
Definition: dvbtables.h:368
vector< const unsigned char * > m_ptrs
Definition: dvbtables.h:94
uint TransportStreamCount(void) const
Definition: dvbtables.h:217
uint LastTableID(void) const
Definition: dvbtables.h:320
~TimeDateTable() override
Definition: dvbtables.h:382
uint TableID(void) const
Definition: mpegtables.h:489
#define assert(x)
uint DurationInSeconds(uint i) const
Definition: dvbtables.h:343
uint OriginalNetworkID(uint i) const
original_network_id 16 2.0+p
Definition: dvbtables.h:72
~BouquetAssociationTable() override
Definition: dvbtables.h:188
time_t EndTimeUnixUTC(uint i) const
Definition: dvbtables.h:336
uint TransportStreamCount(void) const
Definition: dvbtables.h:66
uint EventID(uint i) const
Definition: dvbtables.h:327
virtual QString toString(void) const
Definition: mpegtables.cpp:762
NetworkInformationTable(const NetworkInformationTable &table)
Definition: dvbtables.h:24
const unsigned char * Duration(uint i) const
Definition: dvbtables.h:341
DiscontinuityInformationTable(const PSIPTable &table)
Definition: dvbtables.h:246
uint TSID(uint i) const
transport_stream_id 16 0.0+p
Definition: dvbtables.h:70
uint NetworkDescriptorsLength(void) const
network_desc_length 12 8.4 0
Definition: dvbtables.h:54
Tells what channels can be found on each transponder for one bouquet (a bunch of channels from one pr...
Definition: dvbtables.h:180
time_t StartTimeUnixUTC(uint i) const
Definition: dvbtables.h:334
uint TransportDescriptorsLength(uint i) const
trans_desc_length 12 4.4+p
Definition: dvbtables.h:76
This table tells the decoder on which PIDs to find other tables.
Definition: dvbtables.h:21
uint RunningStatus(uint i) const
Definition: dvbtables.h:350
uint32_t dvbdate2key(const unsigned char *buf)
Definition: dvbtables.cpp:367
DVBEventInformationTable(const PSIPTable &table)
Definition: dvbtables.h:289
static int x1
Definition: mythsocket.cpp:60
uint SegmentLastSectionNumber(void) const
Definition: dvbtables.h:317
#define byteBCD2int(i)