33 #define TS_SYNC_BYTE 0x47 36 #define TS_PAYLOAD_START 0x40 37 #define TS_TRANSPORT_PRIORITY 0x20 38 #define TS_PID_MASK_HI 0x1F 39 #define TS_SCRAMBLING_CONTROL 0xC0 40 #define TS_ADAPT_FIELD_EXISTS 0x20 41 #define TS_PAYLOAD_EXISTS 0x10 42 #define TS_CONT_CNT_MASK 0x0F 43 #define TS_ADAPT_DISCONT 0x80 44 #define TS_ADAPT_RANDOM_ACC 0x40 // would be perfect for detecting independent frames, but unfortunately not used by all broadcasters 45 #define TS_ADAPT_ELEM_PRIO 0x20 46 #define TS_ADAPT_PCR 0x10 47 #define TS_ADAPT_OPCR 0x08 48 #define TS_ADAPT_SPLICING 0x04 49 #define TS_ADAPT_TP_PRIVATE 0x02 50 #define TS_ADAPT_EXTENSION 0x01 52 #define PATPID 0x0000 // PAT PID (constant 0) 53 #define CATPID 0x0001 // CAT PID (constant 1) 54 #define MAXPID 0x2000 // for arrays that use a PID as the index 56 #define PTSTICKS 90000 // number of PTS ticks per second 57 #define PCRFACTOR 300 // conversion from 27MHz PCR extension to 90kHz PCR base 58 #define MAX33BIT 0x00000001FFFFFFFFLL // max. possible value with 33 bit 59 #define MAX27MHZ ((MAX33BIT + 1) * PCRFACTOR - 1) // max. possible PCR value 131 return ((((int64_t)p[ 6]) << 25) |
132 (((int64_t)p[ 7]) << 17) |
133 (((int64_t)p[ 8]) << 9) |
134 (((int64_t)p[ 9]) << 1) |
136 (((((int)p[10]) & 0x01) << 8) |
170 return 6 + p[4] * 256 + p[5];
180 return (p[7] & 0x80) && p[8] >= 5;
185 return (p[7] & 0x40) && p[8] >= 10;
190 return ((((int64_t)p[ 9]) & 0x0E) << 29) |
191 (( (int64_t)p[10]) << 22) |
192 ((((int64_t)p[11]) & 0xFE) << 14) |
193 (( (int64_t)p[12]) << 7) |
194 ((((int64_t)p[13]) & 0xFE) >> 1);
199 return ((((int64_t)p[14]) & 0x0E) << 29) |
200 (( (int64_t)p[15]) << 22) |
201 ((((int64_t)p[16]) & 0xFE) << 14) |
202 (( (int64_t)p[17]) << 7) |
203 ((((int64_t)p[18]) & 0xFE) >> 1);
211 inline int64_t
PtsAdd(int64_t Pts1, int64_t Pts2) {
return (Pts1 + Pts2) &
MAX33BIT; }
213 int64_t
PtsDiff(int64_t Pts1, int64_t Pts2);
236 void Setup(
uchar *Data,
int Length,
int Pid = -1);
257 bool Eof(
void)
const {
return index >= length; }
259 void Statistics(
void)
const;
265 bool SkipBytes(
int Bytes);
268 bool SkipPesHeader(
void);
270 int GetLastIndex(
void);
273 void SetByte(
uchar Byte,
int Index);
278 bool Find(uint32_t Code);
290 #define MAX_SECTION_SIZE 4096 // maximum size of an SI section 291 #define MAX_PMT_TS (MAX_SECTION_SIZE / TS_SIZE + 1) 304 void IncCounter(
int &Counter,
uchar *TsPacket);
305 void IncVersion(
int &Version);
306 void IncEsInfoLength(
int Length);
308 int MakeStream(
uchar *Target,
uchar Type,
int Pid);
309 int MakeAC3Descriptor(
uchar *Target,
uchar Type);
310 int MakeSubtitlingDescriptor(
uchar *Target,
const char *Language,
uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId);
312 int MakeLanguageDescriptor(
uchar *Target,
const char *Language);
313 int MakeCRC(
uchar *Target,
const uchar *Data,
int Length);
314 void GeneratePmtPid(
const cChannel *Channel);
317 void GeneratePat(
void);
319 void GeneratePmt(
const cChannel *Channel);
324 void SetVersions(
int PatVersion,
int PmtVersion);
333 void SetChannel(
const cChannel *Channel);
338 uchar *GetPmt(
int &Index);
347 #define MAX_PMT_PIDS 32 375 int SectionLength(
const uchar *Data,
int Length) {
return (Length >= 3) ? ((int(Data[1]) & 0x0F) << 8)| Data[2] : 0; }
381 void ParsePat(
const uchar *Data,
int Length);
384 void ParsePmt(
const uchar *Data,
int Length);
391 bool ParsePatPmt(
const uchar *Data,
int Length);
395 bool GetVersions(
int &PatVersion,
int &PmtVersion)
const;
398 bool IsPmtPid(
int Pid)
const {
for (
int i = 0; pmtPids[i]; i++)
if (pmtPids[i] == Pid)
return true;
return false; }
401 int Vpid(
void)
const {
return vpid; }
404 int Ppid(
void)
const {
return ppid; }
407 int Vtype(
void)
const {
return vtype; }
410 int Tpid(
void) {
return tpid; }
413 const int *
Apids(
void)
const {
return apids; }
414 const int *
Dpids(
void)
const {
return dpids; }
415 const int *
Spids(
void)
const {
return spids; }
416 int Apid(
int i)
const {
return (0 <= i && i <
MAXAPIDS) ? apids[i] : 0; }
417 int Dpid(
int i)
const {
return (0 <= i && i <
MAXDPIDS) ? dpids[i] : 0; }
418 int Spid(
int i)
const {
return (0 <= i && i <
MAXSPIDS) ? spids[i] : 0; }
421 const char *
Alang(
int i)
const {
return (0 <= i && i <
MAXAPIDS) ? alangs[i] :
""; }
422 const char *
Dlang(
int i)
const {
return (0 <= i && i <
MAXDPIDS) ? dlangs[i] :
""; }
423 const char *
Slang(
int i)
const {
return (0 <= i && i <
MAXSPIDS) ? slangs[i] :
""; }
447 void PutTs(
const uchar *Data,
int Length);
457 const uchar *GetPes(
int &Length);
471 void SetRepeatLast(
void);
483 void TsDump(
const char *Name,
const u_char *Data,
int Length);
484 void PesDump(
const char *Name,
const u_char *Data,
int Length);
488 #define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 100 494 enum { MaxPtsValues = 150 };
500 uint32_t ptsValues[MaxPtsValues];
515 void SetPid(
int Pid,
int Type);
517 int Analyze(
const uchar *Data,
int Length);
538 #define PATCH_NALUDUMP 100 575 bool ProcessTSPacket(
unsigned char *Packet);
578 void ProcessPayload(
unsigned char *Payload,
int size,
bool PayloadStart,
sPayloadInfo &Info);
601 void PutBuffer(
uchar *Data,
int Length);
603 uchar* GetBuffer(
int &OutLength);
const int * Dpids(void) const
int64_t PtsAdd(int64_t Pts1, int64_t Pts2)
Adds the given PTS values, taking into account the 33bit wrap around.
int Used(void)
Returns the number of raw bytes that have already been used (e.g.
const char * Slang(int i) const
bool TsError(const uchar *p)
int PesPayloadOffset(const uchar *p)
bool TsHasAdaptationField(const uchar *p)
bool TsPayloadStart(const uchar *p)
int64_t TsGetDts(const uchar *p, int l)
void TsExtendAdaptionField(unsigned char *Packet, int ToLength)
bool IsPmtPid(int Pid) const
Returns true if Pid the one of the PMT pids as defined by the current PAT.
int64_t PesGetPts(const uchar *p)
long long int GetDroppedPackets()
uchar SubtitlingType(int i) const
bool TsHasPayload(const uchar *p)
int Vtype(void) const
Returns the video stream type as defined by the current PMT, or 0 if no video stream type has been de...
void TsHidePayload(uchar *p)
#define TS_SCRAMBLING_CONTROL
#define TS_ADAPT_FIELD_EXISTS
int Ppid(void) const
Returns the PCR pid as defined by the current PMT, or 0 if no PCR pid has been detected, yet.
int Tpid(void)
Returns the teletext pid as defined by the current PMT, or 0 if no teletext pid has been detected...
void BlockDump(const char *Name, const u_char *Data, int Length)
void TsSetDts(uchar *p, int l, int64_t Dts)
bool AtPayloadStart(void)
Returns true if this payload handler is currently pointing to the first byte of a TS packet that star...
bool PesHasPts(const uchar *p)
cPatPmtParser * pPatPmtParser
int SectionLength(const uchar *Data, int Length)
int Available(void)
Returns the number of raw bytes (including any TS headers) still available in the TS payload handler...
bool TsSetPayload(const uchar *p)
bool Synced(void)
Returns true if the frame detector has synced on the data stream.
bool PesLongEnough(int Length)
long long int GetTotalPackets()
int64_t TsGetPts(const uchar *p, int l)
int TsPid(const uchar *p)
long long int DroppedPackets
#define TS_PAYLOAD_EXISTS
int PesLength(const uchar *p)
void TsSetPcr(uchar *p, int64_t Pcr)
void PesDump(const char *Name, const u_char *Data, int Length)
int TsContinuityCounter(const uchar *p)
const int * Apids(void) const
uchar TsGetContinuityCounter(const uchar *p)
bool PesHasDts(const uchar *p)
const char * Alang(int i) const
void TsDump(const char *Name, const u_char *Data, int Length)
const int * Spids(void) const
const char * Dlang(int i) const
void PesSetDts(uchar *p, int64_t Dts)
void TsSetContinuityCounter(uchar *p, uchar Counter)
bool Eof(void) const
Returns true if all available bytes of the TS payload have been processed.
int TsGetPayload(const uchar **p)
long long int TotalPackets
void PesSetPts(uchar *p, int64_t Pts)
const tTeletextSubtitlePage * TeletextSubtitlePages() const
static void SetBrokenLink(uchar *Data, int Length)
uint16_t AncillaryPageId(int i) const
int64_t TsGetPcr(const uchar *p)
void TsSetPts(uchar *p, int l, int64_t Pts)
int Vpid(void) const
Returns the video pid as defined by the current PMT, or 0 if no video pid has been detected...
int TotalTeletextSubtitlePages() const
bool PesHasLength(const uchar *p)
uint16_t CompositionPageId(int i) const
bool NewFrame(void)
Returns true if the data given to the last call to Analyze() started a new frame. ...
bool IndependentFrame(void)
Returns true if a new frame was detected and this is an independent frame (i.e.
int totalTtxtSubtitlePages
bool TsIsScrambled(const uchar *p)
int64_t PesGetDts(const uchar *p)
int DropPayloadStartBytes
double FramesPerSecond(void)
Returns the number of frames per second, or 0 if this information is not available.
eNaluFillState NaluFillState
int TsPayloadOffset(const uchar *p)
bool AtTsStart(void)
Returns true if this payload handler is currently pointing to first byte of a TS packet.
int64_t PtsDiff(int64_t Pts1, int64_t Pts2)
Returns the difference between two PTS values.
void SetPatPmtParser(cPatPmtParser *_pPatPmtParser)
ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader=NULL)