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
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
57 #define PTSTICKS 90000
59 #define MAX33BIT 0x00000001FFFFFFFFLL
60 #define MAX27MHZ ((MAX33BIT + 1) * PCRFACTOR - 1)
128 return ((((int64_t)p[ 6]) << 25) |
129 (((int64_t)p[ 7]) << 17) |
130 (((int64_t)p[ 8]) << 9) |
131 (((int64_t)p[ 9]) << 1) |
133 (((((int)p[10]) & 0x01) << 8) |
149 #define TS_SYNC(Data, Length) (*Data == TS_SYNC_BYTE ? 0 : TsSync(Data, Length, __FILE__, __FUNCTION__, __LINE__))
150 int TsSync(
const uchar *Data,
int Length,
const char *File = NULL,
const char *Function = NULL,
int Line = 0);
175 return 6 + p[4] * 256 + p[5];
185 return (p[7] & 0x80) && p[8] >= 5;
190 return (p[7] & 0x40) && p[8] >= 10;
195 return ((((int64_t)p[ 9]) & 0x0E) << 29) |
196 (( (int64_t)p[10]) << 22) |
197 ((((int64_t)p[11]) & 0xFE) << 14) |
198 (( (int64_t)p[12]) << 7) |
199 ((((int64_t)p[13]) & 0xFE) >> 1);
204 return ((((int64_t)p[14]) & 0x0E) << 29) |
205 (( (int64_t)p[15]) << 22) |
206 ((((int64_t)p[16]) & 0xFE) << 14) |
207 (( (int64_t)p[17]) << 7) |
208 ((((int64_t)p[18]) & 0xFE) >> 1);
216 inline int64_t
PtsAdd(int64_t Pts1, int64_t Pts2) {
return (Pts1 + Pts2) &
MAX33BIT; }
218 int64_t
PtsDiff(int64_t Pts1, int64_t Pts2);
241 void Setup(
uchar *Data,
int Length,
int Pid = -1);
283 bool Find(uint32_t Code);
295 #define MAX_SECTION_SIZE 4096
296 #define MAX_PMT_TS (MAX_SECTION_SIZE / TS_SIZE + 1)
351 #define MAX_PMT_PIDS 32
377 int SectionLength(
const uchar *Data,
int Length) {
return (Length >= 3) ? ((int(Data[1]) & 0x0F) << 8)| Data[2] : 0; }
397 bool GetVersions(
int &PatVersion,
int &PmtVersion)
const;
437 uint16_t
YMDtoMJD(
int Y,
int M,
int D);
498 void TsDump(
const char *Name,
const u_char *Data,
int Length);
499 void PesDump(
const char *Name,
const u_char *Data,
int Length);
503 #define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 100
553 void SetPid(
int Pid,
int Type);
uchar * AddParentalRatingDescriptor(uchar *p, uchar ParentalRating=0)
uint16_t YMDtoMJD(int Y, int M, int D)
uchar * Generate(int Sid)
bool Synced(void)
Returns true if the frame detector has synced on the data stream.
bool IndependentFrame(void)
Returns true if a new frame was detected and this is an independent frame (i.e.
double FramesPerSecond(void)
Returns the number of frames per second, or 0 if this information is not available.
uint32_t ptsValues[MaxPtsValues]
uint16_t FrameWidth(void)
Returns the frame width, or 0 if this information is not available.
eScanType ScanType(void)
Returns the scan type, or stUnknown if this information is not available.
uint16_t FrameHeight(void)
Returns the frame height, or 0 if this information is not available.
cFrameDetector(int Pid=0, int Type=0)
Sets up a frame detector for the given Pid and stream Type.
int Analyze(const uchar *Data, int Length)
Analyzes the TS packets pointed to by Data.
void SetPid(int Pid, int Type)
Sets the Pid and stream Type to detect frames for.
bool NewFrame(void)
Returns true if the data given to the last call to Analyze() started a new frame.
eAspectRatio AspectRatio(void)
Returns the aspect ratio, or arUnknown if this information is not available.
int MakeCRC(uchar *Target, const uchar *Data, int Length)
uchar * GetPmt(int &Index)
Returns a pointer to the Index'th TS packet of the PMT section.
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
void IncEsInfoLength(int Length)
void IncCounter(int &Counter, uchar *TsPacket)
cPatPmtGenerator(const cChannel *Channel=NULL)
void SetVersions(int PatVersion, int PmtVersion)
Sets the version numbers for the generated PAT and PMT, in case this generator is used to,...
int MakeAC3Descriptor(uchar *Target, uchar Type)
void GeneratePat(void)
Generates a PAT section for later use with GetPat().
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
uchar pmt[MAX_PMT_TS][TS_SIZE]
int MakeLanguageDescriptor(uchar *Target, const char *Language)
void GeneratePmt(const cChannel *Channel)
Generates a PMT section for the given Channel, for later use with GetPmt().
void GeneratePmtPid(const cChannel *Channel)
Generates a PMT pid that doesn't collide with any of the actual pids of the Channel.
int MakeStream(uchar *Target, uchar Type, int Pid)
int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId)
void IncVersion(int &Version)
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...
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...
uchar pmt[MAX_SECTION_SIZE]
cPatPmtParser(bool UpdatePrimaryDevice=false)
void Reset(void)
Resets the parser.
const int * Dpids(void) const
void ParsePat(const uchar *Data, int Length)
Parses the PAT data from the single TS packet in Data.
char dlangs[MAXDPIDS][MAXLANGCODE2]
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 char * Alang(int i) const
int pmtPids[MAX_PMT_PIDS+1]
uchar subtitlingTypes[MAXSPIDS]
const int * Spids(void) const
const char * Slang(int i) const
uint16_t ancillaryPageIds[MAXSPIDS]
int SectionLength(const uchar *Data, int Length)
uint16_t CompositionPageId(int i) const
const char * Dlang(int i) const
void ParsePmt(const uchar *Data, int Length)
Parses the PMT data from the single TS packet in Data.
bool Completed(void)
Returns true if the PMT has been completely parsed.
bool IsPmtPid(int Pid) const
Returns true if Pid the one of the PMT pids as defined by the current PAT.
uchar SubtitlingType(int i) const
uint16_t AncillaryPageId(int i) const
const int * Apids(void) const
uint16_t compositionPageIds[MAXSPIDS]
char alangs[MAXAPIDS][MAXLANGCODE2]
int Ppid(void) const
Returns the PCR pid as defined by the current PMT, or 0 if no PCR pid has been detected,...
int Vpid(void) const
Returns the video pid as defined by the current PMT, or 0 if no video pid has been detected,...
char slangs[MAXSPIDS][MAXLANGCODE2]
static void SetBrokenLink(uchar *Data, int Length)
bool AtPayloadStart(void)
Returns true if this payload handler is currently pointing to the first byte of a TS packet that star...
int Used(void)
Returns the number of raw bytes that have already been used (e.g.
bool Eof(void) const
Returns true if all available bytes of the TS payload have been processed.
void SetByte(uchar Byte, int Index)
Sets the TS data byte at the given Index to the value Byte.
uchar GetByte(void)
Gets the next byte of the TS payload, skipping any intermediate TS header data.
bool AtTsStart(void)
Returns true if this payload handler is currently pointing to first byte of a TS packet.
int Available(void)
Returns the number of raw bytes (including any TS headers) still available in the TS payload handler.
int GetLastIndex(void)
Returns the index into the TS data of the payload byte that has most recently been read.
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...
bool SkipPesHeader(void)
Skips all bytes belonging to the PES header of the payload.
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...
bool Find(uint32_t Code)
Searches for the four byte sequence given in Code and returns true if it was found within the payload...
bool SkipBytes(int Bytes)
Skips the given number of bytes in the payload and returns true if there is still data left to read.
void PutTs(const uchar *Data, int Length)
Puts the payload data of the single TS packet at Data into the converter.
void SetRepeatLast(void)
Makes the next call to GetPes() return exactly the same data as the last one (provided there was no c...
const uchar * GetPes(int &Length)
Gets a pointer to the complete PES packet, or NULL if the packet is not complete yet.
void Reset(void)
Resets the converter.
void TsSetPcr(uchar *p, int64_t Pcr)
const char * AspectRatioTexts[]
bool TsError(const uchar *p)
int TsPid(const uchar *p)
void PesDump(const char *Name, const u_char *Data, int Length)
#define TS_SCRAMBLING_CONTROL
bool TsHasPayload(const uchar *p)
int64_t PtsDiff(int64_t Pts1, int64_t Pts2)
Returns the difference between two PTS values.
int PesPayloadOffset(const uchar *p)
const char * ScanTypeChars
bool TsIsScrambled(const uchar *p)
void TsHidePayload(uchar *p)
void TsSetContinuityCounter(uchar *p, uchar Counter)
uchar TsContinuityCounter(const uchar *p)
int TsGetPayload(const uchar **p)
#define TS_PAYLOAD_EXISTS
bool PesHasPts(const uchar *p)
bool PesLongEnough(int Length)
void TsSetPid(uchar *p, int Pid)
int TsSync(const uchar *Data, int Length, const char *File=NULL, const char *Function=NULL, int Line=0)
int64_t PesGetDts(const uchar *p)
#define TS_ADAPT_FIELD_EXISTS
int64_t PesGetPts(const uchar *p)
bool TsPayloadStart(const uchar *p)
int TsPayloadOffset(const uchar *p)
void PesSetDts(uchar *p, int64_t Dts)
int64_t TsGetPcr(const uchar *p)
bool PesHasDts(const uchar *p)
bool PesHasLength(const uchar *p)
bool TsHasAdaptationField(const uchar *p)
int64_t TsGetDts(const uchar *p, int l)
void TsSetDts(uchar *p, int l, int64_t Dts)
void TsSetPts(uchar *p, int l, int64_t Pts)
ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader=NULL)
int PesLength(const uchar *p)
void PesSetPts(uchar *p, int64_t Pts)
int64_t TsGetPts(const uchar *p, int l)
void BlockDump(const char *Name, const u_char *Data, int Length)
void TsDump(const char *Name, const u_char *Data, int Length)
int64_t PtsAdd(int64_t Pts1, int64_t Pts2)
Adds the given PTS values, taking into account the 33bit wrap around.