47 using Clock = std::chrono::steady_clock;
48 using TimePoint = std::chrono::time_point<Clock, std::chrono::microseconds>;
61 SetContinuityCounter(
cc);
70 m_tsData[0]=header[0];
71 m_tsData[1]=header[1];
72 m_tsData[2]=header[2];
73 m_tsData[3]=header[3];
87 bool PayloadStart(
void)
const {
return ( m_tsData[1] & 0x40 ) != 0; }
89 bool Priority(
void)
const {
return ( m_tsData[1] & 0x20 ) != 0; }
91 unsigned int PID(
void)
const {
92 return ((m_tsData[1] << 8) + m_tsData[2]) & 0x1fff;
102 return (m_tsData[3] >> 4) & 0x3;
110 bool Scrambled(
void)
const {
return ( m_tsData[3] & 0x80 ) != 0; }
113 {
return (HasAdaptationField() ?
static_cast<size_t>(data()[4]) : 0); }
114 bool HasPayload(
void)
const {
return ( m_tsData[3] & 0x10 ) != 0; }
117 {
return (AdaptationFieldSize() > 0) && ((data()[5] & 0x80 ) != 0); }
119 bool HasPCR(
void)
const {
return (AdaptationFieldSize() > 0) &&
120 ((data()[5] & 0x10 ) != 0); }
130 {
return ((
static_cast<int64_t
>(data()[6]) << 25) |
131 (
static_cast<int64_t
>(data()[7]) << 17) |
132 (
static_cast<int64_t
>(data()[8]) << 9) |
133 (
static_cast<int64_t
>(data()[9]) << 1) |
134 (data()[10] >> 7)); }
138 {
return (((
static_cast<int32_t
>(data()[10]) & 0
x1) << 8) |
139 static_cast<int32_t
>(data()[11])); }
143 {
return ((GetPCRbase() * 300) + GetPCRext()); }
147 {
return TimePoint(std::chrono::microseconds(GetPCRraw() / 27)); }
150 if (err) m_tsData[1] |= 0x80;
else m_tsData[1] &= (0xff-(0x80));
153 if (start) m_tsData[1] |= 0x40;
else m_tsData[1] &= (0xff-0x40);
156 if (priority) m_tsData[1] |= 0x20;
else m_tsData[1] &= (0xff-0x20);
159 m_tsData[1] = ((pid >> 8) & 0x1F) | (m_tsData[1] & 0xE0);
160 m_tsData[2] = (pid & 0xFF);
163 m_tsData[3] = (m_tsData[3] & (0xff-(0x3<<6))) | (scr<<6);
166 m_tsData[3] = (m_tsData[3] & 0xcf) | (afc&0
x3)<<4;
169 m_tsData[3] = (m_tsData[3] & 0xf0) | (
cc & 0xf);
172 const unsigned char*
data(
void)
const {
return m_tsData.data(); }
173 unsigned char*
data(
void) {
return m_tsData.data(); }
175 static constexpr
unsigned int kHeaderSize {4};
181 static_assert(
sizeof(
TSHeader) == 4,
182 "The TSHeader class must be 4 bytes in size. It must "
183 "have only one non-static variable (m_tsData) of 4 "
184 "bytes, and it must not have any virtual functions.");
216 pkt->InitHeader(kPayloadOnlyHeader.data());
217 pkt->m_tsPayload.fill(0xFF);
218 pkt->SetStartOfFieldPointer(0);
224 memcpy(pkt,
this, kSize);
231 std::copy(payload, payload+kPayloadSize, m_tsPayload.data());
237 std::copy(payload, payload+size, m_tsPayload.data());
253 {
return m_tsPayload[AFCOffset()-4]; }
255 { m_tsPayload[AFCOffset()-4] = sof; }
259 static constexpr
unsigned int kSize {188};
260 static constexpr
unsigned int kPayloadSize {188-4};
261 static constexpr
unsigned int kDVBEmissionSize {204};
262 static constexpr
unsigned int kISDBEmissionSize {204};
263 static constexpr
unsigned int k8VSBEmissionSize {208};
269 static_assert(
sizeof(
TSPacket) == 188,
270 "The TSPacket class must be 188 bytes in size. It must "
271 "have only one non-static variable (m_tsPayload) of 184 "
272 "bytes, and it must not have any virtual functions.");
283 unsigned char m_tsFec[16];
292 unsigned char m_tsFec[16];
301 unsigned char m_tsFec[20];
305 #endif // TS_PACKET_H