30 : _pesdata(nullptr), _fullbuffer(nullptr), _psiOffset(0),
31 _ccLast(255), _pesdataSize(0), _allocSize(0), _badPacket(
false)
37 : _pesdata(const_cast<unsigned char*>(pesdata)),
38 _fullbuffer(const_cast<unsigned char*>(pesdata)),
39 _psiOffset(0), _ccLast(255), _allocSize(0)
41 _badPacket = !VerifyCRC();
42 _pesdataSize = max(((
int)Length())-1 + (HasCRC() ? 4 : 0), 0);
53 _psiOffset(pkt._psiOffset),
55 _pesdataSize(pkt._pesdataSize),
56 _allocSize(pkt._allocSize),
57 _badPacket(pkt._badPacket)
78 _fullbuffer =
nullptr;
85 bool AddTSPacket(
const TSPacket* tspacket,
bool &broken);
87 bool IsGood()
const {
return !_badPacket; }
90 {
return reinterpret_cast<const TSHeader*>(_fullbuffer); }
92 {
return reinterpret_cast<TSHeader*>(_fullbuffer); }
94 void GetAsTSPackets(vector<TSPacket> &pkts,
uint cc)
const;
99 {
return (_pesdata[1] & 0x0f) << 8 | _pesdata[2]; }
103 {
return (_pesdata[3] & 0x30) >> 4; }
117 bool HasPTS()
const {
return (_pesdata[4] & 0x80) >> 7; }
119 bool HasDTS()
const {
return (_pesdata[4] & 0x40) >> 6; }
121 bool HasESCR()
const {
return (_pesdata[4] & 0x20) >> 5; }
123 bool HasESR()
const {
return (_pesdata[4] & 0x10) >> 4; }
125 bool HasDSM()
const {
return (_pesdata[4] & 0x8) >> 3; }
127 bool HasACI()
const {
return (_pesdata[4] & 0
x4) >> 2; }
129 virtual bool HasCRC()
const {
return (_pesdata[4] & 0
x2) >> 1; }
138 (uint64_t(_pesdata[i+0] & 0x0e) << 29) |
139 (uint64_t(_pesdata[i+1] ) << 22) |
140 (uint64_t(_pesdata[i+2] & 0xfe) << 14) |
141 (uint64_t(_pesdata[i+3] ) << 7) |
142 (uint64_t(_pesdata[i+4] & 0xfe) >> 1);
147 int i = 6+(HasPTS()?5:0);
149 (uint64_t(_pesdata[i+0] & 0x0e) << 29) |
150 (uint64_t(_pesdata[i+1] ) << 22) |
151 (uint64_t(_pesdata[i+2] & 0xfe) << 14) |
152 (uint64_t(_pesdata[i+3] ) << 7) |
153 (uint64_t(_pesdata[i+4] & 0xfe) >> 1);
163 const unsigned char*
pesdata()
const {
return _pesdata; }
166 const unsigned char*
data()
const {
return _fullbuffer; }
167 unsigned char*
data() {
return _fullbuffer; }
172 _pesdata[1] = (_pesdata[1] & 0xf0) | ((len>>8) & 0x0f);
173 _pesdata[2] = len & 0xff;
185 _pesdata = _fullbuffer + _psiOffset + 1;
190 if (!HasCRC() || (Length() < 1))
191 return kTheMagicNoCRCCRC;
192 uint offset = Length() - 1;
193 return ((_pesdata[offset+0]<<24) |
194 (_pesdata[offset+1]<<16) |
195 (_pesdata[offset+2]<<8) |
196 (_pesdata[offset+3]));
204 uint offset = Length() - 1;
205 _pesdata[offset+0] = (crc & 0xff000000) >> 24;
206 _pesdata[offset+1] = (crc & 0x00ff0000) >> 16;
207 _pesdata[offset+2] = (crc & 0x0000ff00) >> 8;
208 _pesdata[offset+3] = (crc & 0x000000ff);
211 uint CalcCRC(
void)
const;
212 bool VerifyCRC(
void)
const;
228 static const uint kTheMagicNoCRCCRC = 0xFFFFFFFF;
234 uint width(
void)
const {
return (data[0] <<4) | (data[1]>>4); }
235 uint height(
void)
const {
return ((data[1] & 0xf)<<8) | data[2]; }
238 float fps(
void)
const {
return mpeg2_fps[fpsNum()]; }
239 float aspect(
bool mpeg1)
const;
245 unsigned char data[11];
246 static const float mpeg1_aspect[16];
247 static const float mpeg2_aspect[16];
248 static const float mpeg2_fps[16];
251 #endif // _PES_PACKET_H_ uint _ccLast
Continuity counter of last inserted TS Packet.
Used to access the data of a Transport Stream packet.
const unsigned char * pesdata() const
const unsigned char * data() const
const TSHeader * tsheader() const
uint64_t PTS(void) const
Presentation Time Stamp, present if HasPTS() is true.
bool HasESR() const
1 bit Elementary Stream Rate field is present
uint64_t DTS(void) const
Decode Time Stamp, present if HasDTS() is true.
bool HasESCR() const
1 bit Elementary Stream Clock Reference field is present
unsigned char * _fullbuffer
Pointer to allocated data.
MTV_PUBLIC unsigned char * pes_alloc(uint size)
bool CopyRight() const
1 bit If true packet may contain copy righted material and is known to have once contained materiale ...
unsigned char * _pesdata
Pointer to PES data in full buffer.
virtual bool HasCRC() const
1 bit Cyclic Redundancy Check present
void SetStreamID(uint id)
PESPacket(const PESPacket &pkt)
PESPacket(const unsigned char *pesdata)
bool HasPTS() const
1 bit Presentation Time Stamp field is present
bool HasDTS() const
1 bit Decoding Time Stamp field is present
bool HighPriority() const
1 bit Indicates if this is a high priority packet
void SetPSIOffset(uint offset)
void SetTotalLength(uint len)
uint _psiOffset
AFCOffset + StartOfFieldPointer.
uint _pesdataSize
Number of data bytes (TS header + PES data)
PESPacket()
noop constructor, only for use by derived classes
uint _allocSize
Total number of bytes we allocated.
MTV_PUBLIC void pes_free(unsigned char *ptr)
uint ScramblingControl() const
static uint8_t * SetLength(uint8_t *Data, int Length)
bool OriginalRecording() const
1 bit Original Recording
bool _badPacket
true if a CRC is not good yet
unsigned char * pesdata()
bool HasDSM() const
1 bit DSM field present (should always be false for broadcasts)
uint TSSizeInBuffer() const
bool DataAligned() const
1 bit Data alignment indicator (must be 0 for video)
Allows us to transform TS packets to PES packets, which are used to hold multimedia streams and very ...
bool HasACI() const
1 bit Additional Copy Info field is present
bool HasExtensionFlags() const
1 bit Extension flags are present