vdr 2.8.3
remux.h
Go to the documentation of this file.
1/*
2 * remux.h: Tools for detecting frames and handling PAT/PMT
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * $Id: remux.h 5.13 2026/07/19 16:54:12 kls Exp $
8 */
9
10#ifndef __REMUX_H
11#define __REMUX_H
12
13#include "channels.h"
14#include "tools.h"
15
22
23ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader = NULL);
24
25class cRemux {
26public:
27 static void SetBrokenLink(uchar *Data, int Length);
28 };
29
30// Some TS handling tools.
31// The following functions all take a pointer to one complete TS packet.
32
33#define TS_SYNC_BYTE 0x47
34#define TS_SIZE 188
35#define TS_ERROR 0x80
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
51
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
56
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
61
62inline bool TsHasPayload(const uchar *p)
63{
64 return p[3] & TS_PAYLOAD_EXISTS;
65}
66
67inline bool TsHasAdaptationField(const uchar *p)
68{
69 return p[3] & TS_ADAPT_FIELD_EXISTS;
70}
71
72inline bool TsPayloadStart(const uchar *p)
73{
74 return p[1] & TS_PAYLOAD_START;
75}
76
77inline bool TsError(const uchar *p)
78{
79 return p[1] & TS_ERROR;
80}
81
82inline int TsPid(const uchar *p)
83{
84 return (p[1] & TS_PID_MASK_HI) * 256 + p[2];
85}
86
87inline void TsSetPid(uchar *p, int Pid)
88{
89 p[1] = (p[1] & ~TS_PID_MASK_HI) | ((Pid >> 8) & TS_PID_MASK_HI);
90 p[2] = Pid & 0x00FF;
91}
92
93inline bool TsIsScrambled(const uchar *p)
94{
95 return p[3] & TS_SCRAMBLING_CONTROL;
96}
97
99{
100 return p[3] & TS_CONT_CNT_MASK;
101}
102
103inline void TsSetContinuityCounter(uchar *p, uchar Counter)
104{
105 p[3] = (p[3] & ~TS_CONT_CNT_MASK) | (Counter & TS_CONT_CNT_MASK);
106}
107
108inline int TsPayloadOffset(const uchar *p)
109{
110 int o = TsHasAdaptationField(p) ? p[4] + 5 : 4;
111 return o <= TS_SIZE ? o : TS_SIZE;
112}
113
114inline int TsGetPayload(const uchar **p)
115{
116 if (TsHasPayload(*p)) {
117 int o = TsPayloadOffset(*p);
118 *p += o;
119 return TS_SIZE - o;
120 }
121 return 0;
122}
123
124inline int64_t TsGetPcr(const uchar *p)
125{
126 if (TsHasAdaptationField(p)) {
127 if (p[4] >= 7 && (p[5] & TS_ADAPT_PCR)) {
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) |
132 (((int64_t)p[10]) >> 7)) * PCRFACTOR +
133 (((((int)p[10]) & 0x01) << 8) |
134 ( ((int)p[11])));
135 }
136 }
137 return -1;
138}
139
140void TsHidePayload(uchar *p);
141void TsSetPcr(uchar *p, int64_t Pcr);
142
143// Helper macro and function to quickly check whether Data points to the beginning
144// of a TS packet. The return value is the number of bytes that need to be skipped
145// to synchronize on the next TS packet (zero if already sync'd). TsSync() can be
146// called directly, the macro just performs the initial check inline and adds some
147// debug information for logging.
148
149#define TS_SYNC(Data, Length) (*Data == TS_SYNC_BYTE ? 0 : TsSync(Data, Length, __FILE__, __FUNCTION__, __LINE__))
150int TsSync(const uchar *Data, int Length, const char *File = NULL, const char *Function = NULL, int Line = 0);
151
152// The following functions all take a pointer to a sequence of complete TS packets.
153
154int64_t TsGetPts(const uchar *p, int l, int Pid = -1);
155int64_t TsGetDts(const uchar *p, int l);
156void TsSetPts(uchar *p, int l, int64_t Pts);
157void TsSetDts(uchar *p, int l, int64_t Dts);
158
159// Some PES handling tools:
160// The following functions that take a pointer to PES data all assume that
161// there is enough data so that PesLongEnough() returns true.
162
163inline bool PesLongEnough(int Length)
164{
165 return Length >= 6;
166}
167
168inline bool PesHasLength(const uchar *p)
169{
170 return p[4] | p[5];
171}
172
173inline int PesLength(const uchar *p)
174{
175 return 6 + p[4] * 256 + p[5];
176}
177
178inline int PesPayloadOffset(const uchar *p)
179{
180 return 9 + p[8];
181}
182
183inline bool PesHasPts(const uchar *p)
184{
185 return (p[7] & 0x80) && p[8] >= 5;
186}
187
188inline bool PesHasDts(const uchar *p)
189{
190 return (p[7] & 0x40) && p[8] >= 10;
191}
192
193inline int64_t PesGetPts(const uchar *p)
194{
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);
200}
201
202inline int64_t PesGetDts(const uchar *p)
203{
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);
209}
210
211void PesSetPts(uchar *p, int64_t Pts);
212void PesSetDts(uchar *p, int64_t Dts);
213
214// PTS handling:
215
216inline int64_t PtsAdd(int64_t Pts1, int64_t Pts2) { return (Pts1 + Pts2) & MAX33BIT; }
218int64_t PtsDiff(int64_t Pts1, int64_t Pts2);
223
224// A transparent TS payload handler:
225
227private:
230 int pid;
231 int index; // points to the next byte to process
232 int numPacketsPid; // the number of TS packets with the given PID (for statistical purposes)
233 int numPacketsOther; // the number of TS packets with other PIDs (for statistical purposes)
234 uchar SetEof(void);
235protected:
236 void Reset(void);
237public:
238 cTsPayload(void);
239 cTsPayload(uchar *Data, int Length, int Pid = -1);
241 void Setup(uchar *Data, int Length, int Pid = -1);
249 bool AtTsStart(void) { return index < length && (index % TS_SIZE) == 0; }
252 bool AtPayloadStart(void) { return AtTsStart() && TsPayloadStart(data + index) && TsPid(data + index) == pid; }
255 int Available(void) { return length - index; }
258 int Used(void) { return (index + TS_SIZE - 1) / TS_SIZE * TS_SIZE; }
262 bool Eof(void) const { return index >= length; }
264 void Statistics(void) const;
268 uchar GetByte(void);
270 bool SkipBytes(int Bytes);
273 bool SkipPesHeader(void);
275 int GetLastIndex(void);
278 void SetByte(uchar Byte, int Index);
283 bool Find(uint32_t Code);
291 };
292
293// PAT/PMT Generator:
294
295#define MAX_SECTION_SIZE 4096 // maximum size of an SI section
296#define MAX_PMT_TS (MAX_SECTION_SIZE / TS_SIZE + 1)
297
299private:
300 uchar pat[TS_SIZE]; // the PAT always fits into a single TS packet
301 uchar pmt[MAX_PMT_TS][TS_SIZE]; // the PMT may well extend over several TS packets
309 void IncCounter(int &Counter, uchar *TsPacket);
310 void IncVersion(int &Version);
311 void IncEsInfoLength(int Length);
312protected:
313 int MakeStream(uchar *Target, uchar Type, int Pid);
314 int MakeAC3Descriptor(uchar *Target, uchar Type);
315 int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId);
316 int MakeLanguageDescriptor(uchar *Target, const char *Language);
317 int MakeCRC(uchar *Target, const uchar *Data, int Length);
318 void GeneratePmtPid(int Vpid, int Ppid, int Tpid, const int *Apids, const int *Dpids, const int *Spids);
320 void GeneratePat(void);
322public:
323 cPatPmtGenerator(const cChannel *Channel = NULL);
324 void SetVersions(int PatVersion, int PmtVersion);
333 void SetPids(int Vpid, int Vtype, int Ppid, int Tpid, const int *Apids, const int *Atypes, const char Alangs[][MAXLANGCODE2], const int *Dpids, const int *Dtypes, const char Dlangs[][MAXLANGCODE2], const int *Spids, const uchar *Stypes, const char Slangs[][MAXLANGCODE2], const uint16_t *CompositionPageIds, const uint16_t *AncillaryPageIds);
335 void SetChannel(const cChannel *Channel);
337 uchar *GetPat(void);
340 uchar *GetPmt(int &Index);
345 int GetPatPmtSize(void);
347 int GetPatPmt(uchar *Dest, int Size);
351 };
352
353// PAT/PMT Parser:
354
355#define MAX_PMT_PIDS 32
356
358private:
363 int pmtPids[MAX_PMT_PIDS + 1]; // list is zero-terminated
364 int vpid;
365 int ppid;
366 int vtype;
367 int apids[MAXAPIDS + 1]; // list is zero-terminated
368 int atypes[MAXAPIDS + 1]; // list is zero-terminated
370 int dpids[MAXDPIDS + 1]; // list is zero-terminated
371 int dtypes[MAXDPIDS + 1]; // list is zero-terminated
373 int spids[MAXSPIDS + 1]; // list is zero-terminated
380protected:
381 int SectionLength(const uchar *Data, int Length) { return (Length >= 3) ? ((int(Data[1]) & 0x0F) << 8)| Data[2] : 0; }
382public:
383 cPatPmtParser(bool UpdatePrimaryDevice = false);
384 void Reset(void);
387 void ParsePat(const uchar *Data, int Length);
390 void ParsePmt(const uchar *Data, int Length);
397 bool ParsePatPmt(const uchar *Data, int Length);
401 bool GetVersions(int &PatVersion, int &PmtVersion) const;
404 bool IsPmtPid(int Pid) const { for (int i = 0; pmtPids[i]; i++) if (pmtPids[i] == Pid) return true; return false; }
407 int Vpid(void) const { return vpid; }
410 int Ppid(void) const { return ppid; }
413 int Vtype(void) const { return vtype; }
416 bool Completed(void) { return completed; }
418 const int *Apids(void) const { return apids; }
419 const int *Dpids(void) const { return dpids; }
420 const int *Spids(void) const { return spids; }
421 int Apid(int i) const { return (0 <= i && i < MAXAPIDS) ? apids[i] : 0; }
422 int Dpid(int i) const { return (0 <= i && i < MAXDPIDS) ? dpids[i] : 0; }
423 int Spid(int i) const { return (0 <= i && i < MAXSPIDS) ? spids[i] : 0; }
424 int Atype(int i) const { return (0 <= i && i < MAXAPIDS) ? atypes[i] : 0; }
425 int Dtype(int i) const { return (0 <= i && i < MAXDPIDS) ? dtypes[i] : 0; }
426 const char *Alang(int i) const { return (0 <= i && i < MAXAPIDS) ? alangs[i] : ""; }
427 const char *Dlang(int i) const { return (0 <= i && i < MAXDPIDS) ? dlangs[i] : ""; }
428 const char *Slang(int i) const { return (0 <= i && i < MAXSPIDS) ? slangs[i] : ""; }
429 uchar SubtitlingType(int i) const { return (0 <= i && i < MAXSPIDS) ? subtitlingTypes[i] : uchar(0); }
430 uint16_t CompositionPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? compositionPageIds[i] : uint16_t(0); }
431 uint16_t AncillaryPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? ancillaryPageIds[i] : uint16_t(0); }
432 };
433
434// EIT Generator:
435
437private:
441 uint16_t YMDtoMJD(int Y, int M, int D);
442 uchar *AddParentalRatingDescriptor(uchar *p, uchar ParentalRating = 0);
443public:
444 cEitGenerator(int Sid = 0);
445 uchar *Generate(int Sid);
446 uchar *Data(void) { return eit; }
447 int Length(void) { return sizeof(eit); }
448 };
449
450// TS to PES converter:
451// Puts together the payload of several TS packets that form one PES
452// packet.
453
454class cTsToPes {
455private:
457 int size;
463public:
464 cTsToPes(void);
465 ~cTsToPes();
466 void PutTs(const uchar *Data, int Length);
476 const uchar *GetPes(int &Length);
490 void SetRepeatLast(void);
493 void Reset(void);
497 };
498
499// Some helper functions for debugging:
500
501void BlockDump(const char *Name, const u_char *Data, int Length);
502void TsDump(const char *Name, const u_char *Data, int Length);
503void PesDump(const char *Name, const u_char *Data, int Length);
504
505// Frame detector:
506
507#define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 100
508
509class cFrameParser;
510
517
526
527extern const char *ScanTypeChars;
528extern const char *AspectRatioTexts[];
529
530class cTsChecker;
531class cPtsChecker;
532
534private:
537public:
538 cFrameChecker(void);
540 void Reset(void);
541 bool Check(const uchar *Data, int Length, bool Independent, bool &Errors, bool &Missing, bool Final, int Pid);
549 int TotalErrors(void);
552 };
553
555private:
556 enum { MaxPtsValues = 150 };
557 int pid;
558 int type;
559 bool synced;
562 uint32_t ptsValues[MaxPtsValues]; // 32 bit is enough - we only need the delta
567 uint16_t frameWidth;
568 uint16_t frameHeight;
572 int framesPerPayloadUnit; // Some broadcasters send one frame per payload unit (== 1),
573 // while others put an entire GOP into one payload unit (> 1).
581public:
582 cFrameDetector(int Pid = 0, int Type = 0);
587 void SetPid(int Pid, int Type);
589 [[deprecated("use SetLastPts() instead")]] void SetMissing(void) {}
590 void SetLastPts(int64_t LastPts);
593 int Errors(bool *PreviousErrors = NULL, bool *MissingFrames = NULL);
598 int Analyze(const uchar *Data, int Length, bool ErrorCheck = true);
607 bool Synced(void) { return synced; }
609 [[deprecated("use NewFrame(bool&, bool&) instead")]] bool NewFrame(int *PreviousErrors = NULL, int *MissingFrames = NULL);
610 bool NewFrame(bool &PreviousErrors, bool &MissingFrames);
617 bool IndependentFrame(void) { return independentFrame; }
621 double FramesPerSecond(void) { return framesPerSecond; }
624 uint16_t FrameWidth(void) { return frameWidth; }
626 uint16_t FrameHeight(void) { return frameHeight; }
628 eScanType ScanType(void) { return scanType; }
632 };
633
634#endif //__REMUX_H
#define MAXLANGCODE2
Definition channels.h:37
#define MAXDPIDS
Definition channels.h:32
#define MAXAPIDS
Definition channels.h:31
#define MAXSPIDS
Definition channels.h:33
uchar eit[TS_SIZE]
Definition remux.h:438
cEitGenerator(int Sid=0)
Definition remux.c:968
int counter
Definition remux.h:439
uchar * Data(void)
Definition remux.h:446
int Length(void)
Definition remux.h:447
uchar * AddParentalRatingDescriptor(uchar *p, uchar ParentalRating=0)
Definition remux.c:982
uint16_t YMDtoMJD(int Y, int M, int D)
Definition remux.c:976
uchar * Generate(int Sid)
Definition remux.c:993
int version
Definition remux.h:440
void Reset(void)
Definition remux.c:2166
cTsChecker * tsChecker
Definition remux.h:535
cFrameChecker(void)
Definition remux.c:2154
cPtsChecker * ptsChecker
Definition remux.h:536
int TotalErrors(void)
Returns the total number of all errors and missing frames detected in the data given to the calls to ...
Definition remux.c:2182
bool Check(const uchar *Data, int Length, bool Independent, bool &Errors, bool &Missing, bool Final, int Pid)
Check Length bytes of the given Data (which must be a complete frame), with Independent telling wheth...
Definition remux.c:2171
int previousErrors
Definition remux.h:576
bool Synced(void)
Returns true if the frame detector has synced on the data stream.
Definition remux.h:607
bool IndependentFrame(void)
Returns true if a new frame was detected and this is an independent frame (i.e.
Definition remux.h:617
double FramesPerSecond(void)
Returns the number of frames per second, or 0 if this information is not available.
Definition remux.h:621
uint32_t ptsValues[MaxPtsValues]
Definition remux.h:562
uint16_t FrameWidth(void)
Returns the frame width, or 0 if this information is not available.
Definition remux.h:624
bool synced
Definition remux.h:559
uint16_t frameHeight
Definition remux.h:568
int Errors(bool *PreviousErrors=NULL, bool *MissingFrames=NULL)
Returns the total number of errors so far.
Definition remux.c:2260
cTsChecker * tsChecker
Definition remux.h:579
uint16_t frameWidth
Definition remux.h:567
bool scanning
Definition remux.h:574
eScanType ScanType(void)
Returns the scan type, or stUnknown if this information is not available.
Definition remux.h:628
int framesPerPayloadUnit
Definition remux.h:572
bool NewFrame(int *PreviousErrors=NULL, int *MissingFrames=NULL)
Definition remux.c:2271
bool firstIframeSeen
Definition remux.h:575
int Analyze(const uchar *Data, int Length, bool ErrorCheck=true)
Analyzes the TS packets pointed to by Data.
Definition remux.c:2292
double framesPerSecond
Definition remux.h:566
int framesInPayloadUnit
Definition remux.h:571
int numIFrames
Definition remux.h:564
cPtsChecker * ptsChecker
Definition remux.h:580
uint16_t FrameHeight(void)
Returns the frame height, or 0 if this information is not available.
Definition remux.h:626
bool independentFrame
Definition remux.h:561
cFrameDetector(int Pid=0, int Type=0)
Sets up a frame detector for the given Pid and stream Type.
Definition remux.c:2199
eScanType scanType
Definition remux.h:569
int missingFrames
Definition remux.h:577
void SetLastPts(int64_t LastPts)
If this is a resumed recording, call this function with the last PTS of the previous recording.
Definition remux.c:2254
void SetMissing(void)
Definition remux.h:589
bool newFrame
Definition remux.h:560
cFrameParser * parser
Definition remux.h:578
int numPtsValues
Definition remux.h:563
bool isVideo
Definition remux.h:565
void SetPid(int Pid, int Type)
Sets the Pid and stream Type to detect frames for.
Definition remux.c:2234
eAspectRatio aspectRatio
Definition remux.h:570
eAspectRatio AspectRatio(void)
Returns the aspect ratio, or arUnknown if this information is not available.
Definition remux.h:630
int MakeCRC(uchar *Target, const uchar *Data, int Length)
Definition remux.c:456
uchar * GetPmt(int &Index)
Returns a pointer to the Index'th TS packet of the PMT section.
Definition remux.c:599
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
Definition remux.c:587
void IncEsInfoLength(int Length)
Definition remux.c:390
void IncCounter(int &Counter, uchar *TsPacket)
Definition remux.c:377
cPatPmtGenerator(const cChannel *Channel=NULL)
Definition remux.c:367
void SetVersions(int PatVersion, int PmtVersion)
Sets the version numbers for the generated PAT and PMT, in case this generator is used to,...
Definition remux.c:581
int numPmtPackets
Definition remux.h:302
uchar * esInfoLength
Definition remux.h:308
uchar pat[TS_SIZE]
Definition remux.h:300
int MakeAC3Descriptor(uchar *Target, uchar Type)
Definition remux.c:411
void GeneratePat(void)
Generates a PAT section for later use with GetPat().
Definition remux.c:486
int GetPatPmtSize(void)
Returns the combined size of PAT and all PMT packets.
Definition remux.c:608
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
Definition remux.c:593
uchar pmt[MAX_PMT_TS][TS_SIZE]
Definition remux.h:301
int MakeLanguageDescriptor(uchar *Target, const char *Language)
Definition remux.c:437
void SetPids(int Vpid, int Vtype, int Ppid, int Tpid, const int *Apids, const int *Atypes, const char Alangs[][MAXLANGCODE2], const int *Dpids, const int *Dtypes, const char Dlangs[][MAXLANGCODE2], const int *Spids, const uchar *Stypes, const char Slangs[][MAXLANGCODE2], const uint16_t *CompositionPageIds, const uint16_t *AncillaryPageIds)
Sets the PIDs this PAT/PMT shall contain.
Definition remux.c:515
int GetPatPmt(uchar *Dest, int Size)
Writes the PAT and all PMT packets to Dest.
Definition remux.c:613
int MakeStream(uchar *Target, uchar Type, int Pid)
Definition remux.c:399
void GeneratePmtPid(int Vpid, int Ppid, int Tpid, const int *Apids, const int *Dpids, const int *Spids)
Generates a PMT pid that doesn't collide with any of the given pids.
Definition remux.c:471
int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId)
Definition remux.c:420
void IncVersion(int &Version)
Definition remux.c:384
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...
Definition remux.c:959
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...
Definition remux.h:413
int dpids[MAXDPIDS+1]
Definition remux.h:370
uchar pmt[MAX_SECTION_SIZE]
Definition remux.h:359
int apids[MAXAPIDS+1]
Definition remux.h:367
cPatPmtParser(bool UpdatePrimaryDevice=false)
Definition remux.c:632
void Reset(void)
Resets the parser.
Definition remux.c:638
int Dtype(int i) const
Definition remux.h:425
void ParsePat(const uchar *Data, int Length)
Parses the PAT data from the single TS packet in Data.
Definition remux.c:648
int pmtSize
Definition remux.h:360
char dlangs[MAXDPIDS][MAXLANGCODE2]
Definition remux.h:372
bool ParsePatPmt(const uchar *Data, int Length)
Parses the given Data (which may consist of several TS packets, typically an entire frame) and extrac...
Definition remux.c:940
int patVersion
Definition remux.h:361
const int * Spids(void) const
Definition remux.h:420
int pmtPids[MAX_PMT_PIDS+1]
Definition remux.h:363
uchar subtitlingTypes[MAXSPIDS]
Definition remux.h:375
int dtypes[MAXDPIDS+1]
Definition remux.h:371
int Dpid(int i) const
Definition remux.h:422
uint16_t ancillaryPageIds[MAXSPIDS]
Definition remux.h:377
const int * Dpids(void) const
Definition remux.h:419
int SectionLength(const uchar *Data, int Length)
Definition remux.h:381
uint16_t CompositionPageId(int i) const
Definition remux.h:430
const int * Apids(void) const
Definition remux.h:418
int Apid(int i) const
Definition remux.h:421
void ParsePmt(const uchar *Data, int Length)
Parses the PMT data from the single TS packet in Data.
Definition remux.c:680
bool completed
Definition remux.h:379
bool Completed(void)
Returns true if the PMT has been completely parsed.
Definition remux.h:416
bool IsPmtPid(int Pid) const
Returns true if Pid the one of the PMT pids as defined by the current PAT.
Definition remux.h:404
uchar SubtitlingType(int i) const
Definition remux.h:429
uint16_t AncillaryPageId(int i) const
Definition remux.h:431
int Spid(int i) const
Definition remux.h:423
uint16_t compositionPageIds[MAXSPIDS]
Definition remux.h:376
char alangs[MAXAPIDS][MAXLANGCODE2]
Definition remux.h:369
int spids[MAXSPIDS+1]
Definition remux.h:373
int Atype(int i) const
Definition remux.h:424
const char * Dlang(int i) const
Definition remux.h:427
const char * Slang(int i) const
Definition remux.h:428
const char * Alang(int i) const
Definition remux.h:426
int Ppid(void) const
Returns the PCR pid as defined by the current PMT, or 0 if no PCR pid has been detected,...
Definition remux.h:410
int pmtVersion
Definition remux.h:362
bool updatePrimaryDevice
Definition remux.h:378
int Vpid(void) const
Returns the video pid as defined by the current PMT, or 0 if no video pid has been detected,...
Definition remux.h:407
char slangs[MAXSPIDS][MAXLANGCODE2]
Definition remux.h:374
int atypes[MAXAPIDS+1]
Definition remux.h:368
Definition remux.h:25
static void SetBrokenLink(uchar *Data, int Length)
Definition remux.c:102
int numPacketsPid
Definition remux.h:232
int pid
Definition remux.h:230
cTsPayload(void)
Definition remux.c:248
bool AtPayloadStart(void)
Returns true if this payload handler is currently pointing to the first byte of a TS packet that star...
Definition remux.h:252
int Used(void)
Returns the number of raw bytes that have already been used (e.g.
Definition remux.h:258
bool Eof(void) const
Returns true if all available bytes of the TS payload have been processed.
Definition remux.h:262
void SetByte(uchar Byte, int Index)
Sets the TS data byte at the given Index to the value Byte.
Definition remux.c:332
uchar GetByte(void)
Gets the next byte of the TS payload, skipping any intermediate TS header data.
Definition remux.c:282
bool AtTsStart(void)
Returns true if this payload handler is currently pointing to first byte of a TS packet.
Definition remux.h:249
int Available(void)
Returns the number of raw bytes (including any TS headers) still available in the TS payload handler.
Definition remux.h:255
int GetLastIndex(void)
Returns the index into the TS data of the payload byte that has most recently been read.
Definition remux.c:327
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...
Definition remux.c:274
bool SkipPesHeader(void)
Skips all bytes belonging to the PES header of the payload.
Definition remux.c:322
int index
Definition remux.h:231
int numPacketsOther
Definition remux.h:233
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...
Definition remux.c:355
uchar SetEof(void)
Definition remux.c:261
int length
Definition remux.h:229
bool Find(uint32_t Code)
Searches for the four byte sequence given in Code and returns true if it was found within the payload...
Definition remux.c:338
void Reset(void)
Definition remux.c:267
uchar * data
Definition remux.h:228
bool SkipBytes(int Bytes)
Skips the given number of bytes in the payload and returns true if there is still data left to read.
Definition remux.c:315
int lastLength
Definition remux.h:461
bool repeatLast
Definition remux.h:462
uchar * lastData
Definition remux.h:460
uchar * data
Definition remux.h:456
void PutTs(const uchar *Data, int Length)
Puts the payload data of the single TS packet at Data into the converter.
Definition remux.c:1067
void SetRepeatLast(void)
Makes the next call to GetPes() return exactly the same data as the last one (provided there was no c...
Definition remux.c:1144
const uchar * GetPes(int &Length)
Gets a pointer to the complete PES packet, or NULL if the packet is not complete yet.
Definition remux.c:1096
cTsToPes(void)
Definition remux.c:1055
int length
Definition remux.h:458
void Reset(void)
Resets the converter.
Definition remux.c:1149
int offset
Definition remux.h:459
int size
Definition remux.h:457
void TsSetPcr(uchar *p, int64_t Pcr)
Definition remux.c:131
const char * AspectRatioTexts[]
Definition remux.c:2190
void PesDump(const char *Name, const u_char *Data, int Length)
Definition remux.c:1185
int64_t PtsDiff(int64_t Pts1, int64_t Pts2)
Returns the difference between two PTS values.
Definition remux.c:236
const char * ScanTypeChars
Definition remux.c:2189
void TsHidePayload(uchar *p)
Definition remux.c:121
void PesSetDts(uchar *p, int64_t Dts)
Definition remux.c:227
int64_t TsGetDts(const uchar *p, int l)
Definition remux.c:175
void TsSetDts(uchar *p, int l, int64_t Dts)
Definition remux.c:202
void TsSetPts(uchar *p, int l, int64_t Pts)
Definition remux.c:188
ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader)
Definition remux.c:32
void PesSetPts(uchar *p, int64_t Pts)
Definition remux.c:218
void BlockDump(const char *Name, const u_char *Data, int Length)
Definition remux.c:1159
int TsSync(const uchar *Data, int Length, const char *File, const char *Function, int Line)
Definition remux.c:147
void TsDump(const char *Name, const u_char *Data, int Length)
Definition remux.c:1170
int64_t TsGetPts(const uchar *p, int l, int Pid)
Definition remux.c:160
#define TS_ERROR
Definition remux.h:35
bool TsError(const uchar *p)
Definition remux.h:77
#define TS_ADAPT_PCR
Definition remux.h:46
int TsPid(const uchar *p)
Definition remux.h:82
#define TS_SCRAMBLING_CONTROL
Definition remux.h:39
bool TsHasPayload(const uchar *p)
Definition remux.h:62
#define MAX33BIT
Definition remux.h:59
#define MAX_PMT_PIDS
Definition remux.h:355
int PesPayloadOffset(const uchar *p)
Definition remux.h:178
bool TsIsScrambled(const uchar *p)
Definition remux.h:93
void TsSetContinuityCounter(uchar *p, uchar Counter)
Definition remux.h:103
uchar TsContinuityCounter(const uchar *p)
Definition remux.h:98
#define MAX_PMT_TS
Definition remux.h:296
int TsGetPayload(const uchar **p)
Definition remux.h:114
#define TS_PAYLOAD_EXISTS
Definition remux.h:41
bool PesHasPts(const uchar *p)
Definition remux.h:183
bool PesLongEnough(int Length)
Definition remux.h:163
#define TS_SIZE
Definition remux.h:34
eAspectRatio
Definition remux.h:518
@ arMax
Definition remux.h:524
@ ar_16_9
Definition remux.h:522
@ ar_1_1
Definition remux.h:520
@ arUnknown
Definition remux.h:519
@ ar_4_3
Definition remux.h:521
@ ar_2_21_1
Definition remux.h:523
void TsSetPid(uchar *p, int Pid)
Definition remux.h:87
eScanType
Definition remux.h:511
@ stMax
Definition remux.h:515
@ stInterlaced
Definition remux.h:514
@ stProgressive
Definition remux.h:513
@ stUnknown
Definition remux.h:512
#define MAX_SECTION_SIZE
Definition remux.h:295
int64_t PesGetDts(const uchar *p)
Definition remux.h:202
#define TS_ADAPT_FIELD_EXISTS
Definition remux.h:40
int64_t PesGetPts(const uchar *p)
Definition remux.h:193
bool TsPayloadStart(const uchar *p)
Definition remux.h:72
int TsPayloadOffset(const uchar *p)
Definition remux.h:108
int64_t TsGetPcr(const uchar *p)
Definition remux.h:124
bool PesHasDts(const uchar *p)
Definition remux.h:188
#define PCRFACTOR
Definition remux.h:58
bool PesHasLength(const uchar *p)
Definition remux.h:168
bool TsHasAdaptationField(const uchar *p)
Definition remux.h:67
int PesLength(const uchar *p)
Definition remux.h:173
ePesHeader
Definition remux.h:16
@ phMPEG2
Definition remux.h:20
@ phNeedMoreData
Definition remux.h:17
@ phInvalid
Definition remux.h:18
@ phMPEG1
Definition remux.h:19
#define TS_CONT_CNT_MASK
Definition remux.h:42
#define TS_PAYLOAD_START
Definition remux.h:36
int64_t PtsAdd(int64_t Pts1, int64_t Pts2)
Adds the given PTS values, taking into account the 33bit wrap around.
Definition remux.h:216
#define TS_PID_MASK_HI
Definition remux.h:38
unsigned char uchar
Definition tools.h:31