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 EITPID 0x0012 // EIT PID (constant 18) 55 #define MAXPID 0x2000 // for arrays that use a PID as the index 57 #define PTSTICKS 90000 // number of PTS ticks per second 58 #define PCRFACTOR 300 // conversion from 27MHz PCR extension to 90kHz PCR base 59 #define MAX33BIT 0x00000001FFFFFFFFLL // max. possible value with 33 bit 60 #define MAX27MHZ ((MAX33BIT + 1) * PCRFACTOR - 1) // max. possible PCR value 133 return ((((int64_t)p[ 6]) << 25) |
134 (((int64_t)p[ 7]) << 17) |
135 (((int64_t)p[ 8]) << 9) |
136 (((int64_t)p[ 9]) << 1) |
138 (((((int)p[10]) & 0x01) << 8) |
154 #define TS_SYNC(Data, Length) (*Data == TS_SYNC_BYTE ? 0 : TsSync(Data, Length, __FILE__, __FUNCTION__, __LINE__)) 155 int TsSync(
const uchar *Data,
int Length,
const char *File = NULL,
const char *Function = NULL,
int Line = 0);
181 return 6 + p[4] * 256 + p[5];
191 return (p[7] & 0x80) && p[8] >= 5;
196 return (p[7] & 0x40) && p[8] >= 10;
201 return ((((int64_t)p[ 9]) & 0x0E) << 29) |
202 (( (int64_t)p[10]) << 22) |
203 ((((int64_t)p[11]) & 0xFE) << 14) |
204 (( (int64_t)p[12]) << 7) |
205 ((((int64_t)p[13]) & 0xFE) >> 1);
210 return ((((int64_t)p[14]) & 0x0E) << 29) |
211 (( (int64_t)p[15]) << 22) |
212 ((((int64_t)p[16]) & 0xFE) << 14) |
213 (( (int64_t)p[17]) << 7) |
214 ((((int64_t)p[18]) & 0xFE) >> 1);
222 inline int64_t
PtsAdd(int64_t Pts1, int64_t Pts2) {
return (Pts1 + Pts2) &
MAX33BIT; }
224 int64_t
PtsDiff(int64_t Pts1, int64_t Pts2);
247 void Setup(
uchar *Data,
int Length,
int Pid = -1);
289 bool Find(uint32_t Code);
301 #define MAX_SECTION_SIZE 4096 // maximum size of an SI section 302 #define MAX_PMT_TS (MAX_SECTION_SIZE / TS_SIZE + 1) 357 #define MAX_PMT_PIDS 32 383 int SectionLength(
const uchar *Data,
int Length) {
return (Length >= 3) ? ((int(Data[1]) & 0x0F) << 8)| Data[2] : 0; }
403 bool GetVersions(
int &PatVersion,
int &PmtVersion)
const;
443 uint16_t
YMDtoMJD(
int Y,
int M,
int D);
504 void TsDump(
const char *Name,
const u_char *Data,
int Length);
505 void PesDump(
const char *Name,
const u_char *Data,
int Length);
509 #define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 100 536 void SetPid(
int Pid,
int Type);
559 #define PATCH_NALUDUMP 100
bool ParsePatPmt(const uchar *Data, int Length)
Parses the given Data (which may consist of several TS packets, typically an entire frame) and extrac...
const int * Dpids(void) const
void ParsePat(const uchar *Data, int Length)
Parses the PAT data from the single TS packet in Data.
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.
uchar GetByte(void)
Gets the next byte of the TS payload, skipping any intermediate TS header data.
uchar subtitlingTypes[MAXSPIDS]
const char * Slang(int i) const
void SetVersions(int PatVersion, int PmtVersion)
Sets the version numbers for the generated PAT and PMT, in case this generator is used to...
bool TsError(const uchar *p)
void SetPid(int Pid, int Type)
Sets the Pid and stream Type to detect frames for.
int PesPayloadOffset(const uchar *p)
void IncCounter(int &Counter, uchar *TsPacket)
bool SkipBytes(int Bytes)
Skips the given number of bytes in the payload and returns true if there is still data left to read...
bool TsHasAdaptationField(const uchar *p)
void ParsePmt(const uchar *Data, int Length)
Parses the PMT data from the single TS packet in Data.
uint16_t ancillaryPageIds[MAXSPIDS]
char alangs[MAXAPIDS][MAXLANGCODE2]
bool TsPayloadStart(const uchar *p)
int64_t TsGetDts(const uchar *p, int l)
void TsExtendAdaptionField(unsigned char *Packet, int ToLength)
int MakeLanguageDescriptor(uchar *Target, const char *Language)
bool IsPmtPid(int Pid) const
Returns true if Pid the one of the PMT pids as defined by the current PAT.
void GeneratePmtPid(const cChannel *Channel)
Generates a PMT pid that doesn't collide with any of the actual pids of the Channel.
int64_t PesGetPts(const uchar *p)
int Analyze(const uchar *Data, int Length)
Analyzes the TS packets pointed to by Data.
long long int GetDroppedPackets()
uint16_t YMDtoMJD(int Y, int M, int D)
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)
uint32_t ptsValues[MaxPtsValues]
char slangs[MAXSPIDS][MAXLANGCODE2]
#define TS_SCRAMBLING_CONTROL
#define TS_ADAPT_FIELD_EXISTS
void TsSetPid(uchar *p, int Pid)
void IncEsInfoLength(int Length)
int MakeCRC(uchar *Target, const uchar *Data, int Length)
int Ppid(void) const
Returns the PCR pid as defined by the current PMT, or 0 if no PCR pid has been detected, yet.
void BlockDump(const char *Name, const u_char *Data, int Length)
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
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)
cPatPmtGenerator(const cChannel *Channel=NULL)
int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId)
void Setup(uchar *Data, int Length, int Pid=-1)
Sets up this TS payload handler with the given Data, which points to a sequence of Length bytes of co...
cPatPmtParser * pPatPmtParser
int MakeAC3Descriptor(uchar *Target, uchar Type)
void GeneratePat(void)
Generates a PAT section for later use with GetPat().
bool Find(uint32_t Code)
Searches for the four byte sequence given in Code and returns true if it was found within the payload...
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...
int MakeStream(uchar *Target, uchar Type, int Pid)
uchar pmt[MAX_PMT_TS][TS_SIZE]
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
cFrameDetector(int Pid=0, int Type=0)
Sets up a frame detector for the given Pid and stream Type.
#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)
bool GetVersions(int &PatVersion, int &PmtVersion) const
Returns true if a valid PAT/PMT has been parsed and stores the current version numbers in the given v...
char dlangs[MAXDPIDS][MAXLANGCODE2]
void Reset(void)
Resets the converter.
const int * Apids(void) const
bool PesHasDts(const uchar *p)
const char * Alang(int i) const
void TsDump(const char *Name, const u_char *Data, int Length)
cPatPmtParser(bool UpdatePrimaryDevice=false)
int GetLastIndex(void)
Returns the index into the TS data of the payload byte that has most recently been read...
const int * Spids(void) const
const char * Dlang(int i) const
void PesSetDts(uchar *p, int64_t Dts)
void PutTs(const uchar *Data, int Length)
Puts the payload data of the single TS packet at Data into the converter.
uchar * GetPmt(int &Index)
Returns a pointer to the Index'th TS packet of the PMT section.
void TsSetContinuityCounter(uchar *p, uchar Counter)
void ProcessPayload(unsigned char *Payload, int size, bool PayloadStart, sPayloadInfo &Info)
uchar * Generate(int Sid)
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 GeneratePmt(const cChannel *Channel)
Generates a PMT section for the given Channel, for later use with GetPmt().
uchar pmt[MAX_SECTION_SIZE]
uint16_t compositionPageIds[MAXSPIDS]
void PesSetPts(uchar *p, int64_t Pts)
bool Completed(void)
Returns true if the PMT has been completely parsed.
int pmtPids[MAX_PMT_PIDS+1]
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)
bool ProcessTSPacket(unsigned char *Packet)
int Vpid(void) const
Returns the video pid as defined by the current PMT, or 0 if no video pid has been detected...
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.
uchar * AddParentalRatingDescriptor(uchar *p, uchar ParentalRating=0)
bool TsIsScrambled(const uchar *p)
int64_t PesGetDts(const uchar *p)
void SetByte(uchar Byte, int Index)
Sets the TS data byte at the given Index to the value Byte.
int DropPayloadStartBytes
double FramesPerSecond(void)
Returns the number of frames per second, or 0 if this information is not available.
eNaluFillState NaluFillState
uchar TsContinuityCounter(const uchar *p)
void Statistics(void) const
May be called after a new frame has been detected, and will log a warning if the number of TS packets...
void IncVersion(int &Version)
const uchar * GetPes(int &Length)
Gets a pointer to the complete PES packet, or NULL if the packet is not complete yet.
int TsPayloadOffset(const uchar *p)
int TsSync(const uchar *Data, int Length, const char *File=NULL, const char *Function=NULL, int Line=0)
void SetRepeatLast(void)
Makes the next call to GetPes() return exactly the same data as the last one (provided there was no c...
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)
void PutBuffer(uchar *Data, int Length)
void Reset(void)
Resets the parser.
ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader=NULL)
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
uchar * GetBuffer(int &OutLength)
bool SkipPesHeader(void)
Skips all bytes belonging to the PES header of the payload.
uchar tempBuffer[TS_SIZE]