MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
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 <stdint.h> // uint32_t
8 
9 #include "dvbdescriptors.h"
10 #include "mpegtables.h"
11 #include "mythtvexp.h"
12 
13 QDateTime dvbdate2qt(const unsigned char*);
14 time_t dvbdate2unix(const unsigned char*);
15 uint32_t dvbdate2key(const unsigned char*);
16 
21 class MTV_PUBLIC NetworkInformationTable : public PSIPTable
22 {
23  public:
25  : PSIPTable(table), _cached_network_name(QString::null)
26  {
28  Parse();
29  }
31  : PSIPTable(table), _cached_network_name(QString::null)
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
54  uint NetworkDescriptorsLength(void) const
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
64  uint TransportStreamDataLength(void) const
65  { return ((_tsc_ptr[0]<<8) | _tsc_ptr[1]) & 0xfff; }
66  uint TransportStreamCount(void) const
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]; }
72  uint OriginalNetworkID(uint i) const
73  { return (_ptrs[i][2]<<8) | _ptrs[i][3]; }
74  // reserved_future_use 4 4.0+p
76  uint TransportDescriptorsLength(uint i) const
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 
84  void Parse(void) const;
85  QString toString(void) const;
86  QString NetworkName(void) const;
87 
88  private:
89  mutable QString _cached_network_name;
90  mutable const unsigned char* _tsc_ptr;
91  mutable vector<const unsigned char*> _ptrs; // used to parse
92 };
93 
98 class MTV_PUBLIC ServiceDescriptionTable : public PSIPTable
99 {
100  public:
102  : PSIPTable(table)
103  {
105  Parse();
106  }
108  {
110  Parse();
111  }
113 
114  // table_id 8 0.0 0x42/0x46
115  // section_syntax_indicator 1 1.0 1
116  // reserved_future_use 1 1.1 1
117  // reserved 2 1.2 3
118  // section_length 12 1.4 0
119  // reserved 2 5.0 3
120  // version_number 5 5.2 0
121  // current_next_indicator 1 5.7 1
122  // section_number 8 6.0 0x00
123  // last_section_number 8 7.0 0x00
124 
126  uint TSID() const { return TableIDExtension(); }
127 
129  uint OriginalNetworkID() const
130  { return (psipdata()[0]<<8) | psipdata()[1]; }
131 
133  uint ServiceCount() const { return _ptrs.size()-1; }
134 
135  // reserved_future_use 8 10.0
136  // for (i=0;i<N;i++) {
138  uint ServiceID(uint i) const { return (_ptrs[i][0]<<8) | (_ptrs[i][1]); }
139  // reserved_future_use 6 2.0+p
140  // EIT_schedule_flag 1 2.6+p
141  bool HasEITSchedule(uint i) const { return bool(_ptrs[i][2] & 0x2); }
142  // EIT_present_following 1 2.7+p
143  bool HasEITPresentFollowing(uint i) const
144  { return bool(_ptrs[i][2] & 0x1); }
146  uint RunningStatus(uint i) const { return (_ptrs[i][3] & 0xE0) >> 5; }
148  bool IsEncrypted(uint i) const { return bool(_ptrs[i][3] & 0x10); }
150  uint ServiceDescriptorsLength(uint i) const
151  { return ((_ptrs[i][3]<<8) | (_ptrs[i][4])) & 0xfff; }
154  const unsigned char* ServiceDescriptors(uint i) const
155  { return _ptrs[i]+5; }
156  // }
157  ServiceDescriptor *GetServiceDescriptor(uint i) const;
158 
160  bool Mutate(void);
161 
162  void Parse(void) const;
163  QString toString(void) const;
164 
165  private:
166  mutable vector<const unsigned char*> _ptrs; // used to parse
167 };
168 
176 class MTV_PUBLIC BouquetAssociationTable : public PSIPTable
177 {
178  public:
180  {
182  Parse();
183  }
185 
186  // table_id 8 0.0 0x4a
187  // section_syntax_indicator 1 1.0 1
188  // reserved_future_use 1 1.1 1
189  // reserved 2 1.2 3
190  // section_length 12 1.4 0
191  // Bouquet ID 16 3.0 0
192  uint BouquetID() const { return TableIDExtension(); }
193 
194  // reserved 2 5.0 3
195  // version_number 5 5.2 0
196  // current_next_indicator 1 5.7 1
197  // section_number 8 6.0 0x00
198  // last_section_number 8 7.0 0x00
199  // reserved 4 8 0x0d
200  uint BouquetDescriptorsLength(void) const
201  { return ((psipdata()[0]<<8) | psipdata()[1]) & 0xfff; }
202 
203  // Bouquet descriptors len 12 8.4
204  // for (i=0;i<N;i++)
205  // Descriptor();
206  const unsigned char* BouquetDescriptors(void) const
207  { return psipdata() + 2; }
208  // reserved 4 10+N.0
209 
210  // Transport stream loop len 12
211  uint TransportStreamDataLength(void) const
212  { return ((_tsc_ptr[0]<<8) | _tsc_ptr[1]) & 0xfff; }
213  uint TransportStreamCount(void) const
214  { return _ptrs.size() - 1; }
215 
216  // for (i=0;i<N;i++) {
217  // transport_stream_id 16
218  uint TSID(uint i) const { return (_ptrs[i][0] << 8) | _ptrs[i][1]; }
219  // original_network_id 16
220  uint OriginalNetworkID(uint i) const
221  { return (_ptrs[i][2] << 8) | _ptrs[i][3]; }
222  // reserved 4
223  // transport descriptor len 12
224  uint TransportDescriptorsLength(uint i) const
225  { return ((_ptrs[i][4]<<8) | _ptrs[i][5]) & 0xfff; }
228  const unsigned char* TransportDescriptors(uint i) const
229  { return _ptrs[i]+6; }
230  // }
231 
232  void Parse(void) const;
233  QString toString(void) const;
234 
235  private:
236  mutable const unsigned char* _tsc_ptr;
237  mutable vector<const unsigned char*> _ptrs;
238 };
239 
240 class MTV_PUBLIC DiscontinuityInformationTable : public PSIPTable
241 {
243  { ; }
244  // table_id 8
245  // section_syntax_indicator 1
246  // reserved_future_use 1
247  // reserved 2
248  // section_length 12
249  // transition_flag 1
250  // reserved_future_use 7
251 };
252 
253 class MTV_PUBLIC SelectionInformationTable : public PSIPTable
254 {
256  { ; }
257  // table_id 8
258  // section_syntax_indicator 1
259  // DVB_reserved_future_use 1
260  // ISO_reserved 2
261  // section_length 12
262  // DVB_reserved_future_use 16
263  // ISO_reserved 2
264  // version_number 5
265  // current_next_indicator 1
266  // section_number 8
267  // last_section_number 8
268  // DVB_reserved_for_future_use 4
269  // transmission_info_loop_length 12
270  // for (i =0;i<N;i++) { descriptor() }
271  // for (i=0;i<N;i++)
272  // {
273  // service_id 16
274  // DVB_reserved_future_use 1
275  // running_status 3
276  // service_loop_length 12
277  // for(j=0;j<N;j++) { descriptor() }
278  // }
279  // CRC_32 32 rpchof
280 };
281 
282 class MTV_PUBLIC DVBEventInformationTable : public PSIPTable
283 {
284  public:
286  {
287  // table_id 8 0.0 0xC7
288  assert(IsEIT(TableID()));
289  // section_syntax_indicator 1 1.0 1
290  // private_indicator 1 1.1 1
291  // reserved 2 1.2 3
292  // section_length 12 1.4
293  // reserved 2 5.0 3
294  // version_number 5 5.2
295  // current_next_indicator 1 5.7 1
296  // section_number 8 6.0
297  // last_section_number 8 7.0
298  Parse();
299  }
300 
301  // service_id 16 3.0
302  uint ServiceID(void) const { return TableIDExtension(); }
303 
304  // transport_stream_id 16 8.0
305  uint TSID(void) const
306  { return (psipdata()[0]<<8) | psipdata()[1]; }
307 
308  // original_network_id 16 10.0
309  uint OriginalNetworkID(void) const
310  { return (psipdata()[2]<<8) | psipdata()[3]; }
311 
312  // segment_last_section_num 8 12.0
313  uint SegmentLastSectionNumber(void) const
314  { return psipdata()[4]; }
315  // last_table_id 8 13.0
316  uint LastTableID(void) const
317  { return psipdata()[5]; }
318 
319  uint EventCount() const { return _ptrs.size()-1; }
320 
321  // for(i=0;i<N;i++) {
322  // event_id 16 0.0+x
323  uint EventID(uint i) const
324  { return (_ptrs[i][0]<<8) | _ptrs[i][1]; }
325  // start_time 40 2.0+x
326  const unsigned char *StartTime(uint i) const
327  { return _ptrs[i]+2; }
328  QDateTime StartTimeUTC(uint i) const
329  { return dvbdate2qt(StartTime(i)); }
330  time_t StartTimeUnixUTC(uint i) const
331  { return dvbdate2unix(StartTime(i)); }
332  time_t EndTimeUnixUTC(uint i) const
333  { return StartTimeUnixUTC(i) + DurationInSeconds(i); }
334  uint32_t StartTimeKey(uint i) const
335  { return dvbdate2key(StartTime(i)); }
336  // duration 24 7.0+x
337  const unsigned char *Duration(uint i) const
338  { return _ptrs[i]+7; }
339  uint DurationInSeconds(uint i) const
340  {
341  return ((byteBCD2int(Duration(i)[0]) * 3600) +
342  (byteBCD2int(Duration(i)[1]) * 60) +
343  (byteBCD2int(Duration(i)[2])));
344  }
345  // running_status 3 10.0+x
346  uint RunningStatus(uint i) const { return _ptrs[i][10] >> 5; }
347  // free_CA_mode 1 10.3+x
348  bool IsScrambled(uint i) const { return bool(_ptrs[i][10] & 0x10); }
349  // descriptors_loop_len 12 10.4+x
350  uint DescriptorsLength(uint i) const
351  { return ((_ptrs[i][10]<<8) | (_ptrs[i][11])) & 0xfff; }
352  // for(i=0;i<N;i++) y 12.0+x
353  // { descriptor() }
354  const unsigned char* Descriptors(uint i) const
355  { return _ptrs[i] + 12; }
356  // }
357  //CRC_32 32 rpchof
358 
359  void Parse(void) const;
360 
361  static bool IsEIT(uint table_id);
362 
363  private:
364  mutable vector<const unsigned char*> _ptrs; // used to parse
365 };
366 
370 class MTV_PUBLIC TimeDateTable : public PSIPTable
371 {
372  public:
373  TimeDateTable(const PSIPTable& table)
374  : PSIPTable(table)
375  {
377  }
379 
380  // table_id 8 0.0 0x70
381  // section_syntax_indicator 1 1.0 0
382  // reserved_future_use 1 1.1 1
383  // reserved 2 1.2 3
384  // section_length 12 1.4 40
385  // UTC_time 40 3.0 0
386  const unsigned char *UTCdata(void) const
387  { return pesdata() + 3; }
388 
389  QDateTime UTC(void) const { return dvbdate2qt(UTCdata()); }
390  time_t UTCUnix(void) const { return dvbdate2unix(UTCdata()); }
391 };
392 
393 #endif // _DVB_TABLES_H_