36 : m_pesData(const_cast<unsigned char*>(pesdata)),
37 m_fullBuffer(const_cast<unsigned char*>(pesdata)),
38 m_badPacket(!VerifyCRC())
42 explicit PESPacket(
const std::vector<uint8_t> &pesdata)
43 : m_pesData(const_cast<unsigned char*>(pesdata.data())),
44 m_fullBuffer(const_cast<unsigned char*>(pesdata.data())),
45 m_badPacket(!VerifyCRC())
56 : m_psiOffset(pkt.m_psiOffset),
57 m_ccLast(pkt.m_ccLast),
58 m_pesDataSize(pkt.m_pesDataSize),
59 m_allocSize(pkt.m_allocSize),
60 m_badPacket(pkt.m_badPacket)
81 m_fullBuffer =
nullptr;
88 bool AddTSPacket(
const TSPacket* tspacket,
int cardid,
bool &broken);
90 bool IsGood()
const {
return !m_badPacket; }
93 {
return reinterpret_cast<const TSHeader*
>(m_fullBuffer); }
95 {
return reinterpret_cast<TSHeader*
>(m_fullBuffer); }
97 void GetAsTSPackets(std::vector<TSPacket> &
output,
uint cc)
const;
102 {
return (m_pesData[1] & 0x0f) << 8 | m_pesData[2]; }
106 {
return (m_pesData[3] & 0x30) >> 4; }
115 bool CopyRight()
const {
return ((m_pesData[3] & 0
x2) >> 1) != 0; }
120 bool HasPTS()
const {
return ((m_pesData[4] & 0x80) >> 7) != 0; }
122 bool HasDTS()
const {
return ((m_pesData[4] & 0x40) >> 6) != 0; }
124 bool HasESCR()
const {
return ((m_pesData[4] & 0x20) >> 5) != 0; }
126 bool HasESR()
const {
return ((m_pesData[4] & 0x10) >> 4) != 0; }
128 bool HasDSM()
const {
return ((m_pesData[4] & 0x8) >> 3) != 0; }
130 bool HasACI()
const {
return ((m_pesData[4] & 0
x4) >> 2) != 0; }
132 virtual bool HasCRC()
const {
return ((m_pesData[4] & 0
x2) >> 1) != 0; }
141 (uint64_t(m_pesData[i+0] & 0x0e) << 29) |
142 (uint64_t(m_pesData[i+1] ) << 22) |
143 (uint64_t(m_pesData[i+2] & 0xfe) << 14) |
144 (uint64_t(m_pesData[i+3] ) << 7) |
145 (uint64_t(m_pesData[i+4] & 0xfe) >> 1);
150 int i = 6+(HasPTS()?5:0);
152 (uint64_t(m_pesData[i+0] & 0x0e) << 29) |
153 (uint64_t(m_pesData[i+1] ) << 22) |
154 (uint64_t(m_pesData[i+2] & 0xfe) << 14) |
155 (uint64_t(m_pesData[i+3] ) << 7) |
156 (uint64_t(m_pesData[i+4] & 0xfe) >> 1);
166 const unsigned char*
pesdata()
const {
return m_pesData; }
167 unsigned char*
pesdata() {
return m_pesData; }
169 const unsigned char*
data()
const {
return m_fullBuffer; }
170 unsigned char*
data() {
return m_fullBuffer; }
175 m_pesData[1] = (m_pesData[1] & 0xf0) | ((len>>8) & 0x0f);
176 m_pesData[2] = len & 0xff;
187 m_psiOffset = offset;
188 m_pesData = m_fullBuffer + m_psiOffset + 1;
193 if (!HasCRC() || (Length() < 1))
194 return kTheMagicNoCRCCRC;
195 uint offset = Length() - 1;
196 return ((m_pesData[offset+0]<<24) |
197 (m_pesData[offset+1]<<16) |
198 (m_pesData[offset+2]<<8) |
199 (m_pesData[offset+3]));
207 uint offset = Length() - 1;
208 m_pesData[offset+0] = (crc & 0xff000000) >> 24;
209 m_pesData[offset+1] = (crc & 0x00ff0000) >> 16;
210 m_pesData[offset+2] = (crc & 0x0000ff00) >> 8;
211 m_pesData[offset+3] = (crc & 0x000000ff);
214 uint CalcCRC(
void)
const;
215 bool VerifyCRC(
void)
const;
216 bool VerifyCRC(
int cardid,
int pid)
const;
221 unsigned char *m_pesData {
nullptr };
222 unsigned char *m_fullBuffer {
nullptr };
228 bool m_badPacket {
false };
232 static const uint kTheMagicNoCRCCRC = 0xFFFFFFFF;
235 static constexpr
uint kMpegCRCSize { 4 };
246 float aspect(
bool mpeg1)
const;
258 #endif // PES_PACKET_H