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 MAXPID 0x2000 // for arrays that use a PID as the index
55 #define PTSTICKS 90000 // number of PTS ticks per second
56 #define PCRFACTOR 300 // conversion from 27MHz PCR extension to 90kHz PCR base
57 #define MAX33BIT 0x00000001FFFFFFFFLL // max. possible value with 33 bit
58 #define MAX27MHZ ((MAX33BIT + 1) * PCRFACTOR - 1) // max. possible PCR value
130 return ((((int64_t)p[ 6]) << 25) |
131 (((int64_t)p[ 7]) << 17) |
132 (((int64_t)p[ 8]) << 9) |
133 (((int64_t)p[ 9]) << 1) |
135 (((((int)p[10]) & 0x01) << 8) |
169 return 6 + p[4] * 256 + p[5];
179 return (p[7] & 0x80) && p[8] >= 5;
184 return (p[7] & 0x40) && p[8] >= 10;
189 return ((((int64_t)p[ 9]) & 0x0E) << 29) |
190 (( (int64_t)p[10]) << 22) |
191 ((((int64_t)p[11]) & 0xFE) << 14) |
192 (( (int64_t)p[12]) << 7) |
193 ((((int64_t)p[13]) & 0xFE) >> 1);
198 return ((((int64_t)p[14]) & 0x0E) << 29) |
199 (( (int64_t)p[15]) << 22) |
200 ((((int64_t)p[16]) & 0xFE) << 14) |
201 (( (int64_t)p[17]) << 7) |
202 ((((int64_t)p[18]) & 0xFE) >> 1);
210 inline int64_t
PtsAdd(int64_t Pts1, int64_t Pts2) {
return (Pts1 + Pts2) &
MAX33BIT; }
212 int64_t
PtsDiff(int64_t Pts1, int64_t Pts2);
232 void Setup(
uchar *Data,
int Length,
int Pid = -1);
270 bool Find(uint32_t Code);
282 #define MAX_SECTION_SIZE 4096 // maximum size of an SI section
283 #define MAX_PMT_TS (MAX_SECTION_SIZE / TS_SIZE + 1)
339 #define MAX_PMT_PIDS 32
367 int SectionLength(
const uchar *Data,
int Length) {
return (Length >= 3) ? ((int(Data[1]) & 0x0F) << 8)| Data[2] : 0; }
387 bool GetVersions(
int &PatVersion,
int &PmtVersion)
const;
475 void TsDump(
const char *Name,
const u_char *Data,
int Length);
476 void PesDump(
const char *Name,
const u_char *Data,
int Length);
480 #define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 5
508 void SetPid(
int Pid,
int Type);
531 #define PATCH_NALUDUMP 100