vdr 2.7.9
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.11 2025/12/30 12:38:52 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 TsSetPayload(const uchar *p)
68{
69 return p[3] & TS_PAYLOAD_EXISTS;
70}
71
72inline bool TsHasAdaptationField(const uchar *p)
73{
74 return p[3] & TS_ADAPT_FIELD_EXISTS;
75}
76
77inline bool TsPayloadStart(const uchar *p)
78{
79 return p[1] & TS_PAYLOAD_START;
80}
81
82inline bool TsError(const uchar *p)
83{
84 return p[1] & TS_ERROR;
85}
86
87inline int TsPid(const uchar *p)
88{
89 return (p[1] & TS_PID_MASK_HI) * 256 + p[2];
90}
91
92inline void TsSetPid(uchar *p, int Pid)
93{
94 p[1] = (p[1] & ~TS_PID_MASK_HI) | ((Pid >> 8) & TS_PID_MASK_HI);
95 p[2] = Pid & 0x00FF;
96}
97
98inline bool TsIsScrambled(const uchar *p)
99{
100 return p[3] & TS_SCRAMBLING_CONTROL;
101}
102
104{
105 return p[3] & TS_CONT_CNT_MASK;
106}
107
108inline void TsSetContinuityCounter(uchar *p, uchar Counter)
109{
110 p[3] = (p[3] & ~TS_CONT_CNT_MASK) | (Counter & TS_CONT_CNT_MASK);
111}
112
113inline int TsPayloadOffset(const uchar *p)
114{
115 int o = TsHasAdaptationField(p) ? p[4] + 5 : 4;
116 return o <= TS_SIZE ? o : TS_SIZE;
117}
118
119inline int TsGetPayload(const uchar **p)
120{
121 if (TsHasPayload(*p)) {
122 int o = TsPayloadOffset(*p);
123 *p += o;
124 return TS_SIZE - o;
125 }
126 return 0;
127}
128
129inline int64_t TsGetPcr(const uchar *p)
130{
131 if (TsHasAdaptationField(p)) {
132 if (p[4] >= 7 && (p[5] & TS_ADAPT_PCR)) {
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) |
137 (((int64_t)p[10]) >> 7)) * PCRFACTOR +
138 (((((int)p[10]) & 0x01) << 8) |
139 ( ((int)p[11])));
140 }
141 }
142 return -1;
143}
144
145void TsHidePayload(uchar *p);
146void TsSetPcr(uchar *p, int64_t Pcr);
147
148// Helper macro and function to quickly check whether Data points to the beginning
149// of a TS packet. The return value is the number of bytes that need to be skipped
150// to synchronize on the next TS packet (zero if already sync'd). TsSync() can be
151// called directly, the macro just performs the initial check inline and adds some
152// debug information for logging.
153
154#define TS_SYNC(Data, Length) (*Data == TS_SYNC_BYTE ? 0 : TsSync(Data, Length, __FILE__, __FUNCTION__, __LINE__))
155int TsSync(const uchar *Data, int Length, const char *File = NULL, const char *Function = NULL, int Line = 0);
156
157// The following functions all take a pointer to a sequence of complete TS packets.
158
159int64_t TsGetPts(const uchar *p, int l);
160int64_t TsGetDts(const uchar *p, int l);
161void TsSetPts(uchar *p, int l, int64_t Pts);
162void TsSetDts(uchar *p, int l, int64_t Dts);
163void TsExtendAdaptionField(unsigned char *Packet, int ToLength);
164
165// Some PES handling tools:
166// The following functions that take a pointer to PES data all assume that
167// there is enough data so that PesLongEnough() returns true.
168
169inline bool PesLongEnough(int Length)
170{
171 return Length >= 6;
172}
173
174inline bool PesHasLength(const uchar *p)
175{
176 return p[4] | p[5];
177}
178
179inline int PesLength(const uchar *p)
180{
181 return 6 + p[4] * 256 + p[5];
182}
183
184inline int PesPayloadOffset(const uchar *p)
185{
186 return 9 + p[8];
187}
188
189inline bool PesHasPts(const uchar *p)
190{
191 return (p[7] & 0x80) && p[8] >= 5;
192}
193
194inline bool PesHasDts(const uchar *p)
195{
196 return (p[7] & 0x40) && p[8] >= 10;
197}
198
199inline int64_t PesGetPts(const uchar *p)
200{
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);
206}
207
208inline int64_t PesGetDts(const uchar *p)
209{
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);
215}
216
217void PesSetPts(uchar *p, int64_t Pts);
218void PesSetDts(uchar *p, int64_t Dts);
219
220// PTS handling:
221
222inline int64_t PtsAdd(int64_t Pts1, int64_t Pts2) { return (Pts1 + Pts2) & MAX33BIT; }
224int64_t PtsDiff(int64_t Pts1, int64_t Pts2);
229
230// A transparent TS payload handler:
231
233private:
236 int pid;
237 int index; // points to the next byte to process
238 int numPacketsPid; // the number of TS packets with the given PID (for statistical purposes)
239 int numPacketsOther; // the number of TS packets with other PIDs (for statistical purposes)
240 uchar SetEof(void);
241protected:
242 void Reset(void);
243public:
244 cTsPayload(void);
245 cTsPayload(uchar *Data, int Length, int Pid = -1);
247 void Setup(uchar *Data, int Length, int Pid = -1);
255 bool AtTsStart(void) { return index < length && (index % TS_SIZE) == 0; }
258 bool AtPayloadStart(void) { return AtTsStart() && TsPayloadStart(data + index) && TsPid(data + index) == pid; }
261 int Available(void) { return length - index; }
264 int Used(void) { return (index + TS_SIZE - 1) / TS_SIZE * TS_SIZE; }
268 bool Eof(void) const { return index >= length; }
270 void Statistics(void) const;
274 uchar GetByte(void);
276 bool SkipBytes(int Bytes);
279 bool SkipPesHeader(void);
281 int GetLastIndex(void);
284 void SetByte(uchar Byte, int Index);
289 bool Find(uint32_t Code);
297 };
298
299// PAT/PMT Generator:
300
301#define MAX_SECTION_SIZE 4096 // maximum size of an SI section
302#define MAX_PMT_TS (MAX_SECTION_SIZE / TS_SIZE + 1)
303
305private:
306 uchar pat[TS_SIZE]; // the PAT always fits into a single TS packet
307 uchar pmt[MAX_PMT_TS][TS_SIZE]; // the PMT may well extend over several TS packets
315 void IncCounter(int &Counter, uchar *TsPacket);
316 void IncVersion(int &Version);
317 void IncEsInfoLength(int Length);
318protected:
319 int MakeStream(uchar *Target, uchar Type, int Pid);
320 int MakeAC3Descriptor(uchar *Target, uchar Type);
321 int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId);
322 int MakeLanguageDescriptor(uchar *Target, const char *Language);
323 int MakeCRC(uchar *Target, const uchar *Data, int Length);
324 void GeneratePmtPid(const cChannel *Channel);
327 void GeneratePat(void);
329 void GeneratePmt(const cChannel *Channel);
332public:
333 cPatPmtGenerator(const cChannel *Channel = NULL);
334 void SetVersions(int PatVersion, int PmtVersion);
343 void SetChannel(const cChannel *Channel);
345 uchar *GetPat(void);
348 uchar *GetPmt(int &Index);
353 };
354
355// PAT/PMT Parser:
356
357#define MAX_PMT_PIDS 32
358
360private:
365 int pmtPids[MAX_PMT_PIDS + 1]; // list is zero-terminated
366 int vpid;
367 int ppid;
368 int vtype;
369 int apids[MAXAPIDS + 1]; // list is zero-terminated
370 int atypes[MAXAPIDS + 1]; // list is zero-terminated
372 int dpids[MAXDPIDS + 1]; // list is zero-terminated
373 int dtypes[MAXDPIDS + 1]; // list is zero-terminated
375 int spids[MAXSPIDS + 1]; // list is zero-terminated
382protected:
383 int SectionLength(const uchar *Data, int Length) { return (Length >= 3) ? ((int(Data[1]) & 0x0F) << 8)| Data[2] : 0; }
384public:
385 cPatPmtParser(bool UpdatePrimaryDevice = false);
386 void Reset(void);
389 void ParsePat(const uchar *Data, int Length);
392 void ParsePmt(const uchar *Data, int Length);
399 bool ParsePatPmt(const uchar *Data, int Length);
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; }
420 const int *Apids(void) const { return apids; }
421 const int *Dpids(void) const { return dpids; }
422 const int *Spids(void) const { return spids; }
423 int Apid(int i) const { return (0 <= i && i < MAXAPIDS) ? apids[i] : 0; }
424 int Dpid(int i) const { return (0 <= i && i < MAXDPIDS) ? dpids[i] : 0; }
425 int Spid(int i) const { return (0 <= i && i < MAXSPIDS) ? spids[i] : 0; }
426 int Atype(int i) const { return (0 <= i && i < MAXAPIDS) ? atypes[i] : 0; }
427 int Dtype(int i) const { return (0 <= i && i < MAXDPIDS) ? dtypes[i] : 0; }
428 const char *Alang(int i) const { return (0 <= i && i < MAXAPIDS) ? alangs[i] : ""; }
429 const char *Dlang(int i) const { return (0 <= i && i < MAXDPIDS) ? dlangs[i] : ""; }
430 const char *Slang(int i) const { return (0 <= i && i < MAXSPIDS) ? slangs[i] : ""; }
431 uchar SubtitlingType(int i) const { return (0 <= i && i < MAXSPIDS) ? subtitlingTypes[i] : uchar(0); }
432 uint16_t CompositionPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? compositionPageIds[i] : uint16_t(0); }
433 uint16_t AncillaryPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? ancillaryPageIds[i] : uint16_t(0); }
434 };
435
436// EIT Generator:
437
439private:
443 uint16_t YMDtoMJD(int Y, int M, int D);
444 uchar *AddParentalRatingDescriptor(uchar *p, uchar ParentalRating = 0);
445public:
446 cEitGenerator(int Sid = 0);
447 uchar *Generate(int Sid);
448 uchar *Data(void) { return eit; }
449 int Length(void) { return sizeof(eit); }
450 };
451
452// TS to PES converter:
453// Puts together the payload of several TS packets that form one PES
454// packet.
455
456class cTsToPes {
457private:
459 int size;
465public:
466 cTsToPes(void);
467 ~cTsToPes();
468 void PutTs(const uchar *Data, int Length);
478 const uchar *GetPes(int &Length);
492 void SetRepeatLast(void);
495 void Reset(void);
499 };
500
501// Some helper functions for debugging:
502
503void BlockDump(const char *Name, const u_char *Data, int Length);
504void TsDump(const char *Name, const u_char *Data, int Length);
505void PesDump(const char *Name, const u_char *Data, int Length);
506
507// Frame detector:
508
509#define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 100
510
511class cFrameParser;
512
519
528
529extern const char *ScanTypeChars;
530extern const char *AspectRatioTexts[];
531
532class cTsChecker;
533class cPtsChecker;
534
536private:
539public:
540 cFrameChecker(void);
542 void Reset(void);
543 bool Check(const uchar *Data, int Length, bool Independent, bool &Errors, bool &Missing, bool Final);
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#define PATCH_NALUDUMP 100
635
637 unsigned int History;
638
642
644
645 int PesId;
647
649
651 NALU_NONE=0, // currently not NALU fill stream
652 NALU_FILL, // Within NALU fill stream, 0xff bytes and NALU start code in byte 0
653 NALU_TERM, // Within NALU fill stream, read 0x80 terminating byte
654 NALU_END // Beyond end of NALU fill stream, expecting 0x00 0x00 0x01 now
655 };
656
658
664
665public:
666 cNaluDumper();
667
668 void reset();
669
670 // Single packet interface:
671 bool ProcessTSPacket(unsigned char *Packet);
672
673private:
674 void ProcessPayload(unsigned char *Payload, int size, bool PayloadStart, sPayloadInfo &Info);
675};
676
678 //Buffer stream interface:
679 int vpid;
687
688 long long int TotalPackets;
689 long long int DroppedPackets;
690public:
692
693 void SetPid(int VPid) { vpid = VPid; }
694 void SetPatPmtParser(cPatPmtParser *_pPatPmtParser) { pPatPmtParser = _pPatPmtParser; }
695 // Set either a PID or set a pointer to an PatPmtParser that will detect _one_ PID
696
697 void PutBuffer(uchar *Data, int Length);
698 // Add new data to be processed. Data must be valid until Get() returns NULL.
699 uchar* GetBuffer(int &OutLength);
700 // Returns filtered data, or NULL/0 to indicate that all data from Put() was processed
701 // or buffered.
702
703 long long int GetTotalPackets() { return TotalPackets; }
704 long long int GetDroppedPackets() { return DroppedPackets; }
705};
706
707#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:440
cEitGenerator(int Sid=0)
Definition remux.c:985
int counter
Definition remux.h:441
uchar * Data(void)
Definition remux.h:448
int Length(void)
Definition remux.h:449
uchar * AddParentalRatingDescriptor(uchar *p, uchar ParentalRating=0)
Definition remux.c:999
uint16_t YMDtoMJD(int Y, int M, int D)
Definition remux.c:993
uchar * Generate(int Sid)
Definition remux.c:1010
int version
Definition remux.h:442
void Reset(void)
Definition remux.c:2175
cTsChecker * tsChecker
Definition remux.h:537
bool Check(const uchar *Data, int Length, bool Independent, bool &Errors, bool &Missing, bool Final)
Check Length bytes of the given Data (which must be a complete frame), with Independent telling wheth...
Definition remux.c:2180
cFrameChecker(void)
Definition remux.c:2163
cPtsChecker * ptsChecker
Definition remux.h:538
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:2191
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:2269
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:2280
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:2301
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:2208
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:2263
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:2243
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
void reset()
Definition remux.c:2444
int LastContinuityInput
Definition remux.h:639
int PesId
Definition remux.h:645
void ProcessPayload(unsigned char *Payload, int size, bool PayloadStart, sPayloadInfo &Info)
Definition remux.c:2456
bool DropAllPayload
Definition remux.h:643
@ NALU_TERM
Definition remux.h:653
@ NALU_NONE
Definition remux.h:651
@ NALU_FILL
Definition remux.h:652
unsigned int History
Definition remux.h:637
int PesOffset
Definition remux.h:646
eNaluFillState NaluFillState
Definition remux.h:657
bool ProcessTSPacket(unsigned char *Packet)
Definition remux.c:2543
cNaluDumper()
Definition remux.c:2438
int NaluOffset
Definition remux.h:648
int ContinuityOffset
Definition remux.h:641
int LastContinuityOutput
Definition remux.h:640
cPatPmtParser * pPatPmtParser
Definition remux.h:685
void SetPid(int VPid)
Definition remux.h:693
long long int DroppedPackets
Definition remux.h:689
long long int TotalPackets
Definition remux.h:688
long long int GetTotalPackets()
Definition remux.h:703
uchar tempBuffer[TS_SIZE]
Definition remux.h:682
cNaluDumper NaluDumper
Definition remux.h:686
void SetPatPmtParser(cPatPmtParser *_pPatPmtParser)
Definition remux.h:694
void PutBuffer(uchar *Data, int Length)
Definition remux.c:2636
uchar * GetBuffer(int &OutLength)
Definition remux.c:2645
long long int GetDroppedPackets()
Definition remux.h:704
int MakeCRC(uchar *Target, const uchar *Data, int Length)
Definition remux.c:489
uchar * GetPmt(int &Index)
Returns a pointer to the Index'th TS packet of the PMT section.
Definition remux.c:638
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
Definition remux.c:623
void IncEsInfoLength(int Length)
Definition remux.c:422
void IncCounter(int &Counter, uchar *TsPacket)
Definition remux.c:409
cPatPmtGenerator(const cChannel *Channel=NULL)
Definition remux.c:399
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:617
int numPmtPackets
Definition remux.h:308
uchar * esInfoLength
Definition remux.h:314
uchar pat[TS_SIZE]
Definition remux.h:306
int MakeAC3Descriptor(uchar *Target, uchar Type)
Definition remux.c:443
void GeneratePat(void)
Generates a PAT section for later use with GetPat().
Definition remux.c:519
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
Definition remux.c:632
uchar pmt[MAX_PMT_TS][TS_SIZE]
Definition remux.h:307
int MakeLanguageDescriptor(uchar *Target, const char *Language)
Definition remux.c:470
void GeneratePmt(const cChannel *Channel)
Generates a PMT section for the given Channel, for later use with GetPmt().
Definition remux.c:548
void GeneratePmtPid(const cChannel *Channel)
Generates a PMT pid that doesn't collide with any of the actual pids of the Channel.
Definition remux.c:504
int MakeStream(uchar *Target, uchar Type, int Pid)
Definition remux.c:431
int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId)
Definition remux.c:453
void IncVersion(int &Version)
Definition remux.c:416
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:976
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:415
int dpids[MAXDPIDS+1]
Definition remux.h:372
uchar pmt[MAX_SECTION_SIZE]
Definition remux.h:361
int apids[MAXAPIDS+1]
Definition remux.h:369
cPatPmtParser(bool UpdatePrimaryDevice=false)
Definition remux.c:649
void Reset(void)
Resets the parser.
Definition remux.c:655
int Dtype(int i) const
Definition remux.h:427
void ParsePat(const uchar *Data, int Length)
Parses the PAT data from the single TS packet in Data.
Definition remux.c:665
int pmtSize
Definition remux.h:362
char dlangs[MAXDPIDS][MAXLANGCODE2]
Definition remux.h:374
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:957
int patVersion
Definition remux.h:363
const int * Spids(void) const
Definition remux.h:422
int pmtPids[MAX_PMT_PIDS+1]
Definition remux.h:365
uchar subtitlingTypes[MAXSPIDS]
Definition remux.h:377
int dtypes[MAXDPIDS+1]
Definition remux.h:373
int Dpid(int i) const
Definition remux.h:424
uint16_t ancillaryPageIds[MAXSPIDS]
Definition remux.h:379
const int * Dpids(void) const
Definition remux.h:421
int SectionLength(const uchar *Data, int Length)
Definition remux.h:383
uint16_t CompositionPageId(int i) const
Definition remux.h:432
const int * Apids(void) const
Definition remux.h:420
int Apid(int i) const
Definition remux.h:423
void ParsePmt(const uchar *Data, int Length)
Parses the PMT data from the single TS packet in Data.
Definition remux.c:697
bool completed
Definition remux.h:381
bool Completed(void)
Returns true if the PMT has been completely parsed.
Definition remux.h:418
bool IsPmtPid(int Pid) const
Returns true if Pid the one of the PMT pids as defined by the current PAT.
Definition remux.h:406
uchar SubtitlingType(int i) const
Definition remux.h:431
uint16_t AncillaryPageId(int i) const
Definition remux.h:433
int Spid(int i) const
Definition remux.h:425
uint16_t compositionPageIds[MAXSPIDS]
Definition remux.h:378
char alangs[MAXAPIDS][MAXLANGCODE2]
Definition remux.h:371
int spids[MAXSPIDS+1]
Definition remux.h:375
int Atype(int i) const
Definition remux.h:426
const char * Dlang(int i) const
Definition remux.h:429
const char * Slang(int i) const
Definition remux.h:430
const char * Alang(int i) const
Definition remux.h:428
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:412
int pmtVersion
Definition remux.h:364
bool updatePrimaryDevice
Definition remux.h:380
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:409
char slangs[MAXSPIDS][MAXLANGCODE2]
Definition remux.h:376
int atypes[MAXAPIDS+1]
Definition remux.h:370
Definition remux.h:25
static void SetBrokenLink(uchar *Data, int Length)
Definition remux.c:102
int numPacketsPid
Definition remux.h:238
int pid
Definition remux.h:236
cTsPayload(void)
Definition remux.c:246
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:258
int Used(void)
Returns the number of raw bytes that have already been used (e.g.
Definition remux.h:264
bool Eof(void) const
Returns true if all available bytes of the TS payload have been processed.
Definition remux.h:268
void SetByte(uchar Byte, int Index)
Sets the TS data byte at the given Index to the value Byte.
Definition remux.c:330
uchar GetByte(void)
Gets the next byte of the TS payload, skipping any intermediate TS header data.
Definition remux.c:280
bool AtTsStart(void)
Returns true if this payload handler is currently pointing to first byte of a TS packet.
Definition remux.h:255
int Available(void)
Returns the number of raw bytes (including any TS headers) still available in the TS payload handler.
Definition remux.h:261
int GetLastIndex(void)
Returns the index into the TS data of the payload byte that has most recently been read.
Definition remux.c:325
bool SkipPesHeader(void)
Skips all bytes belonging to the PES header of the payload.
Definition remux.c:320
int index
Definition remux.h:237
int numPacketsOther
Definition remux.h:239
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:353
uchar SetEof(void)
Definition remux.c:259
int length
Definition remux.h:235
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:336
void Reset(void)
Definition remux.c:265
uchar * data
Definition remux.h:234
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:313
int lastLength
Definition remux.h:463
bool repeatLast
Definition remux.h:464
uchar * lastData
Definition remux.h:462
uchar * data
Definition remux.h:458
void PutTs(const uchar *Data, int Length)
Puts the payload data of the single TS packet at Data into the converter.
Definition remux.c:1084
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:1161
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:1113
cTsToPes(void)
Definition remux.c:1072
int length
Definition remux.h:460
~cTsToPes()
Definition remux.c:1079
void Reset(void)
Resets the converter.
Definition remux.c:1166
int offset
Definition remux.h:461
int size
Definition remux.h:459
cSetup Setup
Definition config.c:372
const char * AspectRatioTexts[]
Definition remux.c:2199
const char * ScanTypeChars
Definition remux.c:2198
void TsSetPcr(uchar *p, int64_t Pcr)
Definition remux.c:131
#define TS_ERROR
Definition remux.h:35
bool TsError(const uchar *p)
Definition remux.h:82
#define TS_ADAPT_PCR
Definition remux.h:46
int TsPid(const uchar *p)
Definition remux.h:87
void PesDump(const char *Name, const u_char *Data, int Length)
Definition remux.c:1202
#define TS_SCRAMBLING_CONTROL
Definition remux.h:39
bool TsHasPayload(const uchar *p)
Definition remux.h:62
int64_t PtsDiff(int64_t Pts1, int64_t Pts2)
Returns the difference between two PTS values.
Definition remux.c:234
#define MAX33BIT
Definition remux.h:59
#define MAX_PMT_PIDS
Definition remux.h:357
int PesPayloadOffset(const uchar *p)
Definition remux.h:184
bool TsIsScrambled(const uchar *p)
Definition remux.h:98
void TsHidePayload(uchar *p)
Definition remux.c:121
void TsSetContinuityCounter(uchar *p, uchar Counter)
Definition remux.h:108
uchar TsContinuityCounter(const uchar *p)
Definition remux.h:103
#define MAX_PMT_TS
Definition remux.h:302
int TsGetPayload(const uchar **p)
Definition remux.h:119
#define TS_PAYLOAD_EXISTS
Definition remux.h:41
bool PesHasPts(const uchar *p)
Definition remux.h:189
bool PesLongEnough(int Length)
Definition remux.h:169
#define TS_SIZE
Definition remux.h:34
eAspectRatio
Definition remux.h:520
@ arMax
Definition remux.h:526
@ ar_16_9
Definition remux.h:524
@ ar_1_1
Definition remux.h:522
@ arUnknown
Definition remux.h:521
@ ar_4_3
Definition remux.h:523
@ ar_2_21_1
Definition remux.h:525
void TsSetPid(uchar *p, int Pid)
Definition remux.h:92
eScanType
Definition remux.h:513
@ stMax
Definition remux.h:517
@ stInterlaced
Definition remux.h:516
@ stProgressive
Definition remux.h:515
@ stUnknown
Definition remux.h:514
#define MAX_SECTION_SIZE
Definition remux.h:301
int TsSync(const uchar *Data, int Length, const char *File=NULL, const char *Function=NULL, int Line=0)
Definition remux.c:147
bool TsSetPayload(const uchar *p)
Definition remux.h:67
int64_t PesGetDts(const uchar *p)
Definition remux.h:208
#define TS_ADAPT_FIELD_EXISTS
Definition remux.h:40
int64_t PesGetPts(const uchar *p)
Definition remux.h:199
bool TsPayloadStart(const uchar *p)
Definition remux.h:77
int TsPayloadOffset(const uchar *p)
Definition remux.h:113
void PesSetDts(uchar *p, int64_t Dts)
Definition remux.c:225
int64_t TsGetPcr(const uchar *p)
Definition remux.h:129
bool PesHasDts(const uchar *p)
Definition remux.h:194
#define PCRFACTOR
Definition remux.h:58
bool PesHasLength(const uchar *p)
Definition remux.h:174
bool TsHasAdaptationField(const uchar *p)
Definition remux.h:72
int64_t TsGetDts(const uchar *p, int l)
Definition remux.c:173
void TsExtendAdaptionField(unsigned char *Packet, int ToLength)
Definition remux.c:361
void TsSetDts(uchar *p, int l, int64_t Dts)
Definition remux.c:200
void TsSetPts(uchar *p, int l, int64_t Pts)
Definition remux.c:186
ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader=NULL)
Definition remux.c:32
int PesLength(const uchar *p)
Definition remux.h:179
void PesSetPts(uchar *p, int64_t Pts)
Definition remux.c:216
int64_t TsGetPts(const uchar *p, int l)
Definition remux.c:160
void BlockDump(const char *Name, const u_char *Data, int Length)
Definition remux.c:1176
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
void TsDump(const char *Name, const u_char *Data, int Length)
Definition remux.c:1187
int64_t PtsAdd(int64_t Pts1, int64_t Pts2)
Adds the given PTS values, taking into account the 33bit wrap around.
Definition remux.h:222
#define TS_PID_MASK_HI
Definition remux.h:38
unsigned char uchar
Definition tools.h:31