9#include "libmythbase/mythconfig.h"
10#include "libavcodec/avcodec.h"
11#include "libavformat/avformat.h"
12#include "libavutil/crc.h"
13#include "libavutil/bswap.h"
25 LOG(VB_RECORD, LOG_ERR,
26 "Error: We started a PES packet, without a payloadStart!");
31 LOG(VB_RECORD, LOG_ERR,
32 "Error: Must clone initially to use addPackets()");
37 const int ccExp = (
m_ccLast + 1) & 0xf;
60 LOG(VB_GENERAL, LOG_ERR, QString(
"PESPacket[%1] Invalid adaptation field size:%2 control:%3")
64 payloadStart += delta;
82 packet->
data() + payloadStart,
93 LOG(VB_RECORD, LOG_ERR,
94 QString(
"AddTSPacket[%1]: Repeat packet!! ").arg(cardid) +
95 QString(
"PID: 0x%1, continuity counter: %2 ").arg(packet->
PID(),0,16).arg(cc) +
96 QString(
"(expected %1)").arg(ccExp));
105 LOG(VB_RECORD, LOG_ERR,
106 QString(
"AddTSPacket[%1]: Out of sync!!! Need to wait for next payloadStart ").arg(cardid) +
107 QString(
"PID: 0x%1, continuity counter: %2 ").arg(packet->
PID(),0,16).arg(cc) +
108 QString(
"(expected %1)").arg(ccExp));
140 LOG(VB_GENERAL, LOG_ERR,
"WriteAsTSPackets m_pesData == m_fullBuffer");
147 output[0].data()[3] = (
output[0].data()[3] & 0xf0) | cc;
152 header.
data()[1] = 0x00;
153 header.
data()[2] = 0x00;
154 header.
data()[3] = 0x10;
176 return av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE), UINT32_MAX,
185 LOG(VB_SIPARSER, LOG_INFO,
186 QString(
"PESPacket: Failed CRC check 0x%1 != 0x%2 "
187 "for StreamID = 0x%3")
188 .arg(
CRC(),8,16,QLatin1Char(
'0')).arg(
CalcCRC(),8,16,QLatin1Char(
'0')).arg(
StreamID(),0,16));
198 LOG(VB_RECORD, LOG_INFO,
199 QString(
"PESPacket[%1] pid(0x%2): ").arg(cardid).arg(pid,0,16) +
200 QString(
"Failed CRC check 0x%1 != 0x%2 for ID = 0x%3")
201 .arg(
CRC(),8,16,QLatin1Char(
'0')).arg(
CalcCRC(),8,16,QLatin1Char(
'0')).arg(
StreamID(),0,16));
209 0.0000F, 1.0000F, 0.6735F, 0.7031F,
210 0.7615F, 0.8055F, 0.8437F, 0.8935F,
211 0.9157F, 0.9815F, 1.0255F, 1.0695F,
212 1.0950F, 1.1575F, 1.2015F, 0.0000F,
219 0.0000F, 1.0000F, -3.0F/4.0F, -9.0F/16.0F,
220 -1.0F/2.21F, 0.0000F, 0.0000F, 0.0000F,
221 0.0000F, 0.0000F, 0.0000F, 0.0000F,
222 0.0000F, 0.0000F, 0.0000F, 0.0000F,
227 0.0F, 24000/1001.0F, 24.0F, 25.0F,
228 30000/1001.0F, 30.0F, 50.0F, 60000/1001.0F,
229 60.0F, 1.0F, 1.0F, 1.0F,
230 1.0F, 1.0F, 1.0F, 1.0F,
245 retval = (retval <= 0.0F) ?
width() * 1.0F /
height() : retval;
256static std::vector<unsigned char*>
mem188;
271 unsigned char* block_start =
mem188.back();
273 free188.push_back((i * 188_UZ) + block_start);
276 unsigned char *ptr =
free188.back();
294 std::vector<unsigned char*>::iterator it;
300 LOG(VB_GENERAL, LOG_DEBUG,
"freeing all 188 blocks");
312 unsigned char* block_start =
mem4096.back();
314 free4096.push_back((i * 4096_UZ) + block_start);
317 unsigned char *ptr =
free4096.back();
334 LOG(VB_GENERAL, LOG_DEBUG, QString(
"%1 4096 blocks remain")
336 map<unsigned char*, bool>::iterator it;
340 LGO(VB_GENERAL, LOG_DEBUG, QString(
"PES Packet: pid(0x%1)")
341 .arg(ts->
PID(),0,16));
342 if (ts->
PID() == 0x1ffb)
344 LOG(VB_GENERAL, LOG_DEBUG, QString(
" tid(0x%1) ext(0x%2)")
354 std::vector<unsigned char*>::iterator it;
360 LOG(VB_GENERAL, LOG_DEBUG,
"freeing all 4096 blocks");
377 return (
unsigned char*) malloc(size);
bool VerifyCRC(void) const
bool AddTSPacket(const TSPacket *tspacket, int cardid, bool &broken)
const unsigned char * data() const
static const uint kTheMagicNoCRCCRC
unsigned char * m_pesData
Pointer to PES data in full buffer.
uint m_psiOffset
AFCOffset + StartOfFieldPointer.
uint m_pesDataSize
Number of data bytes (TS header + PES data)
void GetAsTSPackets(std::vector< TSPacket > &output, uint cc) const
Returns payload only PESPacket as series of TSPackets.
const TSHeader * tsheader() const
uint m_allocSize
Total number of bytes we allocated.
bool m_badPacket
true if a CRC is not good yet
virtual bool HasCRC() const
1 bit Cyclic Redundancy Check present
unsigned char * m_fullBuffer
Pointer to allocated data.
uint m_ccLast
Continuity counter of last inserted TS Packet.
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
uint TableIDExtension(void) const
Used to access the data of a Transport Stream packet.
static constexpr unsigned int kPayloadSize
static constexpr unsigned int kSize
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static std::vector< unsigned char * > mem4096
static bool is_188_block(unsigned char *ptr)
void pes_free(unsigned char *ptr)
static std::vector< unsigned char * > free188
static unsigned char * get_188_block()
static void return_4096_block(unsigned char *ptr)
static bool is_4096_block(unsigned char *ptr)
static constexpr size_t BLOCKS188
static std::map< unsigned char *, bool > alloc188
static std::map< unsigned char *, bool > alloc4096
static std::vector< unsigned char * > free4096
static constexpr size_t BLOCKS4096
static unsigned char * get_4096_block()
unsigned char * pes_alloc(uint size)
static QMutex pes_alloc_mutex
static std::vector< unsigned char * > mem188
static void return_188_block(unsigned char *ptr)
std::array< float, 16 > AspectArray