3 #ifndef _MPEG_TABLES_H_ 4 #define _MPEG_TABLES_H_ 28 #define GPS_EPOCH 315964800 31 #define GPS_LEAP_SECONDS 16 46 PictureStartCode = 0x00,
47 SliceStartCodeBegin = 0x01,
48 SliceStartCodeEnd = 0xaf,
53 SequenceStartCode = 0xb3,
56 MPEG2ExtensionStartCode = 0xb5,
57 MPEGReservedB6 = 0xb6,
63 ProgramEndCode = 0xb9,
66 ProgramStreamMap = 0xbc,
68 NonMPEGAudioVideo = 0xbd,
73 MPEGAudioStreamBegin = 0xc0,
75 MPEGAudioStreamEnd = 0xdf,
77 MPEGVideoStreamBegin = 0xe0,
79 MPEGVideoStreamEnd = 0xef,
86 DataH2221Begin = 0xf4,
90 MPEGReservedFA = 0xfa,
92 MPEGReservedFC = 0xfc,
93 MPEGReservedFD = 0xfd,
94 MPEGReservedFE = 0xfe,
95 ProgramStreamDirectory = 0xff,
117 OpenCableVideo = 0x80,
123 MPEG2AACAudio = 0x0f,
124 MPEG2AudioAmd1 = 0x11,
160 AnyMask = 0xFFFF0000,
161 AnyVideo = 0xFFFF0001,
162 AnyAudio = 0xFFFF0002,
195 const QString &sistandard);
197 static QString GetDescription(
uint streamID);
380 LOG(VB_GENERAL, LOG_ERR,
"Started PESPacket, but !payloadStart()");
383 _pesdata = tspacket.
data() + _psiOffset + 1;
388 if ((_pesdata - tspacket.
data()) <= (188-3) &&
389 (_pesdata +
Length() - tspacket.
data()) <= (188-3))
401 _fullbuffer =
nullptr;
404 InitPESPacket(const_cast<TSPacket&>(tspacket));
405 _fullbuffer = const_cast<unsigned char*>(tspacket.
data());
412 const unsigned char *pesdata,
uint pes_size)
416 _pesdataSize = pes_size;
417 InitPESPacket(const_cast<TSPacket&>(tspacket));
418 int len = pes_size+4;
420 _allocSize = ((len+_psiOffset+187)/188)*188;
422 _pesdata = _fullbuffer + _psiOffset + 1;
423 memcpy(_fullbuffer, tspacket.
data(), 188);
424 memcpy(_pesdata, pesdata, pes_size-1);
433 _pesdataSize = SectionLength();
457 InitPESPacket(const_cast<TSPacket&>(table));
459 int len = (4*1024) - 256;
462 _pesdata = _fullbuffer + _psiOffset + 1;
523 {
return pesdata() + PSIP_OFFSET; }
525 {
return pesdata() + PSIP_OFFSET; }
534 pesdata()[3] = (len>>8) & 0xff;
547 bool HasCRC(
void)
const override;
548 bool HasSectionNumber(
void)
const;
550 bool VerifyPSIP(
bool verify_crc)
const;
552 virtual QString
toString(
void)
const;
553 virtual QString toStringXML(
uint indent_level)
const;
555 static const uint PSIP_OFFSET = 8;
558 QString XMLValues(
uint indent_level)
const;
595 const vector<uint>& pnum,
596 const vector<uint>& pid);
612 return (((
psipdata()[(i<<2) + 2] & 0x1f) << 8) |
621 for (
uint i = 0; i < ProgramCount(); i++)
622 if (progNum==ProgramNumber(i))
623 return ProgramPID(i);
628 for (
uint i = 0; i < ProgramCount(); i++)
629 if (0!=ProgramNumber(i))
630 return ProgramPID(i);
635 for (
uint i = 0; i < ProgramCount(); i++)
636 if (pid==ProgramPID(i))
637 return ProgramNumber(i);
641 QString
toString(
void)
const override;
648 friend class TestMPEGTables;
680 vector<uint> pids, vector<uint> types);
685 const vector<uint> &pids,
686 const vector<uint> &types,
687 const vector<desc_list_t> &prog_desc);
703 {
return _ptrs[i][0]; }
706 {
return ((_ptrs[i][1] << 8) | _ptrs[i][2]) & 0x1fff; }
709 {
return ((_ptrs[i][3] << 8) | _ptrs[i][4]) & 0x0fff; }
712 {
return _ptrs[i] + 5; }
715 {
return (_ptrs.size()) ? _ptrs.size()-1 : 0; }
728 _ptrs[i][1] = ((pid>>8) & 0x1f) | (_ptrs[i][1] & 0xe0);
729 _ptrs[i][2] = pid & 0xff;
733 { _ptrs[i][0] =
type; }
736 bool IsVideo(
uint i, QString sistandard)
const;
737 bool IsAudio(
uint i, QString sistandard)
const;
738 bool IsEncrypted(QString sistandard)
const;
739 bool IsProgramEncrypted(
void)
const;
740 bool IsStreamEncrypted(
uint pid)
const;
742 bool IsStillPicture(QString sistandard)
const;
748 QString StreamDescription(
uint i, QString sistandard)
const;
750 QString GetLanguage(
uint i)
const;
755 const QString &sistandard)
const;
756 uint FindPIDs(
uint type, vector<uint> &pids, vector<uint> &types,
757 const QString &sistandard,
bool normalize)
const;
763 for (
uint i = 0; i < StreamCount(); i++)
764 if (pid == StreamPID(i))
768 uint FindUnusedPID(
uint desired_pid = 0x20);
772 memset(
psipdata(), 0xff, pmt_header);
773 SetProgramInfoLength(0);
776 void AppendStream(
uint pid,
uint type,
unsigned char* si =
nullptr,
uint il = 0);
778 void Parse(
void)
const;
779 QString
toString(
void)
const override;
785 _ptrs[i][3] = ((length>>8) & 0x0f) | (_ptrs[i][3] & 0xf0);
786 _ptrs[i][4] = length & 0xff;
792 SetStreamInfoLength(i, infoLength);
793 memcpy(_ptrs[i] + 5, streamInfo, infoLength);
804 SetProgramInfoLength(infoLength);
805 memcpy(
psipdata() + 4, streamInfo, infoLength);
810 static const uint pmt_header = 4;
811 mutable vector<unsigned char*>
_ptrs;
845 QString
toString(
void)
const override;
862 return ((uint64_t(_data[0] & 0
x1) << 32) |
863 (uint64_t(_data[1]) << 24) |
864 (uint64_t(_data[2]) << 16) |
865 (uint64_t(_data[3]) << 8) |
866 (uint64_t(_data[4])));
871 virtual QString
toString(int64_t first, int64_t
last)
const;
872 virtual QString toStringXML(
873 uint indent_level, int64_t first, int64_t
last)
const;
875 uint size(
void)
const {
return IsTimeSpecified() ? 1 : 5; }
884 const vector<const unsigned char*> &ptrs1) :
885 _ptrs0(ptrs0), _ptrs1(ptrs1)
894 return ((_ptrs0[i][0] << 24) | (_ptrs0[i][1] << 16) |
895 (_ptrs0[i][2] << 8) | (_ptrs0[i][3]));
932 const vector<const unsigned char*> &ptrs1) :
933 _ptrs0(ptrs0), _ptrs1(ptrs1)
940 return ((_ptrs1[0][0] << 24) | (_ptrs1[0][1] << 16) |
941 (_ptrs1[0][2] << 8) | (_ptrs1[0][3]));
974 {
return (_ptrs1[2][0]<<8) | _ptrs1[2][1]; }
981 virtual QString
toString(int64_t first, int64_t
last)
const;
982 virtual QString toStringXML(
983 uint indent_level, int64_t first, int64_t
last)
const;
1038 QString EncryptionAlgorithmString(
void)
const;
1042 pesdata()[4] |= ((val&0x3f) << 1);
1047 return ((uint64_t(
pesdata()[4] & 0
x1) << 32) |
1048 (uint64_t(
pesdata()[5]) << 24) |
1049 (uint64_t(
pesdata()[6]) << 16) |
1050 (uint64_t(
pesdata()[7]) << 8) |
1057 pesdata()[5] = ((val>>24) & 0xff);
1058 pesdata()[6] = ((val>>16) & 0xff);
1059 pesdata()[7] = ((val>>8 ) & 0xff);
1060 pesdata()[8] = ((val ) & 0xff);
1074 pesdata()[11] |= (len >> 8) & 0xf;
1080 kSCTReserved0 = 0x01,
1081 kSCTReserved1 = 0x02,
1082 kSCTReserved2 = 0x03,
1083 kSCTSpliceSchedule = 0x04,
1084 kSCTSpliceInsert = 0x05,
1085 kSCTTimeSignal = 0x06,
1086 kSCTBandwidthReservation = 0x07,
1088 kSCTPrivateCommand = 0xff,
1091 QString SpliceCommandTypeString(
void)
const;
1137 return (_epilog[0] << 8) | _epilog[1];
1144 return (_epilog) ? _epilog + 2 :
nullptr;
1203 bool PCR(
void)
const {
return bool(_data[1] & 0x10); }
1207 bool OPCR(
void)
const {
return bool(_data[1] & 0x08); }
1225 bool LTW(
void)
const {
return bool(_data[3] & 0x80); }
uint SpliceEventID(void) const
Used to access the data of a Transport Stream packet.
uint AvailNum(void) const
const unsigned char * pesdata() 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...
const unsigned char * psipdata(void) const
ISO 13818-3/AMD-1 Audio using LATM syntax.
static const ProgramMapTable ViewData(const unsigned char *pesdata)
ProgramMapTable(const ProgramMapTable &table)
uint ProgramCount(void) const
static const PSIPTable View(const TSPacket &tspacket)
vector< const unsigned char * > _ptrs1
SpliceTimeView(const unsigned char *data)
ConditionalAccessTable(const PSIPTable &table)
PSIPTable(const PESPacket &table)
ProgramAssociationTable(const ProgramAssociationTable &table)
bool OPCR(void) const
OPCR flag (we have OPCR data) 1 1.4 (adds 6 bytes) ((Original) Program Clock Reference; used to time ...
QString toString(MarkTypes type)
void SetLastSection(uint num)
unsigned char * _fullbuffer
Pointer to allocated data.
uint TableIDExtension(void) const
const unsigned char * _data
virtual bool HasCRC() const
1 bit Cyclic Redundancy Check present
bool FieldExtension(void) const
uint SectionLength(void) const
uint AvailsExpected(void) const
bool IsOutOfNetwork(void) const
PSIPTable(const unsigned char *pesdata)
Constructor for viewing a section, does not create it's own data.
void InitPESPacket(TSPacket &tspacket)
Only handles single TS packet PES packets, for PMT/PAT tables basically.
static bool IsAudio(uint type)
Returns true iff audio is MPEG1/2, AAC, AC3 or DTS audio stream.
void SetStreamType(uint i, uint type)
uint ProgramNumber(uint i) const
AdaptationFieldControl is used to transmit various important stream attributes.
uint LastSection(void) const
bool PrivateIndicator(void) const
void SetProgramNumber(uint num)
ISO 13818-7 Audio w/ADTS syntax.
uint FindAnyPID(void) const
PSIPTable(const TSPacket &table)
void SetStreamID(uint id)
static const uint PSIP_OFFSET
void SetStreamInfoLength(uint i, uint length)
void SetATSCProtocolVersion(int ver)
ISO 13818-6 type C NPT DSMCC Data.
const unsigned char * Descriptors(void) const
void RemoveAllStreams(void)
vector< const unsigned char * > desc_list_t
void SetSection(uint num)
uint ExtensionLength(void) const
bool IsCurrent(void) const
unsigned char * pes_alloc(uint size)
ProgramAssociationTable(const PSIPTable &table)
void SetProgramInfoLength(uint length)
uint PCRPID(void) const
stream that contrains program clock reference.
bool SeamlessSplice(void) const
vector< const unsigned char * > _ptrs0
vector< unsigned char * > _ptrs
bool IsSpliceEventCancel(void) const
vector< const unsigned char * > _ptrs0
unsigned char * psipdata(void)
uint UniqueProgramID(void) const
static bool IsVideo(uint type)
Returns true iff video is an MPEG1/2/3, H264 or open cable video stream.
PSIPTable(const PSIPTable &table)
uint StreamInfoLength(uint i) const
uint StreamType(uint i) const
uint _psiOffset
AFCOffset + StartOfFieldPointer.
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
uint StreamPID(uint i) const
bool IsProgramSplice(void) const
static const PSIPTable ViewData(const unsigned char *pesdata)
The CAT is used to transmit additional ConditionalAccessDescriptor instances, in addition to the ones...
uint StreamCount(void) const
bool PrivateTransportData(void) const
const unsigned char * StreamInfo(uint i) const
SpliceTimeView SpliceTime(void) const
SMPTE 421M video codec (aka VC1) in Blu-Ray.
bool SectionSyntaxIndicator(void) const
void SetSectionLength(uint length)
ISO 23008-2 & ITU H.265 (aka HEVC, Ultra HD)
bool Discontinuity(void) const
discontinuity_indicator (time base may change) 1 1.0
Contains listing of Table ID's for various tables (PAT=0,PMT=2,etc).
uint DescriptorsLength(void) const
AdaptationFieldControl(const unsigned char *packet)
void SetStreamProgramInfo(uint i, unsigned char *streamInfo, uint infoLength)
Contains a listing of PES Stream ID's for various PES Packet types.
vector< const unsigned char * > _ptrs1
bool IsTimeSpecified(void) const
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
void SetTableIDExtension(uint len)
void SetCurrent(bool cur)
uint TransportStreamID(void) const
unsigned int AFCOffset() const
ProgramMapTable(const PSIPTable &table)
ISO 13818-6 type D Any DSMCC Data.
void SetStreamPID(uint i, uint pid)
void SetTranportStreamID(uint gtsid)
bool IsDuration(void) const
QString StreamTypeString(uint i) const
Returns a string representation of type at stream index i.
SpliceScheduleView(const vector< const unsigned char * > &ptrs0, const vector< const unsigned char * > &ptrs1)
ISO 14492-10 & ITU H.264 (aka MPEG-4-AVC)
#define LOG(_MASK_, _LEVEL_, _STRING_)
int FindPID(uint pid) const
Locates stream index of pid.
static const unsigned int kSize
uint ProgramNumber(void) const
const unsigned char * _data
static bool IsObjectCarousel(uint type)
Returns true iff stream contains DSMCC Object Carousel.
uint ProgramInfoLength(void) const
static const char * toString(uint streamID)
bool Priority(void) const
SpliceInsertView(const vector< const unsigned char * > &ptrs0, const vector< const unsigned char * > &ptrs1)
bool IsSpliceImmediate(void) const
uint FindPID(uint progNum) const
virtual QString toString(void) const
void SetVersionNumber(uint ver)
void SetProgramInfo(unsigned char *streamInfo, uint infoLength)
unsigned int StartOfFieldPointer() const
Allows us to transform TS packets to PES packets, which are used to hold multimedia streams and very ...
uint64_t PTSTime(void) const
PSIPTable(const TSPacket &tspacket, const unsigned char *pesdata, uint pes_size)
uint SpliceCount(void) const
bool PiecewiseRate(void) const
bool RandomAccess(void) const
bool VerifyCRC(void) const
bool PCR(void) const
PCR flag (we have PCR data) 1 1.3 (adds 6 bytes after adaptation header)
PSIPTable(const TSPacket &tspacket, bool)
The all-ones PID value 0x1FFF indicates a Null TS Packet introduced to maintain a constant bit rate o...
uint FindProgram(uint pid) const
static PSIPTable View(TSPacket &tspacket)
uint ATSCProtocolVersion(void) const
ISO 13818-2 & ITU H.262 (aka MPEG-2)
Contains listing of PMT Stream ID's for various A/V Stream types.
ISO 13818-6 type A Multi-protocol Encap.
virtual QString toStringXML(uint indent_level) const
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
const unsigned char * ProgramInfo(void) const
uint Length(void) const
adaptation header length (after which is payload data) 8 0.0
ISO 13818-6 type B Std DSMCC Data.
uint SpliceEventID(uint i) const
uint ProgramPID(uint i) const