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 126 return ((((int64_t)p[ 6]) << 25) |
127 (((int64_t)p[ 7]) << 17) |
128 (((int64_t)p[ 8]) << 9) |
129 (((int64_t)p[ 9]) << 1) |
131 (((((int)p[10]) & 0x01) << 8) |
164 return 6 + p[4] * 256 + p[5];
174 return (p[7] & 0x80) && p[8] >= 5;
179 return (p[7] & 0x40) && p[8] >= 10;
184 return ((((int64_t)p[ 9]) & 0x0E) << 29) |
185 (( (int64_t)p[10]) << 22) |
186 ((((int64_t)p[11]) & 0xFE) << 14) |
187 (( (int64_t)p[12]) << 7) |
188 ((((int64_t)p[13]) & 0xFE) >> 1);
193 return ((((int64_t)p[14]) & 0x0E) << 29) |
194 (( (int64_t)p[15]) << 22) |
195 ((((int64_t)p[16]) & 0xFE) << 14) |
196 (( (int64_t)p[17]) << 7) |
197 ((((int64_t)p[18]) & 0xFE) >> 1);
205 inline int64_t
PtsAdd(int64_t Pts1, int64_t Pts2) {
return (Pts1 + Pts2) &
MAX33BIT; }
207 int64_t
PtsDiff(int64_t Pts1, int64_t Pts2);
230 void Setup(
uchar *Data,
int Length,
int Pid = -1);
251 bool Eof(
void)
const {
return index >= length; }
253 void Statistics(
void)
const;
259 bool SkipBytes(
int Bytes);
262 bool SkipPesHeader(
void);
264 int GetLastIndex(
void);
267 void SetByte(
uchar Byte,
int Index);
272 bool Find(uint32_t Code);
284 #define MAX_SECTION_SIZE 4096 // maximum size of an SI section 285 #define MAX_PMT_TS (MAX_SECTION_SIZE / TS_SIZE + 1) 298 void IncCounter(
int &Counter,
uchar *TsPacket);
299 void IncVersion(
int &Version);
300 void IncEsInfoLength(
int Length);
302 int MakeStream(
uchar *Target,
uchar Type,
int Pid);
303 int MakeAC3Descriptor(
uchar *Target,
uchar Type);
304 int MakeSubtitlingDescriptor(
uchar *Target,
const char *Language,
uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId);
305 int MakeLanguageDescriptor(
uchar *Target,
const char *Language);
306 int MakeCRC(
uchar *Target,
const uchar *Data,
int Length);
307 void GeneratePmtPid(
const cChannel *Channel);
310 void GeneratePat(
void);
312 void GeneratePmt(
const cChannel *Channel);
317 void SetVersions(
int PatVersion,
int PmtVersion);
326 void SetChannel(
const cChannel *Channel);
331 uchar *GetPmt(
int &Index);
340 #define MAX_PMT_PIDS 32 365 int SectionLength(
const uchar *Data,
int Length) {
return (Length >= 3) ? ((int(Data[1]) & 0x0F) << 8)| Data[2] : 0; }
371 void ParsePat(
const uchar *Data,
int Length);
374 void ParsePmt(
const uchar *Data,
int Length);
381 bool ParsePatPmt(
const uchar *Data,
int Length);
385 bool GetVersions(
int &PatVersion,
int &PmtVersion)
const;
388 bool IsPmtPid(
int Pid)
const {
for (
int i = 0; pmtPids[i]; i++)
if (pmtPids[i] == Pid)
return true;
return false; }
391 int Vpid(
void)
const {
return vpid; }
394 int Ppid(
void)
const {
return ppid; }
397 int Vtype(
void)
const {
return vtype; }
400 const int *
Apids(
void)
const {
return apids; }
401 const int *
Dpids(
void)
const {
return dpids; }
402 const int *
Spids(
void)
const {
return spids; }
403 int Apid(
int i)
const {
return (0 <= i && i <
MAXAPIDS) ? apids[i] : 0; }
404 int Dpid(
int i)
const {
return (0 <= i && i <
MAXDPIDS) ? dpids[i] : 0; }
405 int Spid(
int i)
const {
return (0 <= i && i <
MAXSPIDS) ? spids[i] : 0; }
408 const char *
Alang(
int i)
const {
return (0 <= i && i <
MAXAPIDS) ? alangs[i] :
""; }
409 const char *
Dlang(
int i)
const {
return (0 <= i && i <
MAXDPIDS) ? dlangs[i] :
""; }
410 const char *
Slang(
int i)
const {
return (0 <= i && i <
MAXSPIDS) ? slangs[i] :
""; }
432 void PutTs(
const uchar *Data,
int Length);
442 const uchar *GetPes(
int &Length);
456 void SetRepeatLast(
void);
468 void TsDump(
const char *Name,
const u_char *Data,
int Length);
469 void PesDump(
const char *Name,
const u_char *Data,
int Length);
473 #define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 100 479 enum { MaxPtsValues = 150 };
485 uint32_t ptsValues[MaxPtsValues];
500 void SetPid(
int Pid,
int Type);
502 int Analyze(
const uchar *Data,
int Length);
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 * Alang(int i) const
bool TsError(const uchar *p)
int PesPayloadOffset(const uchar *p)
bool TsHasAdaptationField(const uchar *p)
bool IsPmtPid(int Pid) const
Returns true if Pid the one of the PMT pids as defined by the current PAT.
bool TsPayloadStart(const uchar *p)
int64_t TsGetDts(const uchar *p, int l)
uchar SubtitlingType(int i) const
int64_t PesGetPts(const uchar *p)
bool TsHasPayload(const uchar *p)
void TsHidePayload(uchar *p)
#define TS_SCRAMBLING_CONTROL
#define TS_ADAPT_FIELD_EXISTS
int Vpid(void) const
Returns the video pid as defined by the current PMT, or 0 if no video 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)
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 Eof(void) const
Returns true if all available bytes of the TS payload have been processed.
bool Synced(void)
Returns true if the frame detector has synced on the data stream.
bool PesLongEnough(int Length)
int64_t TsGetPts(const uchar *p, int l)
int TsPid(const uchar *p)
const char * Slang(int i) const
#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 Vtype(void) const
Returns the video stream type as defined by the current PMT, or 0 if no video stream type has been de...
int TsContinuityCounter(const uchar *p)
const int * Spids(void) const
uchar TsGetContinuityCounter(const uchar *p)
bool PesHasDts(const uchar *p)
void TsDump(const char *Name, const u_char *Data, int Length)
void PesSetDts(uchar *p, int64_t Dts)
const int * Dpids(void) const
void TsSetContinuityCounter(uchar *p, uchar Counter)
int TsGetPayload(const uchar **p)
void PesSetPts(uchar *p, int64_t Pts)
const int * Apids(void) const
static void SetBrokenLink(uchar *Data, int Length)
int64_t TsGetPcr(const uchar *p)
void TsSetPts(uchar *p, int l, int64_t Pts)
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.
bool TsIsScrambled(const uchar *p)
int64_t PesGetDts(const uchar *p)
const char * Dlang(int i) const
double FramesPerSecond(void)
Returns the number of frames per second, or 0 if this information is not available.
uint16_t AncillaryPageId(int i) const
int TsPayloadOffset(const uchar *p)
int Ppid(void) const
Returns the PCR pid as defined by the current PMT, or 0 if no PCR pid has been detected, yet.
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.
ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader=NULL)