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