Go to the documentation of this file.
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,
418 LOG(VB_GENERAL, LOG_ERR,
"Started PESPacket, but !payloadStart()");
421 m_pesData = tspacket.
data() + m_psiOffset + 1;
426 if ((m_pesData - tspacket.
data()) <= (188-3) &&
427 (m_pesData + Length() - tspacket.
data()) <= (188-3))
438 m_fullBuffer =
nullptr;
441 InitPESPacket(
const_cast<TSPacket&
>(tspacket));
442 m_fullBuffer =
const_cast<unsigned char*
>(tspacket.
data());
449 const unsigned char *pesdata,
uint pes_size)
452 m_pesDataSize = pes_size;
453 InitPESPacket(
const_cast<TSPacket&
>(tspacket));
454 int len = pes_size+4;
456 m_allocSize = ((len+m_psiOffset+187)/188)*188;
458 m_pesData = m_fullBuffer + m_psiOffset + 1;
459 memcpy(m_fullBuffer, tspacket.
data(), 188);
460 memcpy(m_pesData, pesdata, pes_size-1);
469 m_pesDataSize = SectionLength();
475 m_pesDataSize = SectionLength();
496 InitPESPacket(
const_cast<TSPacket&
>(table));
498 int len = (4*1024) - 256;
501 m_pesData = m_fullBuffer + m_psiOffset + 1;
507 {
return {tspacket,
false}; }
561 {
return pesdata() + kPsipOffset; }
563 {
return pesdata() + kPsipOffset; }
572 pesdata()[3] = (len>>8) & 0xff;
585 bool HasCRC(
void)
const override;
586 bool HasSectionNumber(
void)
const;
588 bool VerifyPSIP(
bool verify_crc)
const;
590 virtual QString
toString(
void)
const;
591 virtual QString toStringXML(
uint indent_level)
const;
593 static const uint kPsipOffset = 8;
596 QString XMLValues(
uint indent_level)
const;
633 const std::vector<uint>& pnum,
634 const std::vector<uint>& pid);
650 return (((
psipdata()[(i<<2) + 2] & 0x1f) << 8) |
659 for (
uint i = 0; i < ProgramCount(); i++)
660 if (progNum==ProgramNumber(i))
661 return ProgramPID(i);
666 for (
uint i = 0; i < ProgramCount(); i++)
667 if (0!=ProgramNumber(i))
668 return ProgramPID(i);
673 for (
uint i = 0; i < ProgramCount(); i++)
674 if (pid==ProgramPID(i))
675 return ProgramNumber(i);
679 QString
toString(
void)
const override;
686 friend class TestMPEGTables;
718 std::vector<uint> pids, std::vector<uint>
types);
723 const std::vector<uint> &pids,
724 const std::vector<uint> &
types,
725 const std::vector<desc_list_t> &prog_desc);
741 {
return m_ptrs[i][0]; }
744 {
return ((m_ptrs[i][1] << 8) | m_ptrs[i][2]) & 0x1fff; }
747 {
return ((m_ptrs[i][3] << 8) | m_ptrs[i][4]) & 0x0fff; }
750 {
return m_ptrs[i] + 5; }
753 {
return (!m_ptrs.empty()) ? m_ptrs.size()-1 : 0; }
766 m_ptrs[i][1] = ((pid>>8) & 0x1f) | (m_ptrs[i][1] & 0xe0);
767 m_ptrs[i][2] = pid & 0xff;
771 { m_ptrs[i][0] =
type; }
774 bool IsVideo(
uint i,
const QString& sistandard)
const;
775 bool IsAudio(
uint i,
const QString& sistandard)
const;
776 bool IsEncrypted(
const QString& sistandard)
const;
777 bool IsProgramEncrypted(
void)
const;
778 bool IsStreamEncrypted(
uint pid)
const;
780 bool IsStillPicture(
const QString& sistandard)
const;
786 QString StreamDescription(
uint i,
const QString& sistandard)
const;
788 QString GetLanguage(
uint i)
const;
793 const QString &sistandard)
const;
795 const QString &sistandard,
bool normalize)
const;
801 for (
uint i = 0; i < StreamCount(); i++)
802 if (pid == StreamPID(i))
806 uint FindUnusedPID(
uint desired_pid = 0x20)
const;
810 memset(
psipdata(), 0xff, kPmtHeaderMinOffset);
811 SetProgramInfoLength(0);
814 void AppendStream(
uint pid,
uint type,
unsigned char* streamInfo =
nullptr,
uint infoLength = 0);
816 void Parse(
void)
const;
817 QString
toString(
void)
const override;
823 m_ptrs[i][3] = ((length>>8) & 0x0f) | (m_ptrs[i][3] & 0xf0);
824 m_ptrs[i][4] = length & 0xff;
830 SetStreamInfoLength(i, infoLength);
831 if ((streamInfo !=
nullptr) && (infoLength > 0))
832 memcpy(m_ptrs[i] + 5, streamInfo, infoLength);
843 SetProgramInfoLength(infoLength);
844 memcpy(
psipdata() + 4, streamInfo, infoLength);
849 static const uint kPmtHeaderMinOffset = 4;
850 mutable std::vector<unsigned char*>
m_ptrs;
884 QString
toString(
void)
const override;
901 return ((uint64_t(m_data[0] & 0
x1) << 32) |
902 (uint64_t(m_data[1]) << 24) |
903 (uint64_t(m_data[2]) << 16) |
904 (uint64_t(m_data[3]) << 8) |
905 (uint64_t(m_data[4])));
910 virtual QString
toString(int64_t first, int64_t last)
const;
911 virtual QString toStringXML(
912 uint indent_level, int64_t first, int64_t last)
const;
914 uint size(
void)
const {
return IsTimeSpecified() ? 1 : 5; }
923 std::vector<const unsigned char*> ptrs1) :
924 m_ptrs0(std::move(ptrs0)), m_ptrs1(std::move(ptrs1))
933 return ((m_ptrs0[i][0] << 24) | (m_ptrs0[i][1] << 16) |
934 (m_ptrs0[i][2] << 8) | (m_ptrs0[i][3]));
971 std::vector<const unsigned char*> ptrs1) :
972 m_ptrs0(std::move(ptrs0)), m_ptrs1(std::move(ptrs1))
979 return ((m_ptrs1[0][0] << 24) | (m_ptrs1[0][1] << 16) |
980 (m_ptrs1[0][2] << 8) | (m_ptrs1[0][3]));
991 bool IsDuration(
void)
const {
return ( m_ptrs1[0][5] & 0x20 ) != 0; }
1013 {
return (m_ptrs1[2][0]<<8) | m_ptrs1[2][1]; }
1020 virtual QString
toString(int64_t first, int64_t last)
const;
1021 virtual QString toStringXML(
1022 uint indent_level, int64_t first, int64_t last)
const;
1077 QString EncryptionAlgorithmString(
void)
const;
1081 pesdata()[4] |= ((val&0x3f) << 1);
1086 return ((uint64_t(
pesdata()[4] & 0
x1) << 32) |
1087 (uint64_t(
pesdata()[5]) << 24) |
1088 (uint64_t(
pesdata()[6]) << 16) |
1089 (uint64_t(
pesdata()[7]) << 8) |
1096 pesdata()[5] = ((val>>24) & 0xff);
1097 pesdata()[6] = ((val>>16) & 0xff);
1098 pesdata()[7] = ((val>>8 ) & 0xff);
1099 pesdata()[8] = ((val ) & 0xff);
1113 pesdata()[11] |= (len >> 8) & 0xf;
1117 enum : std::uint8_t {
1119 kSCTReserved0 = 0x01,
1120 kSCTReserved1 = 0x02,
1121 kSCTReserved2 = 0x03,
1122 kSCTSpliceSchedule = 0x04,
1123 kSCTSpliceInsert = 0x05,
1124 kSCTTimeSignal = 0x06,
1125 kSCTBandwidthReservation = 0x07,
1127 kSCTPrivateCommand = 0xff,
1130 QString SpliceCommandTypeString(
void)
const;
1143 {
return {m_ptrs0, m_ptrs1}; }
1149 {
return {m_ptrs0, m_ptrs1}; }
1176 return (m_epilog[0] << 8) | m_epilog[1];
1183 return (m_epilog) ? m_epilog + 2 :
nullptr;
1199 QString
toString(int64_t first, int64_t last)
const;
1200 QString
toStringXML(
uint indent_level, int64_t first, int64_t last)
const;
1205 const unsigned char *m_epilog {
nullptr};
1235 bool Priority(
void)
const {
return ( m_data[1] & 0x20 ) != 0; }
1242 bool PCR(
void)
const {
return ( m_data[1] & 0x10 ) != 0; }
1246 bool OPCR(
void)
const {
return ( m_data[1] & 0x08 ) != 0; }
1264 bool LTW(
void)
const {
return ( m_data[3] & 0x80 ) != 0; }
1275 #endif // MPEG_TABLES_H
const unsigned char * ProgramInfo(void) const
uint FindAnyPID(void) const
@ DSMCC_B
ISO 13818-6 type B Std DSMCC Data.
uint ProgramPID(uint i) const
uint UniqueProgramID(void) const
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
@ DSMCC_A
ISO 13818-6 type A Multi-protocol Encap.
@ OpenCableVideo
Always MPEG-2??
void InitPESPacket(TSPacket &tspacket)
Only handles single TS packet PES packets, for PMT/PAT tables basically.
unsigned int StartOfFieldPointer(void) const
ProgramAssociationTable(const PSIPTable &table)
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...
void SetTableIDExtension(uint len)
uint StreamCount(void) const
SpliceTimeView SpliceTime(void) const
SpliceScheduleView(std::vector< const unsigned char * > ptrs0, std::vector< const unsigned char * > ptrs1)
@ DSMCC_C
ISO 13818-6 type C NPT DSMCC Data.
const unsigned char * Descriptors(void) const
uint Length(void) const
adaptation header length (after which is payload data) 8 0.0
bool IsCurrent(void) const
void SetStreamInfoLength(uint i, uint length)
void SetProgramInfo(unsigned char *streamInfo, uint infoLength)
const unsigned char * StreamInfo(uint i) const
SpliceTimeView(const unsigned char *data)
void SetTranportStreamID(uint gtsid)
ConditionalAccessTable(const PSIPTable &table)
const unsigned char * pesdata() const
uint FindProgram(uint pid) const
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
@ MPEG2AudioAmd1
ISO 13818-3/AMD-1 Audio using LATM syntax.
int FindPID(uint pid) const
Locates stream index of pid.
uint PCRPID(void) const
stream that contains program clock reference.
unsigned int AFCOffset(void) const
uint ExtensionLength(void) const
static const struct wl_interface * types[]
PSIPTable(const TSPacket &tspacket, const unsigned char *pesdata, uint pes_size)
uint ProgramNumber(void) const
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
std::vector< const unsigned char * > m_ptrs0
uint ProgramCount(void) const
uint ATSCProtocolVersion(void) const
void SetVersionNumber(uint ver)
bool OPCR(void) const
OPCR flag (we have OPCR data) 1 1.4 (adds 6 bytes) ((Original) Program Clock Reference; used to time ...
static constexpr uint8_t GPS_LEAP_SECONDS
Leap seconds as of June 30th, 2022.
uint SectionLengthRaw(void) const
void SetATSCProtocolVersion(int ver)
static const uint kPsipOffset
QString StreamTypeString(uint i) const
Returns a string representation of type at stream index i.
void SetCurrent(bool cur)
static bool IsVideo(uint type)
Returns true iff video is an MPEG1/2/3, H264 or open cable video stream.
bool PrivateIndicator(void) const
uint DescriptorsLength(void) const
bool Discontinuity(void) const
discontinuity_indicator (time base may change) 1 1.0
AdaptationFieldControl(const unsigned char *packet)
@ MPEG_NULL_PID
The all-ones PID value 0x1FFF indicates a Null TS Packet introduced to maintain a constant bit rate o...
Contains listing of PMT Stream ID's for various A/V Stream types.
uint SpliceEventID(void) const
PSIPTable(const TSPacket &table)
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
SpliceInsertView(std::vector< const unsigned char * > ptrs0, std::vector< const unsigned char * > ptrs1)
@ MPEG2AACAudio
ISO 13818-7 Audio w/ADTS syntax.
virtual QString toString(void) const
void RemoveAllStreams(void)
bool SeamlessSplice(void) const
bool PrivateTransportData(void) const
bool IsSpliceImmediate(void) const
uint SpliceCount(void) const
uint TransportStreamID(void) const
uint ProgramNumber(uint i) const
void SetLastSection(uint num)
@ VC1Video
SMPTE 421M video codec (aka VC1) in Blu-Ray.
static bool IsAudio(uint type)
Returns true iff audio is MPEG1/2, AAC, AC3 or DTS audio stream.
@ DSMCC_D
ISO 13818-6 type D Any DSMCC Data.
Used to access the data of a Transport Stream packet.
uint StreamType(uint i) const
PSIPTable(const unsigned char *pesdata)
Constructor for viewing a section, does not create it's own data.
PSIPTable(const TSPacket &tspacket, bool)
@ PREMIERE_EIT_DIREKT_PID
std::vector< const unsigned char * > desc_list_t
ProgramMapTable(const PSIPTable &table)
uint AvailsExpected(void) const
virtual QString toStringXML(uint indent_level) const
bool IsOutOfNetwork(void) const
@ H264Video
ISO 14492-10 & ITU H.264 (aka MPEG-4-AVC)
@ H265Video
ISO 23008-2 & ITU H.265 (aka HEVC, Ultra HD)
void SetStreamPID(uint i, uint pid)
void SetSectionLength(uint length)
bool VerifyCRC(void) const
Contains Packet Identifier numeric values.
const unsigned char * m_data
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
@ MPEG4Video
ISO 14492-2 (aka MPEG-4)
uint LastSection(void) const
std::vector< const unsigned char * > m_ptrs1
bool IsSpliceEventCancel(void) const
Contains listing of Table ID's for various tables (PAT=0,PMT=2,etc).
void SetStreamProgramInfo(uint i, unsigned char *streamInfo, uint infoLength)
Allows us to transform TS packets to PES packets, which are used to hold multimedia streams and very ...
uint SectionLength(void) const
uint ProgramInfoLength(void) const
bool RandomAccess(void) const
unsigned char * pes_alloc(uint size)
static PSIPTable View(const TSPacket &tspacket)
static constexpr qint64 GPS_EPOCH
Seconds between start of GPS time and the start of UNIX time.
bool IsProgramSplice(void) const
void SetProgramNumber(uint num)
static const char * toString(uint streamID)
void SetStreamID(uint id)
ProgramAssociationTable(const ProgramAssociationTable &table)
@ AC3Audio
A/53 Part 3:2009 6.7.1.
uint AvailNum(void) const
uint TableIDExtension(void) const
void SetSection(uint num)
uint64_t PTSTime(void) const
The CAT is used to transmit additional ConditionalAccessDescriptor instances, in addition to the ones...
PSIPTable(const std::vector< uint8_t > &pesdata)
AdaptationFieldControl is used to transmit various important stream attributes.
static ProgramMapTable ViewData(const unsigned char *pesdata)
@ MPEG2Video
ISO 13818-2 & ITU H.262 (aka MPEG-2)
void SetStreamType(uint i, uint type)
uint FindPID(uint progNum) const
uint SpliceEventID(uint i) const
virtual bool HasCRC() const
1 bit Cyclic Redundancy Check present
static bool IsObjectCarousel(uint type)
Returns true iff stream contains DSMCC Object Carousel.
unsigned char * m_fullBuffer
Pointer to allocated data.
std::vector< const unsigned char * > m_ptrs1
unsigned char * psipdata(void)
static PSIPTable ViewData(const unsigned char *pesdata)
Contains a listing of PES Stream ID's for various PES Packet types.
std::vector< const unsigned char * > m_ptrs0
std::vector< unsigned char * > m_ptrs
uint StreamInfoLength(uint i) const
bool IsTimeSpecified(void) const
@ MPEG1Video
ISO 11172-2 (aka MPEG-1)
bool IsDuration(void) const
uint StreamPID(uint i) const
bool PCR(void) const
PCR flag (we have PCR data) 1 1.3 (adds 6 bytes after adaptation header)
bool Priority(void) const
void SetProgramInfoLength(uint length)
const unsigned char * m_data
ProgramMapTable(const ProgramMapTable &table)
@ EAC3Audio
A/53 Part 3:2009 6.7.3.
bool SectionSyntaxIndicator(void) const
const unsigned char * psipdata(void) const
PSIPTable(const PESPacket &table)
static constexpr unsigned int kSize
uint m_psiOffset
AFCOffset + StartOfFieldPointer.
bool PiecewiseRate(void) const
bool FieldExtension(void) const