34 : m_pesData(const_cast<unsigned char*>(pesdata)),
35 m_fullBuffer(const_cast<unsigned char*>(pesdata)),
36 m_badPacket(!VerifyCRC())
40 explicit PESPacket(
const std::vector<uint8_t> &pesdata)
41 : m_pesData(const_cast<unsigned char*>(pesdata.data())),
42 m_fullBuffer(const_cast<unsigned char*>(pesdata.data())),
43 m_badPacket(!VerifyCRC())
54 : m_psiOffset(pkt.m_psiOffset),
55 m_ccLast(pkt.m_ccLast),
56 m_pesDataSize(pkt.m_pesDataSize),
57 m_allocSize(pkt.m_allocSize),
58 m_badPacket(pkt.m_badPacket)
79 m_fullBuffer =
nullptr;
86 bool AddTSPacket(
const TSPacket* tspacket,
int cardid,
bool &broken);
88 bool IsGood()
const {
return !m_badPacket; }
91 {
return reinterpret_cast<const TSHeader*
>(m_fullBuffer); }
93 {
return reinterpret_cast<TSHeader*
>(m_fullBuffer); }
95 void GetAsTSPackets(std::vector<TSPacket> &
output,
uint cc)
const;
100 {
return (m_pesData[1] & 0x0f) << 8 | m_pesData[2]; }
104 {
return (m_pesData[3] & 0x30) >> 4; }
108 bool DataAligned()
const {
return ((m_pesData[3] & 0x4) >> 2) != 0; }
113 bool CopyRight()
const {
return ((m_pesData[3] & 0x2) >> 1) != 0; }
118 bool HasPTS()
const {
return ((m_pesData[4] & 0x80) >> 7) != 0; }
120 bool HasDTS()
const {
return ((m_pesData[4] & 0x40) >> 6) != 0; }
122 bool HasESCR()
const {
return ((m_pesData[4] & 0x20) >> 5) != 0; }
124 bool HasESR()
const {
return ((m_pesData[4] & 0x10) >> 4) != 0; }
126 bool HasDSM()
const {
return ((m_pesData[4] & 0x8) >> 3) != 0; }
128 bool HasACI()
const {
return ((m_pesData[4] & 0x4) >> 2) != 0; }
130 virtual bool HasCRC()
const {
return ((m_pesData[4] & 0x2) >> 1) != 0; }
139 (uint64_t(m_pesData[i+0] & 0x0e) << 29) |
140 (uint64_t(m_pesData[i+1] ) << 22) |
141 (uint64_t(m_pesData[i+2] & 0xfe) << 14) |
142 (uint64_t(m_pesData[i+3] ) << 7) |
143 (uint64_t(m_pesData[i+4] & 0xfe) >> 1);
148 int i = 6+(HasPTS()?5:0);
150 (uint64_t(m_pesData[i+0] & 0x0e) << 29) |
151 (uint64_t(m_pesData[i+1] ) << 22) |
152 (uint64_t(m_pesData[i+2] & 0xfe) << 14) |
153 (uint64_t(m_pesData[i+3] ) << 7) |
154 (uint64_t(m_pesData[i+4] & 0xfe) >> 1);
164 const unsigned char*
pesdata()
const {
return m_pesData; }
165 unsigned char*
pesdata() {
return m_pesData; }
167 const unsigned char*
data()
const {
return m_fullBuffer; }
168 unsigned char*
data() {
return m_fullBuffer; }
173 m_pesData[1] = (m_pesData[1] & 0xf0) | ((len>>8) & 0x0f);
174 m_pesData[2] = len & 0xff;
185 m_psiOffset = offset;
186 m_pesData = m_fullBuffer + m_psiOffset + 1;
191 if (!HasCRC() || (Length() < 1))
192 return kTheMagicNoCRCCRC;
193 uint offset = Length() - 1;
194 return ((m_pesData[offset+0]<<24) |
195 (m_pesData[offset+1]<<16) |
196 (m_pesData[offset+2]<<8) |
197 (m_pesData[offset+3]));
205 uint offset = Length() - 1;
206 m_pesData[offset+0] = (crc & 0xff000000) >> 24;
207 m_pesData[offset+1] = (crc & 0x00ff0000) >> 16;
208 m_pesData[offset+2] = (crc & 0x0000ff00) >> 8;
209 m_pesData[offset+3] = (crc & 0x000000ff);
212 uint CalcCRC(
void)
const;
213 bool VerifyCRC(
void)
const;
214 bool VerifyCRC(
int cardid,
int pid)
const;
219 unsigned char *m_pesData {
nullptr };
220 unsigned char *m_fullBuffer {
nullptr };
226 bool m_badPacket {
false };
230 static const uint kTheMagicNoCRCCRC = 0xFFFFFFFF;
233 static constexpr uint kMpegCRCSize { 4 };
244 float aspect(
bool mpeg1)
const;
Allows us to transform TS packets to PES packets, which are used to hold multimedia streams and very ...
PESPacket(const unsigned char *pesdata)
void SetTotalLength(uint len)
bool OriginalRecording() const
1 bit Original Recording
uint ScramblingControl() const
const unsigned char * data() const
PESPacket & operator=(const PESPacket &pkt)=delete
unsigned char * m_pesData
Pointer to PES data in full buffer.
unsigned char * pesdata()
bool DataAligned() const
1 bit Data alignment indicator (must be 0 for video)
bool HighPriority() const
1 bit Indicates if this is a high priority packet
uint m_pesDataSize
Number of data bytes (TS header + PES data)
const TSHeader * tsheader() const
void SetStreamID(uint id)
bool HasPTS() const
1 bit Presentation Time Stamp field is present
bool HasACI() const
1 bit Additional Copy Info field is present
const unsigned char * pesdata() const
virtual bool HasCRC() const
1 bit Cyclic Redundancy Check present
bool HasESR() const
1 bit Elementary Stream Rate field is present
uint64_t DTS(void) const
Decode Time Stamp, present if HasDTS() is true.
PESPacket(const PESPacket &pkt)
unsigned char * m_fullBuffer
Pointer to allocated data.
bool HasExtensionFlags() const
1 bit Extension flags are present
void SetPSIOffset(uint offset)
bool HasDSM() const
1 bit DSM field present (should always be false for broadcasts)
bool HasESCR() const
1 bit Elementary Stream Clock Reference field is present
bool HasDTS() const
1 bit Decoding Time Stamp field is present
uint TSSizeInBuffer() const
PESPacket()=default
noop constructor, only for use by derived classes
PESPacket(const std::vector< uint8_t > &pesdata)
uint64_t PTS(void) const
Presentation Time Stamp, present if HasPTS() is true.
bool CopyRight() const
1 bit If true packet may contain copy righted material and is known to have once contained materiale ...
Used to access the data of a Transport Stream packet.
static uint8_t * SetLength(uint8_t *Data, int Length)
MTV_PUBLIC void pes_free(unsigned char *ptr)
MTV_PUBLIC unsigned char * pes_alloc(uint size)
std::array< float, 16 > AspectArray