MythTV  master
mpegtables.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2003-2004, Daniel Thor Kristjansson
3 
4 #include "splicedescriptors.h"
5 #include "atscdescriptors.h"
6 #include "mythmiscutil.h" // for xml_indent
7 #include "mythlogging.h"
8 #include "mpegtables.h"
9 
10 const unsigned char DEFAULT_PAT_HEADER[8] =
11 {
12  0x00, // TableID::PAT
13  0xb0, // Syntax indicator
14  0x00, // Length (set separately)
15  0x00, // Transport stream ID top bits
16 
17  0x00, // Transport stream ID bottom bits
18  0xc1, // current | reserved
19  0x00, // Current Section
20  0x00, // Last Section
21 };
22 
23 const unsigned char DEFAULT_PMT_HEADER[12] =
24 {
25  0x02, // TableID::PMT
26  0xb0, // Syntax indicator
27  0x00, // Length (set separately)
28  0x00, // MPEG Program number top bits (set separately)
29 
30  0x00, // MPEG Program number bottom bits (set separately)
31  0xc1, // Version + Current/Next
32  0x00, // Current Section
33  0x00, // Last Section
34  0xff, 0xff, // PCR pid
35  0x00, 0x00, // Program Info Length
36 };
37 
38 static const uint len_for_alloc[] =
39 {
41  - 1 /* for start of field pointer */
42  - 3 /* for data before data last byte of pes length */,
43  4000,
44 };
45 
46 uint StreamID::Normalize(uint stream_id, const desc_list_t &desc,
47  const QString &sistandard)
48 {
49  if ((sistandard != "dvb") && (OpenCableVideo == stream_id))
50  return MPEG2Video;
51 
52  /* normalize DVB style signalling to ATSC style signalling to make
53  * IsAudio work with either, see A/52:2010 A4 vs A5 */
55  return AC3Audio;
56 
57  /* normalize DVB style signalling to ATSC style signalling to make
58  * IsAudio work with either */
60  return EAC3Audio;
61 
62  QString reg;
63  const unsigned char *d = MPEGDescriptor::Find(
65  if (d)
66  {
68  if (rd.IsValid())
69  reg = rd.FormatIdentifierString();
70  }
71 
72  /* normalize all three DTS frame sizes, via http://www.smpte-ra.org/mpegreg/mpegreg.html */
73  if ((reg == "DTS1") || (reg == "DTS2") || (reg == "DTS3"))
74  return DTSAudio;
75 
76  /* normalize AC-3 signalling according to A/52:2010 A4 */
77  if (reg == "AC-3")
78  return AC3Audio;
79 
80  /* normalize E-AC-3 signalling with guesswork via http://www.smpte-ra.org/mpegreg/mpegreg.html */
81  if (reg == "EAC3")
82  return EAC3Audio;
83 
84 #if 0
85  // not needed while there is no specific stream id for these
88  return stream_id;
89 #endif
90 
91  return stream_id;
92 }
93 
94 bool PSIPTable::HasCRC(void) const
95 {
96  // default is false, but gets set to true for 0x80-0xfe at the end!
97  bool has_crc = false;
98 
99  switch (TableID())
100  {
101  // MPEG
102  case TableID::PAT:
103  case TableID::CAT:
104  case TableID::PMT:
105  has_crc = true;
106  break;
107 // case TableID::TSDT
108 
109  // DVB manditory
110  case TableID::NIT:
111  case TableID::SDT:
112  case TableID::PF_EIT:
113  has_crc = true;
114  break;
115  case TableID::TDT:
116  has_crc = false;
117  break;
118 
119  // DVB optional
120  case TableID::NITo:
121  case TableID::SDTo:
122  case TableID::BAT:
123  case TableID::PF_EITo:
124  has_crc = true;
125  break;
126  case TableID::RST:
127  case TableID::ST:
128  has_crc = false;
129  break;
130  case TableID::TOT:
131  has_crc = true;
132  break;
133 // case TableID::RNT:
134 // case TableID::CT:
135 // case TableID::RCT:
136 // case TableID::CIT:
137 // case TableID::MPEFEC:
138  case TableID::DIT:
139  has_crc = false;
140  break;
141  case TableID::SIT:
142  has_crc = true;
143  break;
144 
145  // SCTE
146  case TableID::NITscte:
147  case TableID::NTT:
148  case TableID::SVCTscte:
149  case TableID::STTscte:
150  case TableID::SITscte:
151  has_crc = true;
152  break;
153  case TableID::ADET:
154  has_crc = false;
155  break;
156 
157  // ATSC
158  case TableID::MGT:
159  case TableID::TVCT:
160  case TableID::CVCT:
161  case TableID::RRT:
162  case TableID::EIT:
163  case TableID::ETT:
164  case TableID::STT:
165  case TableID::DET:
166  case TableID::DST:
167 
168  //case TableID::PIT:
169  case TableID::NRT:
170  case TableID::LTST:
171  case TableID::DCCT:
172  case TableID::DCCSCT:
173  //case TableID::SITatsc:
174  case TableID::AEIT:
175  case TableID::AETT:
176  case TableID::SVCT:
177  has_crc = true;
178  break;
179 
180  default:
181  {
182  // DVB Longterm EIT data
183  if (TableID::SC_EITbeg <= TableID() &&
185  {
186  has_crc = true;
187  }
188 
189  // FIXME Dishnet Longterm EIT data, only on PID 0x300! Forces
190  // table_id 0x80-0xfe to true, unless handled before or after!
191  if (TableID::DN_EITbego <= TableID() &&
193  {
194  has_crc = true;
195  }
196 
197  // ATSC/DVB conditional access ECM/EMM, reset to false after Dishnet
198  if (TableID::ECM0 <= TableID() &&
200  {
201  has_crc = false;
202  }
203  }
204  break;
205  }
206 
207  return has_crc;
208 }
209 
211 {
212  bool has_sn = false;
213  switch (TableID())
214  {
215  // MPEG
216  case TableID::PAT:
217  case TableID::CAT:
218  case TableID::PMT:
219  // ATSC
220  case TableID::MGT:
221  case TableID::TVCT:
222  case TableID::CVCT:
223  case TableID::RRT:
224  case TableID::EIT:
225  case TableID::ETT:
226  case TableID::STT:
227  case TableID::DET:
228  case TableID::DST:
229  has_sn = true;
230  break;
231  }
232 
233  return has_sn;
234 }
235 
236 bool PSIPTable::VerifyPSIP(bool verify_crc) const
237 {
238  if (verify_crc && (CalcCRC() != CRC()))
239  {
240  LOG(VB_SIPARSER, LOG_ERR,
241  QString("PSIPTable: Failed CRC check 0x%1 != 0x%2 "
242  "for StreamID = 0x%3")
243  .arg(CRC(),0,16).arg(CalcCRC(),0,16).arg(StreamID(),0,16));
244  return false;
245  }
246 
247  unsigned char *bufend = _fullbuffer + _allocSize;
248 
249  if ((_pesdata + 2) >= bufend)
250  return false; // can't query length
251 
252  if (psipdata() >= bufend)
253  return false; // data outside buffer
254 
255  if (TableID::PAT == TableID())
256  {
257  uint pcnt = (SectionLength() - PSIP_OFFSET - 2) >> 2;
258  bool ok = (psipdata() + (pcnt << 2) + 3 < bufend);
259  if (!ok)
260  {
261  LOG(VB_SIPARSER, LOG_ERR,
262  "PSIPTable: PAT: program list extends past end of buffer");
263  return false;
264  }
265 
266  if ((Length() == 0xfff) && (TableIDExtension() == 0xffff) &&
267  (Section() == 0xff) && (LastSection() == 0xff))
268  {
269  LOG(VB_SIPARSER, LOG_ERR, "PSIPTable: PAT: All values at maximums");
270  return false;
271  }
272 
273  return true;
274  }
275 
276  if (TableID::PMT == TableID())
277  {
278  if (psipdata() + 3 >= bufend)
279  {
280  LOG(VB_SIPARSER, LOG_ERR,
281  "PSIPTable: PMT: can't query program info length");
282  return false;
283  }
284 
285  if (psipdata() + Length() - 9 > bufend)
286  {
287  LOG(VB_SIPARSER, LOG_ERR,
288  "PSIPTable: PMT: reported length too large");
289  return false;
290  }
291 
292  uint proginfolen = ((psipdata()[2]<<8) | psipdata()[3]) & 0x0fff;
293  const unsigned char *proginfo = psipdata() + 4;
294  const unsigned char *cpos = proginfo + proginfolen;
295  if (cpos > bufend)
296  {
297  LOG(VB_SIPARSER, LOG_ERR,
298  "PSIPTable: PMT: program info extends past end of buffer");
299  return false;
300  }
301 
302  const unsigned char *pos = cpos;
303  uint i = 0;
304  for (; pos < psipdata() + Length() - 9; i++)
305  {
306  const unsigned char *ptr = pos;
307  if (pos + 4 > bufend)
308  {
309  LOG(VB_SIPARSER, LOG_ERR,
310  QString("PSIPTable: PMT: stream info %1 extends "
311  "past end of buffer").arg(i));
312  return false;
313  }
314  pos += 5 + (((ptr[3] << 8) | ptr[4]) & 0x0fff);
315  }
316  if (pos > bufend)
317  {
318  LOG(VB_SIPARSER, LOG_ERR,
319  QString("PSIPTable: PMT: last stream info %1 extends "
320  "past end of buffer").arg(i));
321  return false;
322  }
323 
324  return true;
325  }
326 
327  return true;
328 }
329 
331 {
332  (void) smallPacket; // currently always a small packet..
334  memcpy(tspacket->data() + sizeof(TSHeader) + 1/* start of field pointer */,
336  PSIPTable psip = PSIPTable::View(*tspacket);
337  psip.SetLength(TSPacket::kPayloadSize
338  - 1 /* for start of field pointer */
339  - 3 /* for data before data last byte of pes length */);
341  pat->SetTotalLength(sizeof(DEFAULT_PAT_HEADER));
342  delete tspacket;
343  return pat;
344 }
345 
347  uint tsid, uint version,
348  const vector<uint>& pnum, const vector<uint>& pid)
349 {
350  const uint count = min(pnum.size(), pid.size());
352  pat->SetVersionNumber(version);
353  pat->SetTranportStreamID(tsid);
354  pat->SetTotalLength(PSIP_OFFSET + (count * 4));
355 
356  // create PAT data
357  if ((count * 4) >= (184 - (PSIP_OFFSET+1)))
358  { // old PAT must be in single TS for this create function
359  LOG(VB_GENERAL, LOG_ERR,
360  "PAT::Create: Error, old PAT size exceeds maximum PAT size.");
361  delete pat;
362  return nullptr;
363  }
364 
365  uint offset = PSIP_OFFSET;
366  for (uint i = 0; i < count; i++)
367  {
368  // pnum
369  pat->pesdata()[offset++] = pnum[i]>>8;
370  pat->pesdata()[offset++] = pnum[i] & 0xff;
371  // pid
372  pat->pesdata()[offset++] = ((pid[i]>>8) & 0x1f) | 0xe0;
373  pat->pesdata()[offset++] = pid[i] & 0xff;
374  }
375 
376  pat->Finalize();
377 
378  return pat;
379 }
380 
382 {
383  ProgramMapTable *pmt = nullptr;
385  memcpy(tspacket->data() + sizeof(TSHeader) + 1/* start of field pointer */,
387 
388  if (smallPacket)
389  {
390  PSIPTable psip = PSIPTable::View(*tspacket);
391  psip.SetLength(len_for_alloc[0]);
392  pmt = new ProgramMapTable(psip);
393  }
394  else
395  {
396  PSIPTable psip(*tspacket);
397  psip.SetLength(len_for_alloc[1]);
398  pmt = new ProgramMapTable(psip);
399  }
400 
401  pmt->SetTotalLength(sizeof(DEFAULT_PMT_HEADER));
402  delete tspacket;
403  return pmt;
404 }
405 
407  uint programNumber, uint basepid, uint pcrpid, uint version,
408  vector<uint> pids, vector<uint> types)
409 {
410  const uint count = min(pids.size(), types.size());
411  ProgramMapTable* pmt = CreateBlank(false);
412  pmt->tsheader()->SetPID(basepid);
413 
414  pmt->RemoveAllStreams();
415  pmt->SetProgramNumber(programNumber);
416  pmt->SetPCRPID(pcrpid);
417  pmt->SetVersionNumber(version);
418 
419  for (uint i=0; i<count; i++)
420  pmt->AppendStream(pids[i], types[i]);
421  pmt->Finalize();
422 
423  return pmt;
424 }
425 
427  uint programNumber, uint basepid, uint pcrpid, uint version,
428  const desc_list_t &global_desc,
429  const vector<uint> &pids,
430  const vector<uint> &types,
431  const vector<desc_list_t> &prog_desc)
432 {
433  const uint count = min(pids.size(), types.size());
434  ProgramMapTable* pmt = CreateBlank(false);
435  pmt->tsheader()->SetPID(basepid);
436 
437  pmt->RemoveAllStreams();
438  pmt->SetProgramNumber(programNumber);
439  pmt->SetPCRPID(pcrpid);
440  pmt->SetVersionNumber(version);
441 
442  vector<unsigned char> gdesc;
443  for (uint i=0; i<global_desc.size(); i++)
444  {
445  uint len = global_desc[i][1] + 2;
446  gdesc.insert(gdesc.end(), global_desc[i], global_desc[i] + len);
447  }
448  pmt->SetProgramInfo(gdesc.data(), gdesc.size());
449 
450  for (uint i = 0; i < count; i++)
451  {
452  vector<unsigned char> pdesc;
453  for (uint j = 0; j < prog_desc[i].size(); j++)
454  {
455  uint len = prog_desc[i][j][1] + 2;
456  pdesc.insert(pdesc.end(),
457  prog_desc[i][j], prog_desc[i][j] + len);
458  }
459 
460  pmt->AppendStream(pids[i], types[i], pdesc.data(), pdesc.size());
461  }
462  pmt->Finalize();
463 
464  LOG(VB_SIPARSER, LOG_INFO, "Created PMT \n" + pmt->toString());
465 
466  return pmt;
467 }
468 
470 {
471  _ptrs.clear();
472  const unsigned char *cpos = psipdata() + pmt_header + ProgramInfoLength();
473  unsigned char *pos = const_cast<unsigned char*>(cpos);
474  for (uint i = 0; pos < psipdata() + Length() - 9; i++)
475  {
476  _ptrs.push_back(pos);
477  pos += 5 + StreamInfoLength(i);
478 #if 0
479  LOG(VB_SIPARSER, LOG_DEBUG, QString("Parsing PMT(0x%1) i(%2) len(%3)")
480  .arg((uint64_t)this, 0, 16) .arg(i) .arg(StreamInfoLength(i)));
481 #endif
482  }
483  _ptrs.push_back(pos);
484 #if 0
485  LOG(VB_SIPARSER, LOG_DEBUG, QString("Parsed PMT(0x%1)\n%2")
486  .arg((uint64_t)this, 0, 16) .arg(toString()));
487 #endif
488 }
489 
491  uint pid, uint type,
492  unsigned char* streamInfo, uint infoLength)
493 {
494  if (!StreamCount())
495  _ptrs.push_back(psipdata() + pmt_header + ProgramInfoLength());
496  memset(_ptrs[StreamCount()], 0xff, 5);
497  SetStreamPID(StreamCount(), pid);
499  SetStreamProgramInfo(StreamCount(), streamInfo, infoLength);
502 }
503 
514 bool ProgramMapTable::IsVideo(uint i, QString sistandard) const
515 {
517  return true;
518 
521  uint stream_id = StreamID::Normalize(StreamType(i), list, sistandard);
522 
523  return StreamID::IsVideo(stream_id);
524 }
525 
536 bool ProgramMapTable::IsAudio(uint i, QString sistandard) const
537 {
539  return true;
540 
543  uint stream_id = StreamID::Normalize(StreamType(i), list, sistandard);
544 
545  return StreamID::IsAudio(stream_id);
546 }
547 
552 bool ProgramMapTable::IsEncrypted(QString sistandard) const
553 {
554  bool encrypted = IsProgramEncrypted();
555 
556  for (uint i = 0; !encrypted && i < StreamCount(); i++) {
557  /* Only check audio/video streams */
558  if (IsAudio(i,sistandard) || IsVideo(i,sistandard))
559  encrypted |= IsStreamEncrypted(i);
560  }
561 
562  return encrypted;
563 }
564 
569 {
572 
573  uint encrypted = 0;
574  QMap<uint,uint> encryption_system;
575  for (uint i = 0; i < descs.size(); i++)
576  {
577  ConditionalAccessDescriptor cad(descs[i]);
578  encryption_system[cad.PID()] = cad.SystemID();
579  encrypted |= cad.SystemID();
580 
581 #if 0
582  LOG(VB_GENERAL, LOG_INFO, "DTVsm: " + cad.toString());
583 #endif
584  }
585 
586  return encrypted != 0;
587 }
588 
595 {
598 
599  uint encrypted = 0;
600  QMap<uint,uint> encryption_system;
601  for (uint j = 0; j < descs.size(); j++)
602  {
603  ConditionalAccessDescriptor cad(descs[j]);
604  encryption_system[cad.PID()] = cad.SystemID();
605  encrypted |= cad.SystemID();
606 
607 #if 0
608  LOG(VB_GENERAL, LOG_INFO, "DTVsm: " + cad.toString());
609 #endif
610  }
611 
612  return encrypted != 0;
613 }
614 
615 bool ProgramMapTable::IsStillPicture(QString sistandard) const
616 {
617  static const unsigned char STILL_PICTURE_FLAG = 0x01;
618 
619  for (uint i = 0; i < StreamCount(); i++)
620  {
621  if (IsVideo(i, sistandard))
622  {
623  return StreamInfoLength(i) > 2 &&
624  (StreamInfo(i)[2] & STILL_PICTURE_FLAG);
625  }
626  }
627  return false;
628 }
629 
630 
640  vector<uint> &pids,
641  const QString &sistandard) const
642 {
644  {
645  for (uint i=0; i < StreamCount(); i++)
646  if (type == StreamType(i))
647  pids.push_back(StreamPID(i));
648  }
649  else if (StreamID::AnyVideo == type)
650  {
651  for (uint i=0; i < StreamCount(); i++)
652  if (IsVideo(i, sistandard))
653  pids.push_back(StreamPID(i));
654  }
655  else if (StreamID::AnyAudio == type)
656  {
657  for (uint i=0; i < StreamCount(); i++)
658  if (IsAudio(i, sistandard))
659  pids.push_back(StreamPID(i));
660  }
661 
662  return pids.size();
663 }
664 
676  vector<uint> &pids,
677  vector<uint> &types,
678  const QString &sistandard,
679  bool normalize) const
680 {
681  uint pids_start = pids.size();
682 
684  {
685  for (uint i=0; i < StreamCount(); i++)
686  if (type == StreamType(i))
687  {
688  pids.push_back(StreamPID(i));
689  types.push_back(StreamType(i));
690  }
691  }
692  else if (StreamID::AnyVideo == type)
693  {
694  for (uint i=0; i < StreamCount(); i++)
695  if (IsVideo(i, sistandard))
696  {
697  pids.push_back(StreamPID(i));
698  types.push_back(StreamType(i));
699  }
700  }
701  else if (StreamID::AnyAudio == type)
702  {
703  for (uint i=0; i < StreamCount(); i++)
704  if (IsAudio(i, sistandard))
705  {
706  pids.push_back(StreamPID(i));
707  types.push_back(StreamType(i));
708  }
709  }
710 
711  if (!normalize)
712  return pids.size();
713 
714  for (uint i = pids_start; i < pids.size(); i++)
715  {
716  int index = FindPID(pids[i]);
717  if (index >= 0)
718  {
721  types[i] = StreamID::Normalize(types[i], desc, sistandard);
722  }
723  }
724 
725  return pids.size();
726 }
727 
729 {
730  uint pid = desired_pid;
731  if (pid >= MPEG_NULL_PID)
732  pid = 0x20;
733 
734  while (FindPID(pid) != -1)
735  pid += 0x10;
736 
737  if (pid < MPEG_NULL_PID)
738  return pid;
739 
740  pid = desired_pid;
741  while (FindPID(pid) != -1)
742  pid += 1;
743 
744  if (pid < MPEG_NULL_PID)
745  return pid;
746 
747  pid = 0x20;
748  while (FindPID(pid) != -1)
749  pid += 1;
750 
751  return pid & 0x1fff;
752 }
753 
754 QString PSIPTable::toString(void) const
755 {
756  QString str;
757  str.append(QString(" PSIP tableID(0x%1) length(%2) extension(0x%3)\n")
758  .arg(TableID(), 0, 16).arg(Length())
759  .arg(TableIDExtension(), 0, 16));
760  str.append(QString(" version(%1) current(%2) "
761  "section(%3) last_section(%4)\n")
762  .arg(Version()).arg(IsCurrent())
763  .arg(Section()).arg(LastSection()));
764  if ((TableID() >= TableID::MGT) && (TableID() <= TableID::SRM))
765  {
766  str.append(QString(" atsc_protocol_version(%1)\n")
767  .arg(ATSCProtocolVersion()));
768  }
769  return str;
770 }
771 
772 QString PSIPTable::toStringXML(uint indent_level) const
773 {
774  QString indent = xml_indent(indent_level);
775  return indent + "<PSIPSection " + XMLValues(indent_level + 1) + " />";
776 }
777 
778 QString PSIPTable::XMLValues(uint indent_level) const
779 {
780  QString indent = xml_indent(indent_level);
781 
782  QString str = QString(
783  "table_id=\"0x%1\" length=\"%2\"")
784  .arg(TableID(), 2, 16, QChar('0'))
785  .arg(Length());
786 
787  if (HasSectionNumber())
788  {
789  str += QString(" section=\"%4\" last_section=\"%5\"")
790  .arg(Section()).arg(LastSection());
791  }
792 
793  if ((TableID() >= TableID::MGT) && (TableID() <= TableID::SRM))
794  {
795  str += QString("\n%1version=\"%2\" current=\"%3\" "
796  "protocol_version=\"%4\" extension=\"0x%5\"")
797  .arg(indent)
798  .arg(Version()).arg(xml_bool_to_string(IsCurrent()))
799  .arg(ATSCProtocolVersion())
800  .arg(TableIDExtension(), 0, 16);
801  }
802 
803  return str;
804 }
805 
807 {
808  QString str;
809  str.append(QString("Program Association Section\n"));
810  str.append(PSIPTable::toString());
811  str.append(QString(" tsid(%1) ").arg(TransportStreamID()));
812  str.append(QString("programCount(%1)\n").arg(ProgramCount()));
813 
814  uint cnt0 = 0, cnt1fff = 0;
815  for (uint i = 0; i < ProgramCount(); i++)
816  {
817  if (0x1fff == ProgramPID(i))
818  {
819  cnt1fff++;
820  continue;
821  }
822 
823  if (0x0 == ProgramPID(i))
824  {
825  cnt0++;
826  continue;
827  }
828 
829  str += QString(" program number %1 has PID 0x%2\n")
830  .arg(ProgramNumber(i),5)
831  .arg(ProgramPID(i),4,16,QChar('0'));
832  }
833 
834  if (cnt0 || cnt1fff)
835  {
836  str.append(QString(" also contains %1 dummy programs\n")
837  .arg(cnt0 + cnt1fff));
838  }
839 
840  return str;
841 }
842 
843 QString ProgramAssociationTable::toStringXML(uint indent_level) const
844 {
845  QString indent_0 = xml_indent(indent_level);
846  QString indent_1 = xml_indent(indent_level + 1);
847 
848  QString str = QString(
849  "%1<ProgramAssociationSection tsid=\"0x%2\" program_count=\"%3\""
850  "\n%4%5>\n")
851  .arg(indent_0)
852  .arg(TransportStreamID(),4,16,QChar('0'))
853  .arg(ProgramCount())
854  .arg(indent_1)
855  .arg(PSIPTable::XMLValues(indent_level + 1));
856 
857  for (uint i = 0; i < ProgramCount(); i++)
858  {
859  bool dummy = (0x1fff == ProgramPID(i)) || (0x0 == ProgramPID(i));
860  str += QString("%1<Program number=\"%2\" pid=\"0x%3\" %4/>\n")
861  .arg(indent_1)
862  .arg(ProgramNumber(i))
863  .arg(ProgramPID(i),4,16,QChar('0'))
864  .arg(dummy ? "comment=\"Dummy Program\" " : "");
865  }
866 
867  return str + indent_0 + "</ProgramAssociationSection>";
868 }
869 
870 QString ProgramMapTable::toString(void) const
871 {
872  QString str =
873  QString("Program Map Section"
874  "\n%1"
875  " pnum(%2) pid(0x%3) pcrpid(%4)\n")
876  .arg(PSIPTable::toString())
877  .arg(ProgramNumber())
878  .arg(tsheader()->PID(),0,16)
879  .arg(PCRPID(),0,16);
880 
881  vector<const unsigned char*> desc =
883  for (uint i = 0; i < desc.size(); i++)
884  {
885  str.append(QString(" %1\n")
886  .arg(MPEGDescriptor(desc[i], 300).toString()));
887  }
888 
889  for (uint i = 0; i < StreamCount(); i++)
890  {
891  str.append(QString(" Stream #%1 pid(0x%2) type(0x%3 %4)\n")
892  .arg(i).arg(StreamPID(i), 0, 16)
893  .arg(StreamType(i), 2, 16, QChar('0'))
894  .arg(StreamTypeString(i)));
896  for (uint j = 0; j < desc.size(); j++)
897  {
898  str.append(QString(" %1\n")
899  .arg(MPEGDescriptor(desc[j], 300).toString()));
900  }
901  }
902  return str;
903 }
904 
905 QString ProgramMapTable::toStringXML(uint indent_level) const
906 {
907  QString indent_0 = xml_indent(indent_level);
908  QString indent_1 = xml_indent(indent_level + 1);
909 
910  QString str = QString(
911  "%1<ProgramMapSection pcr_pid=\"0x%2\" program_number=\"%3\"\n"
912  "%4program_info_length=\"%5\" stream_count=\"%7\"%8>\n")
913  .arg(indent_0)
914  .arg(PCRPID(),0,16)
915  .arg(ProgramNumber())
916  .arg(indent_1)
917  .arg(ProgramInfoLength())
918  .arg(StreamCount())
919  .arg(PSIPTable::XMLValues(indent_level + 1));
920 
921  vector<const unsigned char*> gdesc =
923  for (uint i = 0; i < gdesc.size(); i++)
924  {
925  str += MPEGDescriptor(gdesc[i], 300)
926  .toStringXML(indent_level + 1) + "\n";
927  }
928 
929  for (uint i = 0; i < StreamCount(); i++)
930  {
931  str += QString("%1<Stream pid=\"0x%2\" type=\"0x%3\" "
932  "type_desc=\"%4\" stream_info_length=\"%5\"")
933  .arg(indent_1)
934  .arg(StreamPID(i),2,16,QChar('0'))
935  .arg(StreamType(i),2,16,QChar('0'))
936  .arg(StreamTypeString(i))
937  .arg(StreamInfoLength(i));
938  vector<const unsigned char*> ldesc =
940  str += (ldesc.empty()) ? " />\n" : ">\n";
941  for (uint j = 0; j < ldesc.size(); j++)
942  {
943  str += MPEGDescriptor(ldesc[j], 300)
944  .toStringXML(indent_level + 2) + "\n";
945  }
946  if (!ldesc.empty())
947  str += indent_1 + "</Stream>\n";
948  }
949 
950  return str + indent_0 + "</ProgramMapSection>";
951 }
952 
953 const char *StreamID::toString(uint streamID)
954 {
955  // valid for some ATSC/DVB stuff too
956  switch (streamID)
957  {
959  return "video-mpeg2";
961  return "video-mpeg1";
963  return "video-mpeg4";
964  case StreamID::H264Video:
965  return "video-h264";
966  case StreamID::H265Video:
967  return "video-h265";
969  return "video-opencable";
970 
971  // audio
972  case StreamID::AC3Audio:
973  return "audio-ac3"; // EIT, PMT
974  case StreamID::EAC3Audio:
975  return "audio-eac3"; // EIT, PMT
977  return "audio-mp2-layer[1,2,3]"; // EIT, PMT
979  return "audio-mp1-layer[1,2,3]"; // EIT, PMT
981  return "audio-aac-latm"; // EIT, PMT
983  return "audio-aac"; // EIT, PMT
984  case StreamID::DTSAudio:
985  return "audio-dts"; // EIT, PMT
986 
987  // other
988  case StreamID::PrivSec:
989  return "private-sec";
990  case StreamID::PrivData:
991  return "private-data";
992 
993  // DSMCC Object Carousel
994  case StreamID::DSMCC_A:
995  return "dsmcc-a encap";
996  case StreamID::DSMCC_B:
997  return "dsmcc-b std data";
998  case StreamID::DSMCC_C:
999  return "dsmcc-c NPD data";
1000  case StreamID::DSMCC_D:
1001  return "dsmcc-d data";
1002 
1003  // Can be in any MPEG stream ATSC, DVB, or ARIB ; but defined in SCTE 35
1004  case StreamID::Splice:
1005  return "splice"; // PMT
1006 
1007  //case TableID::STUFFING: XXX: Duplicate?
1008  // return "stuffing"; // optionally in any
1009  //case TableID::CENSOR: FIXME collides with StreamID::EAC3Audio
1010  // return "censor"; // EIT, optionally in PMT
1011  case TableID::ECN:
1012  return "extended channel name";
1013  case TableID::SRVLOC:
1014  return "service location"; // required in VCT
1015  case TableID::TSS: // other channels with same stuff
1016  return "time-shifted service";
1017  case TableID::CMPNAME:
1018  return "component name"; //??? PMT
1019  }
1020  return "unknown";
1021 }
1022 
1023 QString StreamID::GetDescription(uint stream_id)
1024 {
1025  // valid for some ATSC/DVB stuff too
1026  switch (stream_id)
1027  {
1028  // video
1029  case StreamID::MPEG1Video:
1030  return "11172-2 MPEG-1 Video";
1031  case StreamID::MPEG2Video:
1032  return "13818-2 MPEG-2 Video";
1033  case StreamID::MPEG4Video:
1034  return "14492-2 MPEG-4 Video";
1035  case StreamID::H264Video:
1036  return "H.264 Video";
1037  case StreamID::H265Video:
1038  return "H.265 Video";
1040  return "OpenCable Video";
1041  case StreamID::VC1Video:
1042  return "VC-1 Video";
1043 
1044  // audio
1045  case StreamID::MPEG1Audio:
1046  return "11172-2 MPEG-1 Audio";
1047  case StreamID::MPEG2Audio:
1048  return "13818-3 MPEG-2 Audio";
1050  return "13818-7 AAC MPEG-2 Audio";
1052  return "13818-3 AAC LATM MPEG-2 Audio";
1053  case StreamID::AC3Audio:
1054  return "AC3 Audio";
1055  case StreamID::EAC3Audio:
1056  return "E-AC3 Audio";
1057  case StreamID::DTSAudio:
1058  return "DTS Audio";
1059 
1060  // DSMCC Object Carousel
1061  case StreamID::DSMCC:
1062  return "13818-1 DSM-CC";
1063  case StreamID::DSMCC_A:
1064  return "13818-6 DSM-CC Type A";
1065  case StreamID::DSMCC_B:
1066  return "13818-6 DSM-CC Type B";
1067  case StreamID::DSMCC_C:
1068  return "13818-6 DSM-CC Type C";
1069  case StreamID::DSMCC_D:
1070  return "13818-6 DSM-CC Type D";
1071  case StreamID::DSMCC_DL:
1072  return "13818-6 Download";
1073  case StreamID::MetaDataPES:
1074  return "13818-6 Metadata in PES";
1075  case StreamID::MetaDataSec:
1076  return "13818-6 Metadata in Sections";
1077  case StreamID::MetaDataDC:
1078  return "13818-6 Metadata in Data Carousel";
1079  case StreamID::MetaDataOC:
1080  return "13818-6 Metadata in Obj Carousel";
1081  case StreamID::MetaDataDL:
1082  return "13818-6 Metadata in Download";
1083 
1084  // other
1085  case StreamID::PrivSec:
1086  return "13818-1 Private Sections";
1087  case StreamID::PrivData:
1088  return "13818-3 Private Data";
1089  case StreamID::MHEG:
1090  return "13522 MHEG";
1091  case StreamID::H222_1:
1092  return "ITU H.222.1";
1093  case StreamID::MPEG2Aux:
1094  return "13818-1 Aux & ITU H.222.0";
1095  case StreamID::FlexMuxPES:
1096  return "14496-1 SL/FlexMux in PES";
1097  case StreamID::FlexMuxSec:
1098  return "14496-1 SL/FlexMux in Sections";
1099  case StreamID::MPEG2IPMP:
1100  return "13818-10 IPMP";
1101  case StreamID::MPEG2IPMP2:
1102  return "13818-10 IPMP2";
1103 
1104  case AnyMask: return QString();
1105  case AnyVideo: return "video";
1106  case AnyAudio: return "audio";
1107  }
1108 
1109  return QString();
1110 }
1111 
1113 {
1114  const desc_list_t list = MPEGDescriptor::Parse(
1115  StreamInfo(i), StreamInfoLength(i));
1116  const unsigned char *lang_desc = MPEGDescriptor::Find(
1118 
1119  if (!lang_desc)
1120  return QString();
1121 
1122  ISO639LanguageDescriptor iso_lang(lang_desc);
1123  return iso_lang.CanonicalLanguageString();
1124 }
1125 
1127 {
1128  const desc_list_t list = MPEGDescriptor::Parse(
1129  StreamInfo(i), StreamInfoLength(i));
1130  const unsigned char *lang_desc = MPEGDescriptor::Find(
1132 
1133  if (!lang_desc)
1134  return 0;
1135 
1136  ISO639LanguageDescriptor iso_lang(lang_desc);
1137 
1138  // Hack for non-standard AD labelling on UK Satellite and Irish DTTV
1139  // Language string of 'nar' for narrative indicates an AD track
1140  if (iso_lang.AudioType() == 0x0 &&
1141  iso_lang.LanguageString() == "nar")
1142  return 0x03;
1143 
1144  return iso_lang.AudioType();
1145 }
1146 
1147 QString ProgramMapTable::StreamDescription(uint i, QString sistandard) const
1148 {
1149  desc_list_t list;
1150 
1152  uint type = StreamID::Normalize(StreamType(i), list, sistandard);
1153  QString desc = StreamID::toString(type);
1154  QString lang = GetLanguage(i);
1155 
1156  if (!lang.isEmpty())
1157  desc += QString(" (%1)").arg(lang);
1158 
1159  return desc;
1160 }
1161 
1163 {
1164  QString str =
1165  QString("Condiditional Access Section %1")
1166  .arg(PSIPTable::toString());
1167 
1168  vector<const unsigned char*> gdesc =
1170  for (uint i = 0; i < gdesc.size(); i++)
1171  str += " " + MPEGDescriptor(gdesc[i], 300).toString() + "\n";
1172 
1173  str += "\n";
1174 
1175  return str;
1176 }
1177 
1178 QString ConditionalAccessTable::toStringXML(uint indent_level) const
1179 {
1180  QString indent_0 = xml_indent(indent_level);
1181 
1182  QString str =
1183  QString("%1<ConditionalAccessSection %3")
1184  .arg(indent_0)
1185  .arg(PSIPTable::XMLValues(indent_level + 1));
1186 
1187  vector<const unsigned char*> gdesc =
1189  str += (gdesc.empty()) ? " />\n" : ">\n";
1190  for (uint i = 0; i < gdesc.size(); i++)
1191  {
1192  str += MPEGDescriptor(gdesc[i], 300)
1193  .toStringXML(indent_level + 1) + "\n";
1194  }
1195  if (!gdesc.empty())
1196  str += indent_0 + "</ConditionalAccessSection>\n";
1197 
1198  return str;
1199 }
1200 
1201 QString SpliceTimeView::toString(int64_t first, int64_t last) const
1202 {
1203  if (!IsTimeSpecified())
1204  return QString("splice_time(N/A)");
1205 
1206  int64_t abs_pts_time = PTSTime();
1207  if ((first > 0) && (last > 0))
1208  {
1209  int64_t elapsed = abs_pts_time - first;
1210  elapsed = (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
1211  QTime abs = QTime(0,0,0,0).addMSecs(elapsed/90);
1212 
1213  elapsed = abs_pts_time - last; /* rel_pts_time */
1214  elapsed = (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
1215  QTime rel = QTime(0,0,0,0).addMSecs(elapsed/90);
1216 
1217  return QString("splice_time(pts: %1 abs: %2, rel: +%3)")
1218  .arg(abs_pts_time)
1219  .arg(abs.toString("hh:mm:ss.zzz"))
1220  .arg(rel.toString("hh:mm:ss.zzz"));
1221  }
1222 
1223  return QString("splice_time(pts: %1)").arg(abs_pts_time);
1224 }
1225 
1227  uint indent_level, int64_t first, int64_t last) const
1228 {
1229  QString indent = xml_indent(indent_level);
1230 
1231  if (!IsTimeSpecified())
1232  return indent + "<SpliceTime />";
1233 
1234  int64_t abs_pts_time = PTSTime();
1235 
1236  QString abs_str;
1237  if (first > 0)
1238  {
1239  int64_t elapsed = abs_pts_time - first;
1240  elapsed = (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
1241  QTime abs = QTime(0,0,0,0).addMSecs(elapsed/90);
1242  abs_str = QString("absolute=\"%1\" ")
1243  .arg(abs.toString("hh:mm:ss.zzz"));
1244  }
1245 
1246  QString rel_str;
1247  if (last > 0)
1248  {
1249  int64_t elapsed = abs_pts_time - last; /* rel_pts_time */
1250  elapsed = (elapsed < 0) ? elapsed + 0x1000000000LL : elapsed;
1251  QTime rel = QTime(0,0,0,0).addMSecs(elapsed/90);
1252  rel_str = QString("relative=\"+%1\" ")
1253  .arg(rel.toString("hh:mm:ss.zzz"));
1254  }
1255 
1256  return QString("%1<SpliceTime pts=\"%2\" %3%4/>")
1257  .arg(indent).arg(abs_pts_time).arg(abs_str).arg(rel_str);
1258 }
1259 
1262  const QString &/*codeWord*/) const
1263 {
1264  // TODO
1265  return nullptr;
1266 }
1267 
1269 {
1270  _epilog = nullptr;
1271  _ptrs0.clear();
1272  _ptrs1.clear();
1273 
1274  if (TableID::SITscte != TableID())
1275  return false;
1276 
1277  if (SpliceProtocolVersion() != 0)
1278  return false;
1279 
1280  if (IsEncryptedPacket())
1281  return true; // it's "parsed" but you can't read encrypted portion
1282 
1285  {
1286  _epilog = pesdata() + 14;
1287  }
1288  else if (kSCTTimeSignal == type)
1289  {
1290  _epilog = pesdata() + 14 + TimeSignal().size();
1291  }
1292  else if (kSCTSpliceSchedule == type)
1293  {
1294  uint splice_count = pesdata()[14];
1295  const unsigned char *cur = pesdata() + 15;
1296  for (uint i = 0; i < splice_count; i++)
1297  {
1298  _ptrs0.push_back(cur);
1299  bool event_cancel = cur[4] & 0x80;
1300  if (event_cancel)
1301  {
1302  _ptrs1.push_back(nullptr);
1303  cur += 5;
1304  continue;
1305  }
1306  bool program_slice = cur[5] & 0x40;
1307  uint component_count = cur[6];
1308  _ptrs1.push_back(cur + (program_slice ? 10 : 7 * component_count));
1309  }
1310  if (splice_count)
1311  {
1312  bool duration = _ptrs0.back()[5] & 0x2;
1313  _epilog = _ptrs1.back() + ((duration) ? 9 : 4);
1314  }
1315  else
1316  {
1317  _epilog = cur;
1318  }
1319  }
1320  else if (kSCTSpliceInsert == type)
1321  {
1322  _ptrs1.push_back(pesdata() + 14);
1323  bool splice_cancel = pesdata()[18] & 0x80;
1324  if (splice_cancel)
1325  {
1326  _epilog = pesdata() + 19;
1327  }
1328  else
1329  {
1330  bool program_splice = pesdata()[19] & 0x40;
1331  bool duration = pesdata()[19] & 0x20;
1332  bool splice_immediate = pesdata()[19] & 0x10;
1333  const unsigned char *cur = pesdata() + 20;
1334  if (program_splice && !splice_immediate)
1335  {
1336  cur += SpliceTimeView(cur).size();
1337  }
1338  else if (!program_splice)
1339  {
1340  uint component_count = pesdata()[20];
1341  cur = pesdata() + 21;
1342  for (uint i = 0; i < component_count; i++)
1343  {
1344  _ptrs0.push_back(cur);
1345  cur += (splice_immediate) ?
1346  1 : 1 + SpliceTimeView(cur).size();
1347  }
1348  }
1349  _ptrs1.push_back(cur);
1350  _ptrs1.push_back(cur + (duration ? 5 : 0));
1351  }
1352  }
1353  else
1354  {
1355  _epilog = nullptr;
1356  }
1357 
1358  return _epilog != nullptr;
1359 }
1360 
1362 {
1363  uint alg = EncryptionAlgorithm();
1364  switch (alg)
1365  {
1366  case kNoEncryption: return "None";
1367  case kECB: return "DES-ECB";
1368  case kCBC: return "DES-CBC";
1369  case k3DES: return "3DES";
1370  default:
1371  return QString((alg<32) ? "Reserved(%1)" : "Private(%1)").arg(alg);
1372  }
1373 }
1374 
1376 {
1378  switch (type)
1379  {
1380  case kSCTNull:
1381  return "Null";
1382  case kSCTSpliceSchedule:
1383  return "SpliceSchedule";
1384  case kSCTSpliceInsert:
1385  return "SpliceInsert";
1386  case kSCTTimeSignal:
1387  return "TimeSignal";
1389  return "BandwidthReservation";
1390  case kSCTPrivateCommand:
1391  return "Private";
1392  default:
1393  return QString("Reserved(%1)").arg(type);
1394  };
1395 }
1396 
1397 QString SpliceInformationTable::toString(int64_t first, int64_t last) const
1398 {
1399  QString str =
1400  QString("SpliceInformationSection enc_alg(%1) pts_adj(%2)")
1402  .arg(PTSAdjustment());
1403  str += IsEncryptedPacket() ? QString(" cw_index(%1)") : QString("");
1404  str += QString(" command_len(%1) command_type(%2) scte_pid(0x%3)")
1405  .arg(SpliceCommandLength())
1407  .arg(getSCTEPID(), 0, 16));
1408 
1409  if (IsEncryptedPacket())
1410  return str;
1411 
1412  switch (SpliceCommandType())
1413  {
1414  case kSCTSpliceSchedule:
1415  break;
1416  case kSCTSpliceInsert:
1417  {
1418  str += "\n " + SpliceInsert().toString(first, last);
1419  break;
1420  }
1421  case kSCTTimeSignal:
1422  break;
1423  }
1424 
1425  return str;
1426 }
1427 
1428 QString SpliceInsertView::toString(int64_t first, int64_t last) const
1429 {
1430  QString str =
1431  QString("eventid(0x%1) cancel(%2) "
1432  "out_of_network(%3) program_splice(%4) "
1433  "duration(%5) immediate(%6)\n ")
1434  .arg(SpliceEventID(),0,16)
1435  .arg(IsSpliceEventCancel()?"yes":"no")
1436  .arg(IsOutOfNetwork()?"yes":"no")
1437  .arg(IsProgramSplice()?"yes":"no")
1438  .arg(IsDuration()?"yes":"no")
1439  .arg(IsSpliceImmediate()?"yes":"no");
1440 
1441  if (IsProgramSplice() && !IsSpliceImmediate())
1442  str += SpliceTime().toString(first, last);
1443 
1444  str += QString(" unique_program_id(%1)")
1445  .arg(UniqueProgramID());
1446 
1447  str += QString(" avail(%1/%2)")
1448  .arg(AvailNum()).arg(AvailsExpected());
1449 
1450  return str;
1451 }
1452 
1454  uint indent_level, int64_t first, int64_t last) const
1455 {
1456  QString indent = xml_indent(indent_level);
1457 
1458  QString cap_time = "";
1459  if (first >= 0)
1460  {
1461  cap_time = QString("pts=\"%1\" ").arg(first);
1462  if (last >= 0)
1463  {
1464  QTime abs = QTime(0,0,0,0).addMSecs((last - first)/90);
1465  cap_time += QString("capture_time=\"%1\" ")
1466  .arg(abs.toString("hh:mm:ss.zzz"));
1467  }
1468  }
1469 
1470  QString str = QString(
1471  "%1<SpliceInformationSection %2 encryption_algorithm=\"%3\" "
1472  "pts_adjustment=\"%4\" code_word_index=\"%5\" command_type=\"%6\" scte_pid=\"0x%7\" >\n")
1473  .arg(indent)
1474  .arg(cap_time)
1476  .arg(PTSAdjustment())
1477  .arg(CodeWordIndex())
1478  .arg(SpliceCommandTypeString())
1479  .arg(getSCTEPID(), 0 ,16);
1480 
1481  if (IsEncryptedPacket())
1482  return str + indent + "</SpliceInformationSection>";
1483 
1484  switch (SpliceCommandType())
1485  {
1486  case kSCTSpliceSchedule:
1487  break;
1488  case kSCTSpliceInsert:
1489  {
1490  str += SpliceInsert().toStringXML(indent_level + 1, first, last);
1491  str += "\n";
1492  break;
1493  }
1494  case kSCTTimeSignal:
1495  break;
1496  }
1497 
1498  str += indent + "</SpliceInformationSection>";
1499  return str;
1500 }
1501 
1503  uint indent_level, int64_t first, int64_t last) const
1504 {
1505  QString indent_0 = xml_indent(indent_level);
1506  QString indent_1 = xml_indent(indent_level + 1);
1507  QString str = QString(
1508  "%1<SpliceInsert eventid=\"0x%2\" cancel=\"%3\"\n")
1509  .arg(indent_0)
1510  .arg(SpliceEventID(),0,16)
1512 
1513  str += QString(
1514  "%1out_of_network=\"%2\" program_splice=\"%3\" duration=\"%4\"\n")
1515  .arg(indent_1)
1518  .arg(xml_bool_to_string(IsDuration()));
1519 
1520  str += QString(
1521  "%1immediate=\"%2\" unique_program_id=\"%3\"\n"
1522  "%4avail_num=\"%5\" avails_expected=\"%6\">\n")
1523  .arg(indent_1)
1525  .arg(UniqueProgramID())
1526  .arg(indent_1)
1527  .arg(AvailNum())
1528  .arg(AvailsExpected());
1529 
1530  if (IsProgramSplice() && !IsSpliceImmediate())
1531  {
1532  str += SpliceTime().toStringXML(indent_level + 1, first, last) + "\n";
1533  }
1534 
1535  str += indent_0 + "</SpliceInsert>";
1536  return str;
1537 }
const unsigned char DEFAULT_PMT_HEADER[12]
Definition: mpegtables.cpp:23
uint SpliceEventID(void) const
Definition: mpegtables.h:938
Used to access the data of a Transport Stream packet.
Definition: tspacket.h:127
uint AvailNum(void) const
Definition: mpegtables.h:976
const unsigned char * pesdata() const
Definition: pespacket.h:163
static uint Normalize(uint stream_id, const desc_list_t &desc, const QString &sistandard)
Definition: mpegtables.cpp:46
const unsigned char * psipdata(void) const
Definition: mpegtables.h:522
const TSHeader * tsheader() const
Definition: pespacket.h:89
uint Version(void) const
Definition: mpegtables.h:503
const unsigned char DEFAULT_PAT_HEADER[8]
Definition: mpegtables.cpp:10
bool IsStillPicture(QString sistandard) const
Returns true iff PMT contains a still-picture video stream.
Definition: mpegtables.cpp:615
ISO 13818-3/AMD-1 Audio using LATM syntax.
Definition: mpegtables.h:124
uint Length() const
Definition: pespacket.h:98
QString SpliceCommandTypeString(void) const
static TSPacket * CreatePayloadOnlyPacket()
Definition: tspacket.h:135
SpliceInformationTable * GetDecrypted(const QString &codeWord) const
Returns decrypted version of this packet.
void SetLength(uint len)
Definition: pespacket.h:170
struct exc__state * last
Definition: pxsup2dast.c:98
ProgramMapTable(const ProgramMapTable &table)
Definition: mpegtables.h:660
uint ProgramCount(void) const
Definition: mpegtables.h:600
static const PSIPTable View(const TSPacket &tspacket)
Definition: mpegtables.h:467
uint SpliceProtocolVersion(void) const
Definition: mpegtables.h:1019
QString toString(void) const override
Definition: mpegtables.h:1155
static desc_list_t ParseOnlyInclude(const unsigned char *data, uint len, int descriptorid)
ISO 13818-1 auxiliary & ITU H.222.0.
Definition: mpegtables.h:149
uint FindUnusedPID(uint desired_pid=0x20)
Definition: mpegtables.cpp:728
ProgramAssociationTable(const ProgramAssociationTable &table)
Definition: mpegtables.h:582
QString toString() const override
unsigned char * _fullbuffer
Pointer to allocated data.
Definition: pespacket.h:218
void Parse(void) const
Definition: mpegtables.cpp:469
Meta data in PES packets.
Definition: mpegtables.h:136
uint TableIDExtension(void) const
Definition: mpegtables.h:496
QString CanonicalLanguageString(void) const
unsigned char * _pesdata
Pointer to PES data in full buffer.
Definition: pespacket.h:217
QString EncryptionAlgorithmString(void) const
uint SectionLength(void) const
Definition: mpegtables.h:490
QString toString(void) const override
Definition: mpegtables.cpp:870
uint AvailsExpected(void) const
Definition: mpegtables.h:978
bool IsOutOfNetwork(void) const
Definition: mpegtables.h:948
uint EncryptionAlgorithm(void) const
Definition: mpegtables.h:1037
static bool IsAudio(uint type)
Returns true iff audio is MPEG1/2, AAC, AC3 or DTS audio stream.
Definition: mpegtables.h:176
void SetStreamType(uint i, uint type)
Definition: mpegtables.h:732
uint ProgramNumber(uint i) const
Definition: mpegtables.h:607
uint LastSection(void) const
Definition: mpegtables.h:515
ISO 13818-7 Audio w/ADTS syntax.
Definition: mpegtables.h:123
bool IsEncryptedPacket(void) const
Definition: mpegtables.h:1022
static const uint PSIP_OFFSET
Definition: mpegtables.h:555
ISO 13818-1 private tables & ITU H.222.0.
Definition: mpegtables.h:143
unsigned int uint
Definition: compat.h:140
virtual QString toString(void) const
ISO 13818-6 type C NPT DSMCC Data.
Definition: mpegtables.h:133
const unsigned char * Descriptors(void) const
Definition: mpegtables.h:843
int getSCTEPID(void) const
Definition: mpegtables.h:1008
bool IsAudio(uint i, QString sistandard) const
Returns true iff the stream at index i is an audio stream.
Definition: mpegtables.cpp:536
vector< const unsigned char * > desc_list_t
virtual QString toString(int64_t first, int64_t last) const
bool IsCurrent(void) const
Definition: mpegtables.h:509
ANSI/SCTE 35 2007.
Definition: mpegtables.h:157
uint CalcCRC(void) const
Definition: pespacket.cpp:145
uint SpliceCommandType(void) const
Definition: mpegtables.h:1090
uint PCRPID(void) const
stream that contrains program clock reference.
Definition: mpegtables.h:690
Used to access header of a TSPacket.
Definition: tspacket.h:23
ISO 14496-1 SL/FlexMux in PES packets.
Definition: mpegtables.h:151
uint Section(void) const
Definition: mpegtables.h:512
vector< unsigned char * > _ptrs
Definition: mpegtables.h:811
bool IsSpliceEventCancel(void) const
Definition: mpegtables.h:944
QString GetLanguage(uint i) const
Returns the cannonical language if we find the iso639 descriptor.
static const unsigned int kPayloadSize
Definition: tspacket.h:182
static const uint pmt_header
Definition: mpegtables.h:810
uint UniqueProgramID(void) const
Definition: mpegtables.h:973
static bool IsVideo(uint type)
Returns true iff video is an MPEG1/2/3, H264 or open cable video stream.
Definition: mpegtables.h:165
Meta data in metadata_section's.
Definition: mpegtables.h:137
uint StreamInfoLength(uint i) const
Definition: mpegtables.h:708
uint StreamType(uint i) const
Definition: mpegtables.h:702
static ProgramAssociationTable * Create(uint tsid, uint version, const vector< uint > &pnum, const vector< uint > &pid)
Definition: mpegtables.cpp:346
void SetTotalLength(uint len)
Definition: pespacket.h:175
static ProgramMapTable * Create(uint programNumber, uint basepid, uint pcrpid, uint version, vector< uint > pids, vector< uint > types)
Definition: mpegtables.cpp:406
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
Definition: mpegtables.h:371
ISO 13818-1 PES private data & ITU H.222.0.
Definition: mpegtables.h:144
vector< const unsigned char * > _ptrs0
Definition: mpegtables.h:1164
uint StreamPID(uint i) const
Definition: mpegtables.h:705
bool IsProgramSplice(void) const
Definition: mpegtables.h:950
uint StreamID() const
Definition: pespacket.h:97
QString toStringXML(uint indent_level) const override
Definition: mpegtables.cpp:905
ISO 13818-6 Metadata in Download Protocol.
Definition: mpegtables.h:140
virtual QString toStringXML(uint indent_level, int64_t first, int64_t last) const
uint StreamCount(void) const
Definition: mpegtables.h:714
const unsigned char * StreamInfo(uint i) const
Definition: mpegtables.h:711
SpliceTimeView SpliceTime(void) const
Definition: mpegtables.h:958
SMPTE 421M video codec (aka VC1) in Blu-Ray.
Definition: mpegtables.h:118
ISO 11172-3.
Definition: mpegtables.h:121
static const uint16_t * d
QString toStringXML(uint indent_level) const override
Definition: mpegtables.cpp:843
static ProgramAssociationTable * CreateBlank(bool smallPacket=true)
Definition: mpegtables.cpp:330
ISO 23008-2 & ITU H.265 (aka HEVC, Ultra HD)
Definition: mpegtables.h:116
uint _allocSize
Total number of bytes we allocated.
Definition: pespacket.h:223
uint SpliceCommandLength(void) const
Definition: mpegtables.h:1067
static const uint len_for_alloc[]
Definition: mpegtables.cpp:38
uint GetAudioType(uint i) const
Returns the audio type from the iso 639 descriptor.
uint FindPIDs(uint type, vector< uint > &pids, const QString &sistandard) const
Finds all pids matching type.
Definition: mpegtables.cpp:639
uint DescriptorsLength(void) const
Definition: mpegtables.h:841
const unsigned char * _epilog
Definition: mpegtables.h:1166
ISO 14496-1 SL/FlexMux in 14496_sections.
Definition: mpegtables.h:152
static QString indent(uint level)
ISO 13818-10 Digital Restrictions Mangment.
Definition: mpegtables.h:155
uint CodeWordIndex(void) const
Definition: mpegtables.h:1063
void SetStreamProgramInfo(uint i, unsigned char *streamInfo, uint infoLength)
Definition: mpegtables.h:789
ISO 13818-3.
Definition: mpegtables.h:122
A/53 Part 3:2009 6.7.1.
Definition: mpegtables.h:125
vector< const unsigned char * > _ptrs1
Definition: mpegtables.h:1165
bool IsTimeSpecified(void) const
Definition: mpegtables.h:856
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
Definition: mpegtables.h:579
static const unsigned char * Find(const desc_list_t &parsed, uint desc_tag)
uint TransportStreamID(void) const
Definition: mpegtables.h:598
ISO 13818-6 type D Any DSMCC Data.
Definition: mpegtables.h:134
QString toString(void) const override
void SetStreamPID(uint i, uint pid)
Definition: mpegtables.h:726
uint CRC(void) const
Definition: pespacket.h:188
ISO 14492-2 (aka MPEG-4)
Definition: mpegtables.h:114
bool IsDuration(void) const
Definition: mpegtables.h:952
QString StreamTypeString(uint i) const
Returns a string representation of type at stream index i.
Definition: mpegtables.h:744
QString FormatIdentifierString(void) const
ISO 13818-6 Metadata in Object Carousel.
Definition: mpegtables.h:139
uint TableID(void) const
Definition: mpegtables.h:479
ISO 14492-10 & ITU H.264 (aka MPEG-4-AVC)
Definition: mpegtables.h:115
ISO 13818-6 Download Protocol.
Definition: mpegtables.h:135
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
virtual QString toString(int64_t first, int64_t last) const
int FindPID(uint pid) const
Locates stream index of pid.
Definition: mpegtables.h:761
static int x0
Definition: mythsocket.cpp:59
bool VerifyPSIP(bool verify_crc) const
Definition: mpegtables.cpp:236
QString toString(void) const override
Definition: mpegtables.cpp:806
static QString GetDescription(uint streamID)
static ProgramMapTable * CreateBlank(bool smallPacket=true)
Definition: mpegtables.cpp:381
QString XMLValues(uint indent_level) const
Definition: mpegtables.cpp:778
uint ProgramNumber(void) const
Definition: mpegtables.h:693
ISO 13818-1 Annex A DSM-CC & ITU H.222.0.
Definition: mpegtables.h:130
ISO 13818-6 Metadata in Data Carousel.
Definition: mpegtables.h:138
uint ProgramInfoLength(void) const
Definition: mpegtables.h:696
static const char * toString(uint streamID)
Definition: mpegtables.cpp:953
bool IsSpliceImmediate(void) const
Definition: mpegtables.h:954
virtual QString toString(void) const
Definition: mpegtables.cpp:754
ISO 13522 MHEG.
Definition: mpegtables.h:146
bool IsEncrypted(QString sistandard) const
Returns true iff PMT contains CA descriptor for a vid/aud stream.
Definition: mpegtables.cpp:552
QString StreamDescription(uint i, QString sistandard) const
Returns a better (and more expensive) string representation of type at stream index i than StreamType...
uint64_t PTSTime(void) const
Definition: mpegtables.h:860
ISO 13818-10 Digital Restrictions Mangment.
Definition: mpegtables.h:154
QString toStringXML(uint indent_level) const override
Definition: mpegtables.h:1157
const unsigned char * data() const
Definition: tspacket.h:113
uint64_t PTSAdjustment(void) const
Definition: mpegtables.h:1045
static QString xml_bool_to_string(bool val)
Definition: mythmiscutil.h:60
bool HasSectionNumber(void) const
Definition: mpegtables.cpp:210
bool IsValid(void) const
The all-ones PID value 0x1FFF indicates a Null TS Packet introduced to maintain a constant bit rate o...
Definition: mpegtables.h:233
QString LanguageString(void) const
uint size(void) const
Definition: mpegtables.h:875
uint ATSCProtocolVersion(void) const
Definition: mpegtables.h:519
void AppendStream(uint pid, uint type, unsigned char *si=nullptr, uint il=0)
Definition: mpegtables.cpp:490
ISO 13818-2 & ITU H.262 (aka MPEG-2)
Definition: mpegtables.h:113
SpliceInsertView SpliceInsert(void) const
Definition: mpegtables.h:1109
virtual QString toStringXML(uint indent_level) const
Returns XML representation of string the TS Reader XML format.
ISO 13818-6 type A Multi-protocol Encap.
Definition: mpegtables.h:131
A/53 Part 3:2009 6.7.3.
Definition: mpegtables.h:126
bool HasCRC(void) const override
1 bit Cyclic Redundancy Check present
Definition: mpegtables.cpp:94
virtual QString toStringXML(uint indent_level) const
Definition: mpegtables.cpp:772
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
Definition: mpegtables.h:656
static desc_list_t Parse(const unsigned char *data, uint len)
bool IsVideo(uint i, QString sistandard) const
Returns true iff the stream at index i is a video stream.
Definition: mpegtables.cpp:514
bool IsStreamEncrypted(uint pid) const
Returns true iff PMT contains CA descriptor.
Definition: mpegtables.cpp:594
const unsigned char * ProgramInfo(void) const
Definition: mpegtables.h:699
QString toStringXML(uint indent_level) const override
ISO 11172-2 (aka MPEG-1)
Definition: mpegtables.h:112
ISO 13818-6 type B Std DSMCC Data.
Definition: mpegtables.h:132
QString xml_indent(uint level)
virtual QString toStringXML(uint indent_level, int64_t first, int64_t last) const
bool IsProgramEncrypted(void) const
Returns true iff PMT's ProgramInfo contains CA descriptor.
Definition: mpegtables.cpp:568
ITU H.222.1.
Definition: mpegtables.h:147
SpliceTimeView TimeSignal(void) const
Definition: mpegtables.h:1115
uint ProgramPID(uint i) const
Definition: mpegtables.h:610
Always MPEG-2??
Definition: mpegtables.h:117