49 PictureStartCode = 0x00,
50 SliceStartCodeBegin = 0x01,
51 SliceStartCodeEnd = 0xaf,
56 SequenceStartCode = 0xb3,
59 MPEG2ExtensionStartCode = 0xb5,
60 MPEGReservedB6 = 0xb6,
66 ProgramEndCode = 0xb9,
69 ProgramStreamMap = 0xbc,
71 NonMPEGAudioVideo = 0xbd,
76 MPEGAudioStreamBegin = 0xc0,
78 MPEGAudioStreamEnd = 0xdf,
80 MPEGVideoStreamBegin = 0xe0,
82 MPEGVideoStreamEnd = 0xef,
89 DataH2221Begin = 0xf4,
93 MPEGReservedFA = 0xfa,
95 MPEGReservedFC = 0xfc,
96 MPEGReservedFD = 0xfd,
97 MPEGReservedFE = 0xfe,
98 ProgramStreamDirectory = 0xff,
120 OpenCableVideo = 0x80,
126 MPEG2AACAudio = 0x0f,
127 MPEG2AudioAmd1 = 0x11,
163 AnyMask = 0xFFFF0000,
164 AnyVideo = 0xFFFF0001,
165 AnyAudio = 0xFFFF0002,
198 const QString &sistandard);
200 static QString GetDescription(
uint stream_id);
398 OTV_EIT_TITbeg = 0xA0,
399 OTV_EIT_TITend = 0xA3,
400 OTV_EIT_SUMbeg = 0xA8,
401 OTV_EIT_SUMend = 0xAB,
412 void InitPESPacket(
TSPacket& tspacket);
419 m_fullBuffer =
nullptr;
422 InitPESPacket(
const_cast<TSPacket&
>(tspacket));
423 m_fullBuffer =
const_cast<unsigned char*
>(tspacket.
data());
430 const unsigned char *pesdata,
uint pes_size)
433 m_pesDataSize = pes_size;
434 InitPESPacket(
const_cast<TSPacket&
>(tspacket));
435 int len = pes_size+4;
437 m_allocSize = ((len+m_psiOffset+187)/188)*188;
439 m_pesData = m_fullBuffer + m_psiOffset + 1;
440 memcpy(m_fullBuffer, tspacket.
data(), 188);
441 memcpy(m_pesData, pesdata, pes_size-1);
450 m_pesDataSize = SectionLength();
456 m_pesDataSize = SectionLength();
477 InitPESPacket(
const_cast<TSPacket&
>(table));
479 int len = (4*1024) - 256;
480 m_allocSize = len + m_psiOffset;
482 m_pesData = m_fullBuffer + m_psiOffset + 1;
488 {
return {tspacket,
false}; }
509 {
return ((pesdata()[1]<<8) | pesdata()[2]) & 0x0fff; }
516 {
return (pesdata()[3]<<8) | pesdata()[4]; }
542 {
return pesdata() + kPsipOffset; }
544 {
return pesdata() + kPsipOffset; }
553 pesdata()[3] = (len>>8) & 0xff;
554 pesdata()[4] = len & 0xff;
557 { pesdata()[5] = (pesdata()[5] & 0xc1) | ((ver & 0x1f)<<1); }
559 { pesdata()[5] = (pesdata()[5] & 0xfe) | (cur ? 1 : 0); }
566 bool HasCRC(
void)
const override;
567 bool HasSectionNumber(
void)
const;
569 bool VerifyPSIP(
bool verify_crc)
const;
571 virtual QString
toString(
void)
const;
572 virtual QString toStringXML(
uint indent_level)
const;
574 static const uint kPsipOffset = 8;
577 QString XMLValues(
uint indent_level)
const;
614 const std::vector<uint>& pnum,
615 const std::vector<uint>& pid);
621 if (SectionLength() > (kPsipOffset+2))
622 return (SectionLength()-kPsipOffset-2)>>2;
627 {
return (psipdata()[(i<<2)] << 8) | psipdata()[(i<<2) + 1]; }
631 return (((psipdata()[(i<<2) + 2] & 0x1f) << 8) |
632 psipdata()[(i<<2) + 3]);
640 for (
uint i = 0; i < ProgramCount(); i++)
641 if (progNum==ProgramNumber(i))
642 return ProgramPID(i);
647 for (
uint i = 0; i < ProgramCount(); i++)
648 if (0!=ProgramNumber(i))
649 return ProgramPID(i);
654 for (
uint i = 0; i < ProgramCount(); i++)
655 if (pid==ProgramPID(i))
656 return ProgramNumber(i);
660 QString
toString(
void)
const override;
661 QString toStringXML(
uint indent_level)
const override;
667 friend class TestMPEGTables;
699 std::vector<uint> pids, std::vector<uint>
types);
704 const std::vector<uint> &pids,
705 const std::vector<uint> &
types,
706 const std::vector<desc_list_t> &prog_desc);
710 {
return ((psipdata()[0] << 8) | psipdata()[1]) & 0x1fff; }
713 {
return TableIDExtension(); }
716 {
return ((psipdata()[2]<<8) | psipdata()[3]) & 0x0fff; }
719 {
return psipdata() + 4; }
722 {
return m_ptrs[i][0]; }
725 {
return ((m_ptrs[i][1] << 8) | m_ptrs[i][2]) & 0x1fff; }
728 {
return ((m_ptrs[i][3] << 8) | m_ptrs[i][4]) & 0x0fff; }
731 {
return m_ptrs[i] + 5; }
734 {
return (!m_ptrs.empty()) ? m_ptrs.size()-1 : 0; }
739 psipdata()[0] = ((pid >> 8) & 0x1F) | (psipdata()[0] & 0xE0);
740 psipdata()[1] = (pid & 0xFF);
747 m_ptrs[i][1] = ((pid>>8) & 0x1f) | (m_ptrs[i][1] & 0xe0);
748 m_ptrs[i][2] = pid & 0xff;
752 { m_ptrs[i][0] =
type; }
755 bool IsVideo(
uint i,
const QString& sistandard)
const;
756 bool IsAudio(
uint i,
const QString& sistandard)
const;
757 bool IsEncrypted(
const QString& sistandard)
const;
758 bool IsProgramEncrypted(
void)
const;
759 bool IsStreamEncrypted(
uint pid)
const;
761 bool IsStillPicture(
const QString& sistandard)
const;
767 QString StreamDescription(
uint i,
const QString& sistandard)
const;
769 QString GetLanguage(
uint i)
const;
774 const QString &sistandard)
const;
776 const QString &sistandard,
bool normalize)
const;
782 for (
uint i = 0; i < StreamCount(); i++)
783 if (pid == StreamPID(i))
787 uint FindUnusedPID(
uint desired_pid = 0x20)
const;
791 memset(psipdata(), 0xff, kPmtHeaderMinOffset);
792 SetProgramInfoLength(0);
795 void AppendStream(
uint pid,
uint type,
unsigned char* streamInfo =
nullptr,
uint infoLength = 0);
797 void Parse(
void)
const;
798 QString
toString(
void)
const override;
799 QString toStringXML(
uint indent_level)
const override;
804 m_ptrs[i][3] = ((length>>8) & 0x0f) | (m_ptrs[i][3] & 0xf0);
805 m_ptrs[i][4] = length & 0xff;
811 SetStreamInfoLength(i, infoLength);
812 if ((streamInfo !=
nullptr) && (infoLength > 0))
813 memcpy(m_ptrs[i] + 5, streamInfo, infoLength);
818 psipdata()[2] = ((length>>8) & 0x0f) | (psipdata()[2] & 0xf0);
819 psipdata()[3] = length & 0xff;
824 SetProgramInfoLength(infoLength);
825 memcpy(psipdata() + 4, streamInfo, infoLength);
830 static const uint kPmtHeaderMinOffset = 4;
831 mutable std::vector<unsigned char*>
m_ptrs;
862 {
return SectionLength() - kPsipOffset; }
863 const unsigned char *
Descriptors(
void)
const {
return psipdata(); }
865 QString
toString(
void)
const override;
866 QString toStringXML(
uint indent_level)
const override;
882 return ((uint64_t(m_data[0] & 0x1) << 32) |
883 (uint64_t(m_data[1]) << 24) |
884 (uint64_t(m_data[2]) << 16) |
885 (uint64_t(m_data[3]) << 8) |
886 (uint64_t(m_data[4])));
891 virtual QString
toString(int64_t first, int64_t last)
const;
892 virtual QString toStringXML(
893 uint indent_level, int64_t first, int64_t last)
const;
895 uint size(
void)
const {
return IsTimeSpecified() ? 1 : 5; }
904 std::vector<const unsigned char*> ptrs1) :
905 m_ptrs0(
std::move(ptrs0)), m_ptrs1(
std::move(ptrs1))
914 return ((m_ptrs0[i][0] << 24) | (m_ptrs0[i][1] << 16) |
915 (m_ptrs0[i][2] << 8) | (m_ptrs0[i][3]));
952 std::vector<const unsigned char*> ptrs1) :
953 m_ptrs0(
std::move(ptrs0)), m_ptrs1(
std::move(ptrs1))
960 return ((m_ptrs1[0][0] << 24) | (m_ptrs1[0][1] << 16) |
961 (m_ptrs1[0][2] << 8) | (m_ptrs1[0][3]));
972 bool IsDuration(
void)
const {
return ( m_ptrs1[0][5] & 0x20 ) != 0; }
994 {
return (m_ptrs1[2][0]<<8) | m_ptrs1[2][1]; }
1001 virtual QString
toString(int64_t first, int64_t last)
const;
1002 virtual QString toStringXML(
1003 uint indent_level, int64_t first, int64_t last)
const;
1045 pesdata()[4] = (pesdata()[4] & ~0x80) | ((val) ? 0x80 : 0);
1058 QString EncryptionAlgorithmString(
void)
const;
1061 pesdata()[4] &= 0x81;
1062 pesdata()[4] |= ((val&0x3f) << 1);
1067 return ((uint64_t(pesdata()[4] & 0x1) << 32) |
1068 (uint64_t(pesdata()[5]) << 24) |
1069 (uint64_t(pesdata()[6]) << 16) |
1070 (uint64_t(pesdata()[7]) << 8) |
1071 (uint64_t(pesdata()[8])));
1075 pesdata()[4] &= ~0x1;
1076 pesdata()[4] |= (val>>32) & 0x1;
1077 pesdata()[5] = ((val>>24) & 0xff);
1078 pesdata()[6] = ((val>>16) & 0xff);
1079 pesdata()[7] = ((val>>8 ) & 0xff);
1080 pesdata()[8] = ((val ) & 0xff);
1089 return ((pesdata()[11] & 0xf) << 8) | pesdata()[12];
1093 pesdata()[11] &= ~0xf;
1094 pesdata()[11] |= (len >> 8) & 0xf;
1095 pesdata()[12] = len & 0xff;
1098 enum : std::uint8_t {
1100 kSCTReserved0 = 0x01,
1101 kSCTReserved1 = 0x02,
1102 kSCTReserved2 = 0x03,
1103 kSCTSpliceSchedule = 0x04,
1104 kSCTSpliceInsert = 0x05,
1105 kSCTTimeSignal = 0x06,
1106 kSCTBandwidthReservation = 0x07,
1108 kSCTPrivateCommand = 0xff,
1111 QString SpliceCommandTypeString(
void)
const;
1124 {
return {m_ptrs0, m_ptrs1}; }
1130 {
return {m_ptrs0, m_ptrs1}; }
1157 return (m_epilog[0] << 8) | m_epilog[1];
1164 return (m_epilog) ? m_epilog + 2 :
nullptr;
1178 {
return toStringXML(indent_level, -1LL, -1LL); }
1180 QString
toString(int64_t first, int64_t last)
const;
1181 QString toStringXML(
uint indent_level, int64_t first, int64_t last)
const;
1186 const unsigned char *m_epilog {
nullptr};
1216 bool Priority(
void)
const {
return ( m_data[1] & 0x20 ) != 0; }
1223 bool PCR(
void)
const {
return ( m_data[1] & 0x10 ) != 0; }
1227 bool OPCR(
void)
const {
return ( m_data[1] & 0x08 ) != 0; }
1245 bool LTW(
void)
const {
return ( m_data[3] & 0x80 ) != 0; }
AdaptationFieldControl is used to transmit various important stream attributes.
bool PCR(void) const
PCR flag (we have PCR data) 1 1.3 (adds 6 bytes after adaptation header)
bool Priority(void) const
bool RandomAccess(void) const
bool PiecewiseRate(void) const
bool PrivateTransportData(void) const
uint ExtensionLength(void) const
bool FieldExtension(void) const
uint Length(void) const
adaptation header length (after which is payload data) 8 0.0
bool OPCR(void) const
OPCR flag (we have OPCR data) 1 1.4 (adds 6 bytes) ((Original) Program Clock Reference; used to time ...
bool Discontinuity(void) const
discontinuity_indicator (time base may change) 1 1.0
AdaptationFieldControl(const unsigned char *packet)
const unsigned char * m_data
bool SeamlessSplice(void) const
bool SplicingPoint(void) const
splicing_point_flag 1 1.5 (adds 1 byte) (we have splice point data) Splice data is packets until a go...
The CAT is used to transmit additional ConditionalAccessDescriptor instances, in addition to the ones...
uint DescriptorsLength(void) const
const unsigned char * Descriptors(void) const
ConditionalAccessTable(const PSIPTable &table)
Allows us to transform TS packets to PES packets, which are used to hold multimedia streams and very ...
Contains a listing of PES Stream ID's for various PES Packet types.
Contains Packet Identifier numeric values.
@ PREMIERE_EIT_DIREKT_PID
@ MPEG_NULL_PID
The all-ones PID value 0x1FFF indicates a Null TS Packet introduced to maintain a constant bit rate o...
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
uint LastSection(void) const
void SetATSCProtocolVersion(int ver)
static PSIPTable View(const TSPacket &tspacket)
uint ATSCProtocolVersion(void) const
void SetTableIDExtension(uint len)
void SetSectionLength(uint length)
void SetCurrent(bool cur)
bool SectionSyntaxIndicator(void) const
void SetSection(uint num)
void SetLastSection(uint num)
const unsigned char * psipdata(void) const
unsigned char * psipdata(void)
bool IsCurrent(void) const
PSIPTable(const std::vector< uint8_t > &pesdata)
static PSIPTable ViewData(const unsigned char *pesdata)
PSIPTable(const unsigned char *pesdata)
Constructor for viewing a section, does not create it's own data.
PSIPTable(const TSPacket &tspacket, bool)
bool PrivateIndicator(void) const
PSIPTable(const PSIPTable &)=default
uint TableIDExtension(void) const
uint SectionLengthRaw(void) const
uint SectionLength(void) const
PSIPTable(const TSPacket &tspacket, const unsigned char *pesdata, uint pes_size)
PSIPTable(const TSPacket &table)
void SetVersionNumber(uint ver)
PSIPTable(const PESPacket &table)
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
void SetTranportStreamID(uint gtsid)
uint FindAnyPID(void) const
uint FindProgram(uint pid) const
ProgramAssociationTable(const PSIPTable &table)
uint ProgramCount(void) const
uint TransportStreamID(void) const
uint FindPID(uint progNum) const
ProgramAssociationTable(const ProgramAssociationTable &table)
uint ProgramNumber(uint i) const
uint ProgramPID(uint i) const
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
void RemoveAllStreams(void)
void SetStreamPID(uint i, uint pid)
uint StreamCount(void) const
void SetStreamType(uint i, uint type)
uint PCRPID(void) const
stream that contains program clock reference.
uint StreamPID(uint i) const
void SetStreamProgramInfo(uint i, unsigned char *streamInfo, uint infoLength)
std::vector< unsigned char * > m_ptrs
void SetProgramNumber(uint num)
uint StreamType(uint i) const
int FindPID(uint pid) const
Locates stream index of pid.
void SetProgramInfoLength(uint length)
const unsigned char * ProgramInfo(void) const
const unsigned char * StreamInfo(uint i) const
ProgramMapTable(const PSIPTable &table)
uint ProgramNumber(void) const
QString StreamTypeString(uint i) const
Returns a string representation of type at stream index i.
uint ProgramInfoLength(void) const
uint StreamInfoLength(uint i) const
void SetStreamInfoLength(uint i, uint length)
static ProgramMapTable ViewData(const unsigned char *pesdata)
ProgramMapTable(const ProgramMapTable &table)
void SetProgramInfo(unsigned char *streamInfo, uint infoLength)
SpliceTimeView SpliceTime(void) const
bool IsSpliceImmediate(void) const
bool IsSpliceEventCancel(void) const
std::vector< const unsigned char * > m_ptrs1
SpliceInsertView(std::vector< const unsigned char * > ptrs0, std::vector< const unsigned char * > ptrs1)
bool IsProgramSplice(void) const
uint AvailsExpected(void) const
std::vector< const unsigned char * > m_ptrs0
uint SpliceEventID(void) const
bool IsOutOfNetwork(void) const
bool IsDuration(void) const
uint UniqueProgramID(void) const
uint AvailNum(void) const
SpliceScheduleView(std::vector< const unsigned char * > ptrs0, std::vector< const unsigned char * > ptrs1)
std::vector< const unsigned char * > m_ptrs1
std::vector< const unsigned char * > m_ptrs0
uint SpliceCount(void) const
uint SpliceEventID(uint i) const
const unsigned char * m_data
bool IsTimeSpecified(void) const
uint64_t PTSTime(void) const
SpliceTimeView(const unsigned char *data)
Contains listing of PMT Stream ID's for various A/V Stream types.
@ MPEG2Video
ISO 13818-2 & ITU H.262 (aka MPEG-2)
@ EAC3Audio
A/53 Part 3:2009 6.7.3.
@ DSMCC_D
ISO 13818-6 type D Any DSMCC Data.
@ DSMCC_A
ISO 13818-6 type A Multi-protocol Encap.
@ DSMCC_B
ISO 13818-6 type B Std DSMCC Data.
@ MPEG2AACAudio
ISO 13818-7 Audio w/ADTS syntax.
@ AC3Audio
A/53 Part 3:2009 6.7.1.
@ DSMCC_C
ISO 13818-6 type C NPT DSMCC Data.
@ H265Video
ISO 23008-2 & ITU H.265 (aka HEVC, Ultra HD)
@ VC1Video
SMPTE 421M video codec (aka VC1) in Blu-Ray.
@ MPEG4Video
ISO 14492-2 (aka MPEG-4)
@ MPEG2AudioAmd1
ISO 13818-3/AMD-1 Audio using LATM syntax.
@ MPEG1Video
ISO 11172-2 (aka MPEG-1)
@ OpenCableVideo
Always MPEG-2??
@ H264Video
ISO 14492-10 & ITU H.264 (aka MPEG-4-AVC)
static const char * toString(uint streamID)
static bool IsObjectCarousel(uint type)
Returns true iff stream contains DSMCC Object Carousel.
static bool IsAudio(uint type)
Returns true iff audio is MPEG1/2, AAC, AC3 or DTS audio stream.
static bool IsVideo(uint type)
Returns true iff video is an MPEG1/2/3, H264 or open cable video stream.
Used to access the data of a Transport Stream packet.
static constexpr unsigned int kSize
Contains listing of Table ID's for various tables (PAT=0,PMT=2,etc).
static uint8_t * SetLength(uint8_t *Data, int Length)
static const struct wl_interface * types[]
std::vector< const unsigned char * > desc_list_t
static constexpr uint8_t GPS_LEAP_SECONDS
Leap seconds as of June 30th, 2022.
static constexpr qint64 GPS_EPOCH
Seconds between start of GPS time and the start of UNIX time.
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
unsigned char * pes_alloc(uint size)