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*);
14 MTV_PUBLIC time_t dvbdate2unix(const unsigned char*);
15 uint32_t dvbdate2key(const unsigned char*);
16 
22 {
23  public:
25  : PSIPTable(table)
26  {
28  Parse();
29  }
30  explicit NetworkInformationTable(const PSIPTable& table)
31  : PSIPTable(table)
32  {
34  Parse();
35  }
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 ((_tsc_ptr[0]<<8) | _tsc_ptr[1]) & 0xfff; }
67  { return _ptrs.size() - 1; }
68  // for(i=0; i<N; i++) {
70  uint TSID(uint i) const { return (_ptrs[i][0]<<8) | _ptrs[i][1]; }
73  { return (_ptrs[i][2]<<8) | _ptrs[i][3]; }
74  // reserved_future_use 4 4.0+p
77  { return ((_ptrs[i][4]<<8) | _ptrs[i][5]) & 0xfff; }
80  const unsigned char* TransportDescriptors(uint i) const
81  { return _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 _cached_network_name;
93  mutable const unsigned char* _tsc_ptr;
94  mutable vector<const unsigned char*> _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  }
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 _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 (_ptrs[i][0]<<8) | (_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(_ptrs[i][2] & 0x2); }
145  // EIT_present_following 1 2.7+p
147  { return bool(_ptrs[i][2] & 0x1); }
149  uint RunningStatus(uint i) const { return (_ptrs[i][3] & 0xE0) >> 5; }
151  bool IsEncrypted(uint i) const { return bool(_ptrs[i][3] & 0x10); }
154  { return ((_ptrs[i][3]<<8) | (_ptrs[i][4])) & 0xfff; }
157  const unsigned char* ServiceDescriptors(uint i) const
158  { return _ptrs[i]+5; }
159  // }
160  ServiceDescriptor *GetServiceDescriptor(uint i) const;
161 
163  bool Mutate(void);
164 
165  void Parse(void) const;
166  QString toString(void) const override; // PSIPTable
167 
168  private:
169  mutable vector<const unsigned char*> _ptrs; // used to parse
170 };
171 
180 {
181  public:
182  explicit BouquetAssociationTable(const PSIPTable& table) : PSIPTable(table)
183  {
185  Parse();
186  }
188 
189  // table_id 8 0.0 0x4a
190  // section_syntax_indicator 1 1.0 1
191  // reserved_future_use 1 1.1 1
192  // reserved 2 1.2 3
193  // section_length 12 1.4 0
194  // Bouquet ID 16 3.0 0
195  uint BouquetID() const { return TableIDExtension(); }
196 
197  // reserved 2 5.0 3
198  // version_number 5 5.2 0
199  // current_next_indicator 1 5.7 1
200  // section_number 8 6.0 0x00
201  // last_section_number 8 7.0 0x00
202  // reserved 4 8 0x0d
204  { return ((psipdata()[0]<<8) | psipdata()[1]) & 0xfff; }
205 
206  // Bouquet descriptors len 12 8.4
207  // for (i=0;i<N;i++)
208  // Descriptor();
209  const unsigned char* BouquetDescriptors(void) const
210  { return psipdata() + 2; }
211  // reserved 4 10+N.0
212 
213  // Transport stream loop len 12
215  { return ((_tsc_ptr[0]<<8) | _tsc_ptr[1]) & 0xfff; }
217  { return _ptrs.size() - 1; }
218 
219  // for (i=0;i<N;i++) {
220  // transport_stream_id 16
221  uint TSID(uint i) const { return (_ptrs[i][0] << 8) | _ptrs[i][1]; }
222  // original_network_id 16
224  { return (_ptrs[i][2] << 8) | _ptrs[i][3]; }
225  // reserved 4
226  // transport descriptor len 12
228  { return ((_ptrs[i][4]<<8) | _ptrs[i][5]) & 0xfff; }
231  const unsigned char* TransportDescriptors(uint i) const
232  { return _ptrs[i]+6; }
233  // }
234 
235  void Parse(void) const;
236  QString toString(void) const override; // PSIPTable
237 
238  private:
239  mutable const unsigned char* _tsc_ptr;
240  mutable vector<const unsigned char*> _ptrs;
241 };
242 
244 {
245  explicit DiscontinuityInformationTable(const PSIPTable& table) : PSIPTable(table)
246  { ; }
247  // table_id 8
248  // section_syntax_indicator 1
249  // reserved_future_use 1
250  // reserved 2
251  // section_length 12
252  // transition_flag 1
253  // reserved_future_use 7
254 };
255 
257 {
258  explicit SelectionInformationTable(const PSIPTable& table) : PSIPTable(table)
259  { ; }
260  // table_id 8
261  // section_syntax_indicator 1
262  // DVB_reserved_future_use 1
263  // ISO_reserved 2
264  // section_length 12
265  // DVB_reserved_future_use 16
266  // ISO_reserved 2
267  // version_number 5
268  // current_next_indicator 1
269  // section_number 8
270  // last_section_number 8
271  // DVB_reserved_for_future_use 4
272  // transmission_info_loop_length 12
273  // for (i =0;i<N;i++) { descriptor() }
274  // for (i=0;i<N;i++)
275  // {
276  // service_id 16
277  // DVB_reserved_future_use 1
278  // running_status 3
279  // service_loop_length 12
280  // for(j=0;j<N;j++) { descriptor() }
281  // }
282  // CRC_32 32 rpchof
283 };
284 
286 {
287  public:
288  explicit DVBEventInformationTable(const PSIPTable& table) : PSIPTable(table)
289  {
290  // table_id 8 0.0 0xC7
291  assert(IsEIT(TableID()));
292  // section_syntax_indicator 1 1.0 1
293  // private_indicator 1 1.1 1
294  // reserved 2 1.2 3
295  // section_length 12 1.4
296  // reserved 2 5.0 3
297  // version_number 5 5.2
298  // current_next_indicator 1 5.7 1
299  // section_number 8 6.0
300  // last_section_number 8 7.0
301  Parse();
302  }
303 
304  // service_id 16 3.0
305  uint ServiceID(void) const { return TableIDExtension(); }
306 
307  // transport_stream_id 16 8.0
308  uint TSID(void) const
309  { return (psipdata()[0]<<8) | psipdata()[1]; }
310 
311  // original_network_id 16 10.0
313  { return (psipdata()[2]<<8) | psipdata()[3]; }
314 
315  // segment_last_section_num 8 12.0
317  { return psipdata()[4]; }
318  // last_table_id 8 13.0
319  uint LastTableID(void) const
320  { return psipdata()[5]; }
321 
322  uint EventCount() const { return _ptrs.size()-1; }
323 
324  // for(i=0;i<N;i++) {
325  // event_id 16 0.0+x
326  uint EventID(uint i) const
327  { return (_ptrs[i][0]<<8) | _ptrs[i][1]; }
328  // start_time 40 2.0+x
329  const unsigned char *StartTime(uint i) const
330  { return _ptrs[i]+2; }
331  QDateTime StartTimeUTC(uint i) const
332  { return dvbdate2qt(StartTime(i)); }
333  time_t StartTimeUnixUTC(uint i) const
334  { return dvbdate2unix(StartTime(i)); }
335  time_t EndTimeUnixUTC(uint i) const
336  { return StartTimeUnixUTC(i) + DurationInSeconds(i); }
337  uint32_t StartTimeKey(uint i) const
338  { return dvbdate2key(StartTime(i)); }
339  // duration 24 7.0+x
340  const unsigned char *Duration(uint i) const
341  { return _ptrs[i]+7; }
343  {
344  return ((byteBCD2int(Duration(i)[0]) * 3600) +
345  (byteBCD2int(Duration(i)[1]) * 60) +
346  (byteBCD2int(Duration(i)[2])));
347  }
348  // running_status 3 10.0+x
349  uint RunningStatus(uint i) const { return _ptrs[i][10] >> 5; }
350  // free_CA_mode 1 10.3+x
351  bool IsScrambled(uint i) const { return bool(_ptrs[i][10] & 0x10); }
352  // descriptors_loop_len 12 10.4+x
354  { return ((_ptrs[i][10]<<8) | (_ptrs[i][11])) & 0xfff; }
355  // for(i=0;i<N;i++) y 12.0+x
356  // { descriptor() }
357  const unsigned char* Descriptors(uint i) const
358  { return _ptrs[i] + 12; }
359  // }
360  //CRC_32 32 rpchof
361 
362  void Parse(void) const;
363 
364  static bool IsEIT(uint table_id);
365 
366  private:
367  mutable vector<const unsigned char*> _ptrs; // used to parse
368 };
369 
374 {
375  public:
376  explicit TimeDateTable(const PSIPTable& table)
377  : PSIPTable(table)
378  {
380  }
382 
383  // table_id 8 0.0 0x70
384  // section_syntax_indicator 1 1.0 0
385  // reserved_future_use 1 1.1 1
386  // reserved 2 1.2 3
387  // section_length 12 1.4 40
388  // UTC_time 40 3.0 0
389  const unsigned char *UTCdata(void) const
390  { return pesdata() + 3; }
391 
392  QDateTime UTC(void) const { return dvbdate2qt(UTCdata()); }
393  time_t UTCUnix(void) const { return dvbdate2unix(UTCdata()); }
394 };
395 
396 #endif // _DVB_TABLES_H_
uint BouquetID() const
Definition: dvbtables.h:195
const unsigned char * pesdata() const
Definition: pespacket.h:163
QDateTime UTC(void) const
Definition: dvbtables.h:392
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:522
const unsigned char * TransportDescriptors(uint i) const
for(j=0;j<N;j++) x 6.0+p { descriptor() }
Definition: dvbtables.h:231
uint TSID(void) const
Definition: dvbtables.h:308
uint TransportDescriptorsLength(uint i) const
Definition: dvbtables.h:227
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:203
This table tells the decoder on which PIDs to find A/V data.
Definition: dvbtables.h:101
uint TableIDExtension(void) const
Definition: mpegtables.h:496
TimeDateTable(const PSIPTable &table)
Definition: dvbtables.h:376
MTV_PUBLIC QDateTime dvbdate2qt(const unsigned char *)
Definition: dvbtables.cpp:277
time_t UTCUnix(void) const
Definition: dvbtables.h:393
uint ServiceID(uint i) const
service_id 16 0.0+p
Definition: dvbtables.h:141
const unsigned char * _tsc_ptr
Definition: dvbtables.h:93
vector< const unsigned char * > _ptrs
Definition: dvbtables.h:169
uint ServiceDescriptorsLength(uint i) const
desc_loop_length 12 3.4+p
Definition: dvbtables.h:153
This table gives the current DVB stream time.
Definition: dvbtables.h:373
const unsigned char * Descriptors(uint i) const
Definition: dvbtables.h:357
bool
Definition: pxsup2dast.c:30
uint TSID(uint i) const
Definition: dvbtables.h:221
bool IsScrambled(uint i) const
Definition: dvbtables.h:351
unsigned int uint
Definition: compat.h:140
BouquetAssociationTable(const PSIPTable &table)
Definition: dvbtables.h:182
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
vector< const unsigned char * > _ptrs
Definition: dvbtables.h:240
uint RunningStatus(uint i) const
running_status 3 3.0+p
Definition: dvbtables.h:149
QDateTime StartTimeUTC(uint i) const
Definition: dvbtables.h:331
ServiceDescriptionTable(const PSIPTable &table)
Definition: dvbtables.h:110
uint EventCount() const
Definition: dvbtables.h:322
SelectionInformationTable(const PSIPTable &table)
Definition: dvbtables.h:258
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:371
vector< const unsigned char * > _ptrs
Definition: dvbtables.h:367
const unsigned char * BouquetDescriptors(void) const
Definition: dvbtables.h:209
uint ServiceID(void) const
Definition: dvbtables.h:305
#define MTV_PUBLIC
Definition: mythtvexp.h:15
static int x2
Definition: mythsocket.cpp:61
uint DescriptorsLength(uint i) const
Definition: dvbtables.h:353
const unsigned char * UTCdata(void) const
Definition: dvbtables.h:389
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
vector< const unsigned char * > _ptrs
Definition: dvbtables.h:94
uint OriginalNetworkID(void) const
Definition: dvbtables.h:312
const unsigned char * StartTime(uint i) const
Definition: dvbtables.h:329
uint TransportStreamDataLength(void) const
Definition: dvbtables.h:214
uint32_t StartTimeKey(uint i) const
Definition: dvbtables.h:337
uint OriginalNetworkID(uint i) const
Definition: dvbtables.h:223
MTV_PUBLIC time_t dvbdate2unix(const unsigned char *)
Definition: dvbtables.cpp:322
bool HasEITSchedule(uint i) const
Definition: dvbtables.h:144
QString _cached_network_name
Definition: dvbtables.h:92
uint TransportStreamCount(void) const
Definition: dvbtables.h:216
uint32_t dvbdate2key(const unsigned char *)
Definition: dvbtables.cpp:340
uint LastTableID(void) const
Definition: dvbtables.h:319
uint TableID(void) const
Definition: mpegtables.h:479
#define assert(x)
uint DurationInSeconds(uint i) const
Definition: dvbtables.h:342
uint OriginalNetworkID(uint i) const
original_network_id 16 2.0+p
Definition: dvbtables.h:72
time_t EndTimeUnixUTC(uint i) const
Definition: dvbtables.h:335
uint TransportStreamCount(void) const
Definition: dvbtables.h:66
uint EventID(uint i) const
Definition: dvbtables.h:326
const unsigned char * _tsc_ptr
Definition: dvbtables.h:239
virtual QString toString(void) const
Definition: mpegtables.cpp:757
NetworkInformationTable(const NetworkInformationTable &table)
Definition: dvbtables.h:24
const unsigned char * Duration(uint i) const
Definition: dvbtables.h:340
DiscontinuityInformationTable(const PSIPTable &table)
Definition: dvbtables.h:245
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:179
time_t StartTimeUnixUTC(uint i) const
Definition: dvbtables.h:333
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:349
DVBEventInformationTable(const PSIPTable &table)
Definition: dvbtables.h:288
static int x1
Definition: mythsocket.cpp:60
uint SegmentLastSectionNumber(void) const
Definition: dvbtables.h:316
#define byteBCD2int(i)