Go to the documentation of this file.
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;
406 bool IsPmtPid(
int Pid)
const {
for (
int i = 0;
pmtPids[i]; i++)
if (
pmtPids[i] == Pid)
return true;
return false; }
409 int Vpid(
void)
const {
return vpid; }
412 int Ppid(
void)
const {
return ppid; }
415 int Vtype(
void)
const {
return vtype; }
418 bool Completed(
void) {
return completed; }
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);
544 bool Synced(
void) {
return synced; }
546 bool NewFrame(
void) {
return newFrame; }
559 #define PATCH_NALUDUMP 100
cPatPmtParser * pPatPmtParser
bool PesLongEnough(int Length)
int TsGetPayload(const uchar **p)
void TsSetPid(uchar *p, int Pid)
void SetPid(int Pid, int Type)
Sets the Pid and stream Type to detect frames for.
void GeneratePmt(const cChannel *Channel)
Generates a PMT section for the given Channel, for later use with GetPmt().
int TsSync(const uchar *Data, int Length, const char *File=NULL, const char *Function=NULL, int Line=0)
uchar * GetPmt(int &Index)
Returns a pointer to the Index'th TS packet of the PMT section.
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...
const char * Slang(int i) const
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...
void TsExtendAdaptionField(unsigned char *Packet, int ToLength)
#define TS_ADAPT_FIELD_EXISTS
int64_t PtsDiff(int64_t Pts1, int64_t Pts2)
Returns the difference between two PTS values.
const char * Dlang(int i) const
void PesDump(const char *Name, const u_char *Data, int Length)
int Analyze(const uchar *Data, int Length)
Analyzes the TS packets pointed to by Data.
void PesSetDts(uchar *p, int64_t Dts)
char alangs[MAXAPIDS][MAXLANGCODE2]
bool TsError(const uchar *p)
bool TsHasAdaptationField(const uchar *p)
cFrameDetector(int Pid=0, int Type=0)
Sets up a frame detector for the given Pid and stream Type.
int64_t PesGetDts(const uchar *p)
char dlangs[MAXDPIDS][MAXLANGCODE2]
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...
void ParsePat(const uchar *Data, int Length)
Parses the PAT data from the single TS packet in Data.
void SetPatPmtParser(cPatPmtParser *_pPatPmtParser)
uchar pmt[MAX_SECTION_SIZE]
uchar SubtitlingType(int i) const
uint16_t AncillaryPageId(int i) const
long long int TotalPackets
const char * Alang(int i) const
bool ParsePatPmt(const uchar *Data, int Length)
Parses the given Data (which may consist of several TS packets, typically an entire frame) and extrac...
void BlockDump(const char *Name, const u_char *Data, int Length)
int TsPayloadOffset(const uchar *p)
int TsPid(const uchar *p)
int64_t TsGetPcr(const uchar *p)
void IncVersion(int &Version)
#define TS_SCRAMBLING_CONTROL
uchar GetByte(void)
Gets the next byte of the TS payload, skipping any intermediate TS header data.
uint32_t ptsValues[MaxPtsValues]
int DropPayloadStartBytes
bool PesHasLength(const uchar *p)
bool Find(uint32_t Code)
Searches for the four byte sequence given in Code and returns true if it was found within the payload...
long long int GetTotalPackets()
int PesLength(const uchar *p)
bool TsHasPayload(const uchar *p)
long long int GetDroppedPackets()
static void SetBrokenLink(uchar *Data, int Length)
bool TsIsScrambled(const uchar *p)
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
int64_t TsGetPts(const uchar *p, int l)
void ProcessPayload(unsigned char *Payload, int size, bool PayloadStart, sPayloadInfo &Info)
bool ProcessTSPacket(unsigned char *Packet)
int GetLastIndex(void)
Returns the index into the TS data of the payload byte that has most recently been read.
void IncCounter(int &Counter, uchar *TsPacket)
bool PesHasDts(const uchar *p)
const int * Apids(void) const
bool TsPayloadStart(const uchar *p)
void SetVersions(int PatVersion, int PmtVersion)
Sets the version numbers for the generated PAT and PMT, in case this generator is used to,...
int MakeLanguageDescriptor(uchar *Target, const char *Language)
uint16_t ancillaryPageIds[MAXSPIDS]
uint16_t YMDtoMJD(int Y, int M, int D)
uchar * Generate(int Sid)
uchar * AddParentalRatingDescriptor(uchar *p, uchar ParentalRating=0)
void Reset(void)
Resets the parser.
int SectionLength(const uchar *Data, int Length)
uint16_t CompositionPageId(int i) const
uchar * GetBuffer(int &OutLength)
const int * Spids(void) const
uchar TsContinuityCounter(const uchar *p)
void PutTs(const uchar *Data, int Length)
Puts the payload data of the single TS packet at Data into the converter.
ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader=NULL)
int MakeCRC(uchar *Target, const uchar *Data, int Length)
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId)
void GeneratePmtPid(const cChannel *Channel)
Generates a PMT pid that doesn't collide with any of the actual pids of the Channel.
void TsSetDts(uchar *p, int l, int64_t Dts)
uchar subtitlingTypes[MAXSPIDS]
void SetByte(uchar Byte, int Index)
Sets the TS data byte at the given Index to the value Byte.
void TsHidePayload(uchar *p)
uint16_t compositionPageIds[MAXSPIDS]
eNaluFillState NaluFillState
void TsDump(const char *Name, const u_char *Data, int Length)
int pmtPids[MAX_PMT_PIDS+1]
void GeneratePat(void)
Generates a PAT section for later use with GetPat().
void ParsePmt(const uchar *Data, int Length)
Parses the PMT data from the single TS packet in Data.
void IncEsInfoLength(int Length)
void TsSetContinuityCounter(uchar *p, uchar Counter)
cPatPmtParser(bool UpdatePrimaryDevice=false)
cPatPmtGenerator(const cChannel *Channel=NULL)
bool SkipBytes(int Bytes)
Skips the given number of bytes in the payload and returns true if there is still data left to read.
long long int DroppedPackets
void TsSetPcr(uchar *p, int64_t Pcr)
int MakeAC3Descriptor(uchar *Target, uchar Type)
void Reset(void)
Resets the converter.
#define TS_PAYLOAD_EXISTS
bool TsSetPayload(const uchar *p)
uchar tempBuffer[TS_SIZE]
uchar pmt[MAX_PMT_TS][TS_SIZE]
int MakeStream(uchar *Target, uchar Type, int Pid)
void SetRepeatLast(void)
Makes the next call to GetPes() return exactly the same data as the last one (provided there was no c...
const int * Dpids(void) const
char slangs[MAXSPIDS][MAXLANGCODE2]
int64_t PesGetPts(const uchar *p)
int64_t TsGetDts(const uchar *p, int l)
int PesPayloadOffset(const uchar *p)
void PesSetPts(uchar *p, int64_t Pts)
const uchar * GetPes(int &Length)
Gets a pointer to the complete PES packet, or NULL if the packet is not complete yet.
bool SkipPesHeader(void)
Skips all bytes belonging to the PES header of the payload.
bool PesHasPts(const uchar *p)
void TsSetPts(uchar *p, int l, int64_t Pts)
void PutBuffer(uchar *Data, int Length)