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 <cstdint> // uint32_t
7#include <ctime>
8
9using uint = unsigned int;
10
11#include <QDateTime>
12#include <QString>
13
16#include "libmythtv/mythtvexp.h"
17
18uint32_t dvbdate2key(const unsigned char *buf);
19
20static inline QDateTime dvbdate2qt(const std::array<uint8_t,5> buf)
21{
22 return dvbdate2qt(buf.data());
23}
24static inline time_t dvbdate2unix(const std::array<uint8_t,5> buf)
25{
26 return dvbdate2unix(buf.data());
27}
28
34{
35 public:
37 : PSIPTable(table)
38 {
40 Parse();
41 }
42 explicit NetworkInformationTable(const PSIPTable& table)
43 : PSIPTable(table)
44 {
46 Parse();
47 }
48 ~NetworkInformationTable() override { ; }
49
50 // table_id 8 0.0 0x40/0x41
51 // section_syntax_indicator 1 1.0 1
52 // reserved_future_use 1 1.1 1
53 // reserved 2 1.2 3
54 // section_length 12 1.4 0
55 // reserved 2 5.0 3
56 // version_number 5 5.2 0
57 // current_next_indicator 1 5.7 1
58 // section_number 8 6.0 0x00
59 // last_section_number 8 7.0 0x00
60
62 uint NetworkID(void) const { return TableIDExtension(); }
63
64 // reserved_future_use 4 8.0 0xf
67 { return ((psipdata()[0]<<8) | psipdata()[1]) & 0xfff; }
68
71 const unsigned char* NetworkDescriptors(void) const
72 { return psipdata() + 2; }
73
74 // reserved_future_use 4 0.0+ndl 0xf
77 { return ((m_tscPtr[0]<<8) | m_tscPtr[1]) & 0xfff; }
79 { return m_ptrs.size() - 1; }
80 // for(i=0; i<N; i++) {
82 uint TSID(uint i) const { return (m_ptrs[i][0]<<8) | m_ptrs[i][1]; }
85 { return (m_ptrs[i][2]<<8) | m_ptrs[i][3]; }
86 // reserved_future_use 4 4.0+p
89 { return ((m_ptrs[i][4]<<8) | m_ptrs[i][5]) & 0xfff; }
92 const unsigned char* TransportDescriptors(uint i) const
93 { return m_ptrs[i]+6; }
94 // }
95
97 bool Mutate(void);
98
99 void Parse(void) const;
100 QString toString(void) const override; // PSIPTable
101 QString NetworkName(void) const;
102
103 private:
104 mutable QString m_cachedNetworkName;
105 mutable const unsigned char* m_tscPtr {nullptr};
106 mutable std::vector<const unsigned char*> m_ptrs; // used to parse
107};
108
114{
115 public:
117 : PSIPTable(table)
118 {
120 Parse();
121 }
122 explicit ServiceDescriptionTable(const PSIPTable& table) : PSIPTable(table)
123 {
125 Parse();
126 }
128
129 // table_id 8 0.0 0x42/0x46
130 // section_syntax_indicator 1 1.0 1
131 // reserved_future_use 1 1.1 1
132 // reserved 2 1.2 3
133 // section_length 12 1.4 0
134 // reserved 2 5.0 3
135 // version_number 5 5.2 0
136 // current_next_indicator 1 5.7 1
137 // section_number 8 6.0 0x00
138 // last_section_number 8 7.0 0x00
139
141 uint TSID() const { return TableIDExtension(); }
142
145 { return (psipdata()[0]<<8) | psipdata()[1]; }
146
148 uint ServiceCount() const { return m_ptrs.size()-1; }
149
150 // reserved_future_use 8 10.0
151 // for (i=0;i<N;i++) {
153 uint ServiceID(uint i) const { return (m_ptrs[i][0]<<8) | (m_ptrs[i][1]); }
154 // reserved_future_use 6 2.0+p
155 // EIT_schedule_flag 1 2.6+p
156 bool HasEITSchedule(uint i) const { return ( m_ptrs[i][2] & 0x02 ) != 0; }
157 // EIT_present_following 1 2.7+p
159 { return ( m_ptrs[i][2] & 0x01 ) != 0; }
161 uint RunningStatus(uint i) const { return (m_ptrs[i][3] & 0xE0) >> 5; }
163 bool IsEncrypted(uint i) const { return ( m_ptrs[i][3] & 0x10 ) != 0; }
166 { return ((m_ptrs[i][3]<<8) | (m_ptrs[i][4])) & 0xfff; }
169 const unsigned char* ServiceDescriptors(uint i) const
170 { return m_ptrs[i]+5; }
171 // }
172 ServiceDescriptor *GetServiceDescriptor(uint i) const;
173 ServiceRelocatedDescriptor *GetServiceRelocatedDescriptor(uint i) const;
174
176 bool Mutate(void);
177
178 void Parse(void) const;
179 QString toString(void) const override; // PSIPTable
180
181 private:
182 mutable std::vector<const unsigned char*> m_ptrs; // used to parse
183};
184
193{
194 public:
195 explicit BouquetAssociationTable(const PSIPTable& table) : PSIPTable(table)
196 {
198 Parse();
199 }
201
202 // table_id 8 0.0 0x4a
203 // section_syntax_indicator 1 1.0 1
204 // reserved_future_use 1 1.1 1
205 // reserved 2 1.2 3
206 // section_length 12 1.4 0
207 // Bouquet ID 16 3.0 0
208 uint BouquetID() const { return TableIDExtension(); }
209
210 // reserved 2 5.0 3
211 // version_number 5 5.2 0
212 // current_next_indicator 1 5.7 1
213 // section_number 8 6.0 0x00
214 // last_section_number 8 7.0 0x00
215 // reserved 4 8 0x0d
217 { return ((psipdata()[0]<<8) | psipdata()[1]) & 0xfff; }
218
219 // Bouquet descriptors len 12 8.4
220 // for (i=0;i<N;i++)
221 // Descriptor();
222 const unsigned char* BouquetDescriptors(void) const
223 { return psipdata() + 2; }
224 // reserved 4 10+N.0
225
226 // Transport stream loop len 12
228 { return ((m_tscPtr[0]<<8) | m_tscPtr[1]) & 0xfff; }
230 { return m_ptrs.size() - 1; }
231
232 // for (i=0;i<N;i++) {
233 // transport_stream_id 16
234 uint TSID(uint i) const { return (m_ptrs[i][0] << 8) | m_ptrs[i][1]; }
235 // original_network_id 16
237 { return (m_ptrs[i][2] << 8) | m_ptrs[i][3]; }
238 // reserved 4
239 // transport descriptor len 12
241 { return ((m_ptrs[i][4]<<8) | m_ptrs[i][5]) & 0xfff; }
244 const unsigned char* TransportDescriptors(uint i) const
245 { return m_ptrs[i]+6; }
246 // }
247
248 void Parse(void) const;
249 QString toString(void) const override; // PSIPTable
250
251 private:
252 mutable const unsigned char* m_tscPtr {nullptr};
253 mutable std::vector<const unsigned char*> m_ptrs;
254};
255
257{
258 explicit DiscontinuityInformationTable(const PSIPTable& table) : PSIPTable(table)
259 { ; }
260 // table_id 8
261 // section_syntax_indicator 1
262 // reserved_future_use 1
263 // reserved 2
264 // section_length 12
265 // transition_flag 1
266 // reserved_future_use 7
267};
268
270{
271 explicit SelectionInformationTable(const PSIPTable& table) : PSIPTable(table)
272 { ; }
273 // table_id 8
274 // section_syntax_indicator 1
275 // DVB_reserved_future_use 1
276 // ISO_reserved 2
277 // section_length 12
278 // DVB_reserved_future_use 16
279 // ISO_reserved 2
280 // version_number 5
281 // current_next_indicator 1
282 // section_number 8
283 // last_section_number 8
284 // DVB_reserved_for_future_use 4
285 // transmission_info_loop_length 12
286 // for (i =0;i<N;i++) { descriptor() }
287 // for (i=0;i<N;i++)
288 // {
289 // service_id 16
290 // DVB_reserved_future_use 1
291 // running_status 3
292 // service_loop_length 12
293 // for(j=0;j<N;j++) { descriptor() }
294 // }
295 // CRC_32 32 rpchof
296};
297
299{
300 public:
301 explicit DVBEventInformationTable(const PSIPTable& table) : PSIPTable(table)
302 {
303 // table_id 8 0.0 0xC7
304 assert(IsEIT(TableID()));
305 // section_syntax_indicator 1 1.0 1
306 // private_indicator 1 1.1 1
307 // reserved 2 1.2 3
308 // section_length 12 1.4
309 // reserved 2 5.0 3
310 // version_number 5 5.2
311 // current_next_indicator 1 5.7 1
312 // section_number 8 6.0
313 // last_section_number 8 7.0
314 Parse();
315 }
316
317 // service_id 16 3.0
318 uint ServiceID(void) const { return TableIDExtension(); }
319
320 // transport_stream_id 16 8.0
321 uint TSID(void) const
322 { return (psipdata()[0]<<8) | psipdata()[1]; }
323
324 // original_network_id 16 10.0
326 { return (psipdata()[2]<<8) | psipdata()[3]; }
327
328 // segment_last_section_num 8 12.0
330 { return psipdata()[4]; }
331 // last_table_id 8 13.0
332 uint LastTableID(void) const
333 { return psipdata()[5]; }
334
335 uint EventCount() const { return m_ptrs.size()-1; }
336
337 // for(i=0;i<N;i++) {
338 // event_id 16 0.0+x
340 { return (m_ptrs[i][0]<<8) | m_ptrs[i][1]; }
341 // start_time 40 2.0+x
342 const unsigned char *StartTime(uint i) const
343 { return m_ptrs[i]+2; }
344 QDateTime StartTimeUTC(uint i) const
345 { return dvbdate2qt(StartTime(i)); }
346 time_t StartTimeUnixUTC(uint i) const
347 { return dvbdate2unix(StartTime(i)); }
348 time_t EndTimeUnixUTC(uint i) const
349 { return StartTimeUnixUTC(i) + DurationInSeconds(i); }
350 uint32_t StartTimeKey(uint i) const
351 { return dvbdate2key(StartTime(i)); }
352 // duration 24 7.0+x
353 const unsigned char *Duration(uint i) const
354 { return m_ptrs[i]+7; }
356 {
357 return ((byteBCD2int(Duration(i)[0]) * 3600) +
358 (byteBCD2int(Duration(i)[1]) * 60) +
359 (byteBCD2int(Duration(i)[2])));
360 }
361 // running_status 3 10.0+x
362 uint RunningStatus(uint i) const { return m_ptrs[i][10] >> 5; }
363 // free_CA_mode 1 10.3+x
364 bool IsScrambled(uint i) const { return ( m_ptrs[i][10] & 0x10 ) != 0; }
365 // descriptors_loop_len 12 10.4+x
367 { return ((m_ptrs[i][10]<<8) | (m_ptrs[i][11])) & 0xfff; }
368 // for(i=0;i<N;i++) y 12.0+x
369 // { descriptor() }
370 const unsigned char* Descriptors(uint i) const
371 { return m_ptrs[i] + 12; }
372 // }
373 //CRC_32 32 rpchof
374
375 void Parse(void) const;
376
377 static bool IsEIT(uint table_id);
378
379 private:
380 mutable std::vector<const unsigned char*> m_ptrs; // used to parse
381};
382
387{
388 public:
389 explicit TimeDateTable(const PSIPTable& table)
390 : PSIPTable(table)
391 {
393 }
394 ~TimeDateTable() override { ; }
395
396 // table_id 8 0.0 0x70
397 // section_syntax_indicator 1 1.0 0
398 // reserved_future_use 1 1.1 1
399 // reserved 2 1.2 3
400 // section_length 12 1.4 40
401 // UTC_time 40 3.0 0
402 const unsigned char *UTCdata(void) const
403 { return pesdata() + 3; }
404
405 QDateTime UTC(void) const { return dvbdate2qt(UTCdata()); }
406 time_t UTCUnix(void) const { return dvbdate2unix(UTCdata()); }
407};
408
413{
414 public:
415 explicit TimeOffsetTable(const PSIPTable& table)
416 : PSIPTable(table)
417 {
419 }
420 ~TimeOffsetTable() override { ; }
421
422 // table_id 8 0.0 0x70
423 // section_syntax_indicator 1 1.0 0
424 // reserved_future_use 1 1.1 1
425 // reserved 2 1.2 3
426 // section_length 12 1.4 40
427 // UTC_time 40 3.0 0
428 const unsigned char *UTCdata(void) const
429 { return pesdata() + 3; }
430
431 QDateTime UTC(void) const { return dvbdate2qt(UTCdata()); }
432 time_t UTCUnix(void) const { return dvbdate2unix(UTCdata()); }
433
434 // Reserved 4 8.0 0x0F
435 // Descriptors Length 12 8.4 0
437 { return ((pesdata()[8]<<8) | pesdata()[9]) & 0x0fff; }
438 // for (i=0;i<N;i++)
439 // Descriptor();
440 const unsigned char* Descriptors(void) const
441 { return pesdata() + 10; }
442};
443
444#endif // DVB_TABLES_H
#define assert(x)
Tells what channels can be found on each transponder for one bouquet (a bunch of channels from one pr...
Definition: dvbtables.h:193
uint TSID(uint i) const
Definition: dvbtables.h:234
BouquetAssociationTable(const PSIPTable &table)
Definition: dvbtables.h:195
const unsigned char * BouquetDescriptors(void) const
Definition: dvbtables.h:222
uint TransportDescriptorsLength(uint i) const
Definition: dvbtables.h:240
const unsigned char * TransportDescriptors(uint i) const
for(j=0;j<N;j++) x 6.0+p { descriptor() }
Definition: dvbtables.h:244
~BouquetAssociationTable() override
Definition: dvbtables.h:200
std::vector< const unsigned char * > m_ptrs
Definition: dvbtables.h:253
uint BouquetID() const
Definition: dvbtables.h:208
uint BouquetDescriptorsLength(void) const
Definition: dvbtables.h:216
uint TransportStreamDataLength(void) const
Definition: dvbtables.h:227
uint OriginalNetworkID(uint i) const
Definition: dvbtables.h:236
uint TransportStreamCount(void) const
Definition: dvbtables.h:229
bool IsScrambled(uint i) const
Definition: dvbtables.h:364
uint EventCount() const
Definition: dvbtables.h:335
uint RunningStatus(uint i) const
Definition: dvbtables.h:362
time_t StartTimeUnixUTC(uint i) const
Definition: dvbtables.h:346
uint SegmentLastSectionNumber(void) const
Definition: dvbtables.h:329
std::vector< const unsigned char * > m_ptrs
Definition: dvbtables.h:380
uint EventID(uint i) const
Definition: dvbtables.h:339
uint ServiceID(void) const
Definition: dvbtables.h:318
uint OriginalNetworkID(void) const
Definition: dvbtables.h:325
uint LastTableID(void) const
Definition: dvbtables.h:332
const unsigned char * Descriptors(uint i) const
Definition: dvbtables.h:370
uint DescriptorsLength(uint i) const
Definition: dvbtables.h:366
time_t EndTimeUnixUTC(uint i) const
Definition: dvbtables.h:348
const unsigned char * Duration(uint i) const
Definition: dvbtables.h:353
uint TSID(void) const
Definition: dvbtables.h:321
QDateTime StartTimeUTC(uint i) const
Definition: dvbtables.h:344
uint DurationInSeconds(uint i) const
Definition: dvbtables.h:355
DVBEventInformationTable(const PSIPTable &table)
Definition: dvbtables.h:301
uint32_t StartTimeKey(uint i) const
Definition: dvbtables.h:350
const unsigned char * StartTime(uint i) const
Definition: dvbtables.h:342
DiscontinuityInformationTable(const PSIPTable &table)
Definition: dvbtables.h:258
This table tells the decoder on which PIDs to find other tables.
Definition: dvbtables.h:34
uint OriginalNetworkID(uint i) const
original_network_id 16 2.0+p
Definition: dvbtables.h:84
NetworkInformationTable(const NetworkInformationTable &table)
Definition: dvbtables.h:36
uint TransportDescriptorsLength(uint i) const
trans_desc_length 12 4.4+p
Definition: dvbtables.h:88
uint NetworkID(void) const
network_id 16 3.0 0x0000
Definition: dvbtables.h:62
NetworkInformationTable(const PSIPTable &table)
Definition: dvbtables.h:42
const unsigned char * TransportDescriptors(uint i) const
for(j=0;j<N;j++) x 6.0+p { descriptor() }
Definition: dvbtables.h:92
uint TransportStreamDataLength(void) const
trans_stream_loop_len 12 0.4+ndl
Definition: dvbtables.h:76
uint TSID(uint i) const
transport_stream_id 16 0.0+p
Definition: dvbtables.h:82
~NetworkInformationTable() override
Definition: dvbtables.h:48
const unsigned char * NetworkDescriptors(void) const
for(i=0; i<N; i++) x 10.0 { descriptor() }
Definition: dvbtables.h:71
std::vector< const unsigned char * > m_ptrs
Definition: dvbtables.h:106
uint NetworkDescriptorsLength(void) const
network_desc_length 12 8.4 0
Definition: dvbtables.h:66
uint TransportStreamCount(void) const
Definition: dvbtables.h:78
const unsigned char * pesdata() const
Definition: pespacket.h:164
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
Definition: mpegtables.h:410
const unsigned char * psipdata(void) const
Definition: mpegtables.h:541
uint TableID(void) const
Definition: mpegtables.h:496
virtual QString toString(void) const
Definition: mpegtables.cpp:789
uint TableIDExtension(void) const
Definition: mpegtables.h:515
SelectionInformationTable(const PSIPTable &table)
Definition: dvbtables.h:271
This table tells the decoder on which PIDs to find A/V data.
Definition: dvbtables.h:114
uint TSID() const
transport_stream_id 16 3.0 0x0000
Definition: dvbtables.h:141
ServiceDescriptionTable(const PSIPTable &table)
Definition: dvbtables.h:122
const unsigned char * ServiceDescriptors(uint i) const
for (j=0;j<N;j++) x 5.0+p { descriptor() }
Definition: dvbtables.h:169
bool HasEITPresentFollowing(uint i) const
Definition: dvbtables.h:158
std::vector< const unsigned char * > m_ptrs
Definition: dvbtables.h:182
~ServiceDescriptionTable() override
Definition: dvbtables.h:127
uint RunningStatus(uint i) const
running_status 3 3.0+p
Definition: dvbtables.h:161
ServiceDescriptionTable(const ServiceDescriptionTable &table)
Definition: dvbtables.h:116
bool HasEITSchedule(uint i) const
Definition: dvbtables.h:156
uint ServiceID(uint i) const
service_id 16 0.0+p
Definition: dvbtables.h:153
uint ServiceCount() const
Number of services.
Definition: dvbtables.h:148
uint ServiceDescriptorsLength(uint i) const
desc_loop_length 12 3.4+p
Definition: dvbtables.h:165
uint OriginalNetworkID() const
original_network_id 16 8.0
Definition: dvbtables.h:144
bool IsEncrypted(uint i) const
free_CA_mode 1 3.3+p
Definition: dvbtables.h:163
This table gives the current DVB stream time.
Definition: dvbtables.h:387
QDateTime UTC(void) const
Definition: dvbtables.h:405
const unsigned char * UTCdata(void) const
Definition: dvbtables.h:402
TimeDateTable(const PSIPTable &table)
Definition: dvbtables.h:389
time_t UTCUnix(void) const
Definition: dvbtables.h:406
~TimeDateTable() override
Definition: dvbtables.h:394
This table gives the current DVB stream time, plus descriptors.
Definition: dvbtables.h:413
TimeOffsetTable(const PSIPTable &table)
Definition: dvbtables.h:415
QDateTime UTC(void) const
Definition: dvbtables.h:431
time_t UTCUnix(void) const
Definition: dvbtables.h:432
~TimeOffsetTable() override
Definition: dvbtables.h:420
const unsigned char * Descriptors(void) const
Definition: dvbtables.h:440
const unsigned char * UTCdata(void) const
Definition: dvbtables.h:428
uint DescriptorsLength(void) const
Definition: dvbtables.h:436
static constexpr uint8_t byteBCD2int(uint8_t i)
static QDateTime dvbdate2qt(const std::array< uint8_t, 5 > buf)
Definition: dvbtables.h:20
static time_t dvbdate2unix(const std::array< uint8_t, 5 > buf)
Definition: dvbtables.h:24
uint32_t dvbdate2key(const unsigned char *buf)
Definition: dvbtables.cpp:369
unsigned int uint
Definition: freesurround.h:24
#define MTV_PUBLIC
Definition: mythtvexp.h:15