vdr  2.2.0
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 3.4 2014/03/22 14:58:24 kls Exp $
8  */
9 
10 #ifndef __REMUX_H
11 #define __REMUX_H
12 
13 #include "channels.h"
14 #include "tools.h"
15 
16 enum ePesHeader {
18  phInvalid = 0,
19  phMPEG1 = 1,
20  phMPEG2 = 2
21  };
22 
23 ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader = NULL);
24 
25 class cRemux {
26 public:
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 MAXPID 0x2000 // for arrays that use a PID as the index
55 
56 #define PTSTICKS 90000 // number of PTS ticks per second
57 #define PCRFACTOR 300 // conversion from 27MHz PCR extension to 90kHz PCR base
58 #define MAX33BIT 0x00000001FFFFFFFFLL // max. possible value with 33 bit
59 #define MAX27MHZ ((MAX33BIT + 1) * PCRFACTOR - 1) // max. possible PCR value
60 
61 inline bool TsHasPayload(const uchar *p)
62 {
63  return p[3] & TS_PAYLOAD_EXISTS;
64 }
65 
66 inline bool TsSetPayload(const uchar *p)
67 {
68  return p[3] & TS_PAYLOAD_EXISTS;
69 }
70 
71 inline bool TsHasAdaptationField(const uchar *p)
72 {
73  return p[3] & TS_ADAPT_FIELD_EXISTS;
74 }
75 
76 inline bool TsPayloadStart(const uchar *p)
77 {
78  return p[1] & TS_PAYLOAD_START;
79 }
80 
81 inline bool TsError(const uchar *p)
82 {
83  return p[1] & TS_ERROR;
84 }
85 
86 inline int TsPid(const uchar *p)
87 {
88  return (p[1] & TS_PID_MASK_HI) * 256 + p[2];
89 }
90 
91 inline bool TsIsScrambled(const uchar *p)
92 {
93  return p[3] & TS_SCRAMBLING_CONTROL;
94 }
95 
97 {
98  return p[3] & TS_CONT_CNT_MASK;
99 }
100 
101 inline void TsSetContinuityCounter(uchar *p, uchar Counter)
102 {
103  p[3] = (p[3] & ~TS_CONT_CNT_MASK) | (Counter & TS_CONT_CNT_MASK);
104 }
105 
106 inline int TsPayloadOffset(const uchar *p)
107 {
108  int o = TsHasAdaptationField(p) ? p[4] + 5 : 4;
109  return o <= TS_SIZE ? o : TS_SIZE;
110 }
111 
112 inline int TsGetPayload(const uchar **p)
113 {
114  if (TsHasPayload(*p)) {
115  int o = TsPayloadOffset(*p);
116  *p += o;
117  return TS_SIZE - o;
118  }
119  return 0;
120 }
121 
122 inline int TsContinuityCounter(const uchar *p)
123 {
124  return p[3] & TS_CONT_CNT_MASK;
125 }
126 
127 inline int64_t TsGetPcr(const uchar *p)
128 {
129  if (TsHasAdaptationField(p)) {
130  if (p[4] >= 7 && (p[5] & TS_ADAPT_PCR)) {
131  return ((((int64_t)p[ 6]) << 25) |
132  (((int64_t)p[ 7]) << 17) |
133  (((int64_t)p[ 8]) << 9) |
134  (((int64_t)p[ 9]) << 1) |
135  (((int64_t)p[10]) >> 7)) * PCRFACTOR +
136  (((((int)p[10]) & 0x01) << 8) |
137  ( ((int)p[11])));
138  }
139  }
140  return -1;
141 }
142 
143 void TsHidePayload(uchar *p);
144 void TsSetPcr(uchar *p, int64_t Pcr);
145 
146 // The following functions all take a pointer to a sequence of complete TS packets.
147 
148 int64_t TsGetPts(const uchar *p, int l);
149 int64_t TsGetDts(const uchar *p, int l);
150 void TsSetPts(uchar *p, int l, int64_t Pts);
151 void TsSetDts(uchar *p, int l, int64_t Dts);
152 void TsExtendAdaptionField(unsigned char *Packet, int ToLength);
153 
154 // Some PES handling tools:
155 // The following functions that take a pointer to PES data all assume that
156 // there is enough data so that PesLongEnough() returns true.
157 
158 inline bool PesLongEnough(int Length)
159 {
160  return Length >= 6;
161 }
162 
163 inline bool PesHasLength(const uchar *p)
164 {
165  return p[4] | p[5];
166 }
167 
168 inline int PesLength(const uchar *p)
169 {
170  return 6 + p[4] * 256 + p[5];
171 }
172 
173 inline int PesPayloadOffset(const uchar *p)
174 {
175  return 9 + p[8];
176 }
177 
178 inline bool PesHasPts(const uchar *p)
179 {
180  return (p[7] & 0x80) && p[8] >= 5;
181 }
182 
183 inline bool PesHasDts(const uchar *p)
184 {
185  return (p[7] & 0x40) && p[8] >= 10;
186 }
187 
188 inline int64_t PesGetPts(const uchar *p)
189 {
190  return ((((int64_t)p[ 9]) & 0x0E) << 29) |
191  (( (int64_t)p[10]) << 22) |
192  ((((int64_t)p[11]) & 0xFE) << 14) |
193  (( (int64_t)p[12]) << 7) |
194  ((((int64_t)p[13]) & 0xFE) >> 1);
195 }
196 
197 inline int64_t PesGetDts(const uchar *p)
198 {
199  return ((((int64_t)p[14]) & 0x0E) << 29) |
200  (( (int64_t)p[15]) << 22) |
201  ((((int64_t)p[16]) & 0xFE) << 14) |
202  (( (int64_t)p[17]) << 7) |
203  ((((int64_t)p[18]) & 0xFE) >> 1);
204 }
205 
206 void PesSetPts(uchar *p, int64_t Pts);
207 void PesSetDts(uchar *p, int64_t Dts);
208 
209 // PTS handling:
210 
211 inline int64_t PtsAdd(int64_t Pts1, int64_t Pts2) { return (Pts1 + Pts2) & MAX33BIT; }
213 int64_t PtsDiff(int64_t Pts1, int64_t Pts2);
218 
219 // A transprent TS payload handler:
220 
221 class cTsPayload {
222 private:
224  int length;
225  int pid;
226  int index; // points to the next byte to process
227  int numPacketsPid; // the number of TS packets with the given PID (for statistical purposes)
228  int numPacketsOther; // the number of TS packets with other PIDs (for statistical purposes)
229  uchar SetEof(void);
230 protected:
231  void Reset(void);
232 public:
233  cTsPayload(void);
234  cTsPayload(uchar *Data, int Length, int Pid = -1);
236  void Setup(uchar *Data, int Length, int Pid = -1);
244  bool AtTsStart(void) { return index < length && (index % TS_SIZE) == 0; }
247  bool AtPayloadStart(void) { return AtTsStart() && TsPayloadStart(data + index); }
250  int Available(void) { return length - index; }
253  int Used(void) { return (index + TS_SIZE - 1) / TS_SIZE * TS_SIZE; }
257  bool Eof(void) const { return index >= length; }
259  void Statistics(void) const;
263  uchar GetByte(void);
265  bool SkipBytes(int Bytes);
268  bool SkipPesHeader(void);
270  int GetLastIndex(void);
273  void SetByte(uchar Byte, int Index);
278  bool Find(uint32_t Code);
286  };
287 
288 // PAT/PMT Generator:
289 
290 #define MAX_SECTION_SIZE 4096 // maximum size of an SI section
291 #define MAX_PMT_TS (MAX_SECTION_SIZE / TS_SIZE + 1)
292 
294 private:
295  uchar pat[TS_SIZE]; // the PAT always fits into a single TS packet
296  uchar pmt[MAX_PMT_TS][TS_SIZE]; // the PMT may well extend over several TS packets
302  int pmtPid;
304  void IncCounter(int &Counter, uchar *TsPacket);
305  void IncVersion(int &Version);
306  void IncEsInfoLength(int Length);
307 protected:
308  int MakeStream(uchar *Target, uchar Type, int Pid);
309  int MakeAC3Descriptor(uchar *Target, uchar Type);
310  int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId);
311  int MakeTeletextDescriptor(uchar *Target, const tTeletextSubtitlePage *pages, int pageCount);
312  int MakeLanguageDescriptor(uchar *Target, const char *Language);
313  int MakeCRC(uchar *Target, const uchar *Data, int Length);
314  void GeneratePmtPid(const cChannel *Channel);
317  void GeneratePat(void);
319  void GeneratePmt(const cChannel *Channel);
322 public:
323  cPatPmtGenerator(const cChannel *Channel = NULL);
324  void SetVersions(int PatVersion, int PmtVersion);
333  void SetChannel(const cChannel *Channel);
335  uchar *GetPat(void);
338  uchar *GetPmt(int &Index);
343  };
344 
345 // PAT/PMT Parser:
346 
347 #define MAX_PMT_PIDS 32
348 
350 private:
352  int pmtSize;
355  int pmtPids[MAX_PMT_PIDS + 1]; // list is zero-terminated
356  int vpid;
357  int ppid;
358  int vtype;
359  int tpid;
360  int apids[MAXAPIDS + 1]; // list is zero-terminated
361  int atypes[MAXAPIDS + 1]; // list is zero-terminated
363  int dpids[MAXDPIDS + 1]; // list is zero-terminated
364  int dtypes[MAXDPIDS + 1]; // list is zero-terminated
366  int spids[MAXSPIDS + 1]; // list is zero-terminated
374 protected:
375  int SectionLength(const uchar *Data, int Length) { return (Length >= 3) ? ((int(Data[1]) & 0x0F) << 8)| Data[2] : 0; }
376 public:
377  cPatPmtParser(bool UpdatePrimaryDevice = false);
378  void Reset(void);
381  void ParsePat(const uchar *Data, int Length);
384  void ParsePmt(const uchar *Data, int Length);
391  bool ParsePatPmt(const uchar *Data, int Length);
395  bool GetVersions(int &PatVersion, int &PmtVersion) const;
398  bool IsPmtPid(int Pid) const { for (int i = 0; pmtPids[i]; i++) if (pmtPids[i] == Pid) return true; return false; }
401  int Vpid(void) const { return vpid; }
404  int Ppid(void) const { return ppid; }
407  int Vtype(void) const { return vtype; }
410  int Tpid(void) { return tpid; }
413  const int *Apids(void) const { return apids; }
414  const int *Dpids(void) const { return dpids; }
415  const int *Spids(void) const { return spids; }
416  int Apid(int i) const { return (0 <= i && i < MAXAPIDS) ? apids[i] : 0; }
417  int Dpid(int i) const { return (0 <= i && i < MAXDPIDS) ? dpids[i] : 0; }
418  int Spid(int i) const { return (0 <= i && i < MAXSPIDS) ? spids[i] : 0; }
419  int Atype(int i) const { return (0 <= i && i < MAXAPIDS) ? atypes[i] : 0; }
420  int Dtype(int i) const { return (0 <= i && i < MAXDPIDS) ? dtypes[i] : 0; }
421  const char *Alang(int i) const { return (0 <= i && i < MAXAPIDS) ? alangs[i] : ""; }
422  const char *Dlang(int i) const { return (0 <= i && i < MAXDPIDS) ? dlangs[i] : ""; }
423  const char *Slang(int i) const { return (0 <= i && i < MAXSPIDS) ? slangs[i] : ""; }
424  uchar SubtitlingType(int i) const { return (0 <= i && i < MAXSPIDS) ? subtitlingTypes[i] : uchar(0); }
425  uint16_t CompositionPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? compositionPageIds[i] : uint16_t(0); }
426  uint16_t AncillaryPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? ancillaryPageIds[i] : uint16_t(0); }
429  };
430 
431 // TS to PES converter:
432 // Puts together the payload of several TS packets that form one PES
433 // packet.
434 
435 class cTsToPes {
436 private:
438  int size;
439  int length;
440  int offset;
444 public:
445  cTsToPes(void);
446  ~cTsToPes();
447  void PutTs(const uchar *Data, int Length);
457  const uchar *GetPes(int &Length);
471  void SetRepeatLast(void);
474  void Reset(void);
478  };
479 
480 // Some helper functions for debugging:
481 
482 void BlockDump(const char *Name, const u_char *Data, int Length);
483 void TsDump(const char *Name, const u_char *Data, int Length);
484 void PesDump(const char *Name, const u_char *Data, int Length);
485 
486 // Frame detector:
487 
488 #define MIN_TS_PACKETS_FOR_FRAME_DETECTOR 100
489 
490 class cFrameParser;
491 
493 private:
494  enum { MaxPtsValues = 150 };
495  int pid;
496  int type;
497  bool synced;
498  bool newFrame;
500  uint32_t ptsValues[MaxPtsValues]; // 32 bit is enough - we only need the delta
503  bool isVideo;
506  int framesPerPayloadUnit; // Some broadcasters send one frame per payload unit (== 1),
507  // while others put an entire GOP into one payload unit (> 1).
508  bool scanning;
510 public:
511  cFrameDetector(int Pid = 0, int Type = 0);
515  void SetPid(int Pid, int Type);
517  int Analyze(const uchar *Data, int Length);
523  bool Synced(void) { return synced; }
525  bool NewFrame(void) { return newFrame; }
528  bool IndependentFrame(void) { return independentFrame; }
532  double FramesPerSecond(void) { return framesPerSecond; }
535  };
536 
537 
538 #define PATCH_NALUDUMP 100
539 
540 class cNaluDumper {
541  unsigned int History;
542 
546 
548 
549  int PesId;
551 
553 
555  NALU_NONE=0, // currently not NALU fill stream
556  NALU_FILL, // Within NALU fill stream, 0xff bytes and NALU start code in byte 0
557  NALU_TERM, // Within NALU fill stream, read 0x80 terminating byte
558  NALU_END // Beyond end of NALU fill stream, expecting 0x00 0x00 0x01 now
559  };
560 
562 
563  struct sPayloadInfo {
567  };
568 
569 public:
570  cNaluDumper();
571 
572  void reset();
573 
574  // Single packet interface:
575  bool ProcessTSPacket(unsigned char *Packet);
576 
577 private:
578  void ProcessPayload(unsigned char *Payload, int size, bool PayloadStart, sPayloadInfo &Info);
579 };
580 
582  //Buffer stream interface:
583  int vpid;
585  int length;
591 
592  long long int TotalPackets;
593  long long int DroppedPackets;
594 public:
596 
597  void SetPid(int VPid) { vpid = VPid; }
598  void SetPatPmtParser(cPatPmtParser *_pPatPmtParser) { pPatPmtParser = _pPatPmtParser; }
599  // Set either a PID or set a pointer to an PatPmtParser that will detect _one_ PID
600 
601  void PutBuffer(uchar *Data, int Length);
602  // Add new data to be processed. Data must be valid until Get() returns NULL.
603  uchar* GetBuffer(int &OutLength);
604  // Returns filtered data, or NULL/0 to indicate that all data from Put() was processed
605  // or buffered.
606 
607  long long int GetTotalPackets() { return TotalPackets; }
608  long long int GetDroppedPackets() { return DroppedPackets; }
609 };
610 
611 #endif // __REMUX_H
int framesInPayloadUnit
Definition: remux.h:505
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:990
const int * Dpids(void) const
Definition: remux.h:414
unsigned char uchar
Definition: tools.h:30
void ParsePat(const uchar *Data, int Length)
Parses the PAT data from the single TS packet in Data.
Definition: remux.c:678
int64_t PtsAdd(int64_t Pts1, int64_t Pts2)
Adds the given PTS values, taking into account the 33bit wrap around.
Definition: remux.h:211
uchar * data
Definition: remux.h:223
int Used(void)
Returns the number of raw bytes that have already been used (e.g.
Definition: remux.h:253
uchar GetByte(void)
Gets the next byte of the TS payload, skipping any intermediate TS header data.
Definition: remux.c:267
bool repeatLast
Definition: remux.h:443
int vpid
Definition: remux.h:356
int index
Definition: remux.h:226
int pid
Definition: remux.h:225
int Apid(int i) const
Definition: remux.h:416
uchar subtitlingTypes[MAXSPIDS]
Definition: remux.h:368
const char * Slang(int i) const
Definition: remux.h:423
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:630
bool TsError(const uchar *p)
Definition: remux.h:81
void SetPid(int Pid, int Type)
Sets the Pid and stream Type to detect frames for.
Definition: remux.c:1544
int PesPayloadOffset(const uchar *p)
Definition: remux.h:173
void IncCounter(int &Counter, uchar *TsPacket)
Definition: remux.c:394
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:298
bool TsHasAdaptationField(const uchar *p)
Definition: remux.h:71
void ParsePmt(const uchar *Data, int Length)
Parses the PMT data from the single TS packet in Data.
Definition: remux.c:710
uint16_t ancillaryPageIds[MAXSPIDS]
Definition: remux.h:370
int framesPerPayloadUnit
Definition: remux.h:506
int pmtSize
Definition: remux.h:352
char alangs[MAXAPIDS][MAXLANGCODE2]
Definition: remux.h:362
cNaluDumper NaluDumper
Definition: remux.h:590
#define MAX33BIT
Definition: remux.h:58
int LastContinuityInput
Definition: remux.h:543
void SetPid(int VPid)
Definition: remux.h:597
bool TsPayloadStart(const uchar *p)
Definition: remux.h:76
int64_t TsGetDts(const uchar *p, int l)
Definition: remux.c:160
void TsExtendAdaptionField(unsigned char *Packet, int ToLength)
Definition: remux.c:346
int MakeLanguageDescriptor(uchar *Target, const char *Language)
Definition: remux.c:478
bool IsPmtPid(int Pid) const
Returns true if Pid the one of the PMT pids as defined by the current PAT.
Definition: remux.h:398
void GeneratePmtPid(const cChannel *Channel)
Generates a PMT pid that doesn&#39;t collide with any of the actual pids of the Channel.
Definition: remux.c:512
int64_t PesGetPts(const uchar *p)
Definition: remux.h:188
int NaluOffset
Definition: remux.h:552
int Analyze(const uchar *Data, int Length)
Analyzes the TS packets pointed to by Data.
Definition: remux.c:1561
int Atype(int i) const
Definition: remux.h:419
uchar pat[TS_SIZE]
Definition: remux.h:295
long long int GetDroppedPackets()
Definition: remux.h:608
int numPacketsPid
Definition: remux.h:227
uchar SubtitlingType(int i) const
Definition: remux.h:424
bool TsHasPayload(const uchar *p)
Definition: remux.h:61
bool DropAllPayload
Definition: remux.h:547
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:407
void TsHidePayload(uchar *p)
Definition: remux.c:121
uint32_t ptsValues[MaxPtsValues]
Definition: remux.h:500
int Dtype(int i) const
Definition: remux.h:420
#define TS_ERROR
Definition: remux.h:35
char slangs[MAXSPIDS][MAXLANGCODE2]
Definition: remux.h:367
#define TS_SCRAMBLING_CONTROL
Definition: remux.h:39
#define TS_ADAPT_FIELD_EXISTS
Definition: remux.h:40
void IncEsInfoLength(int Length)
Definition: remux.c:407
int MakeCRC(uchar *Target, const uchar *Data, int Length)
Definition: remux.c:497
int Ppid(void) const
Returns the PCR pid as defined by the current PMT, or 0 if no PCR pid has been detected, yet.
Definition: remux.h:404
int MakeTeletextDescriptor(uchar *Target, const tTeletextSubtitlePage *pages, int pageCount)
Definition: remux.c:455
int Tpid(void)
Returns the teletext pid as defined by the current PMT, or 0 if no teletext pid has been detected...
Definition: remux.h:410
#define MAXTXTPAGES
Definition: channels.h:39
void BlockDump(const char *Name, const u_char *Data, int Length)
Definition: remux.c:1122
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
Definition: remux.c:636
void TsSetDts(uchar *p, int l, int64_t Dts)
Definition: remux.c:187
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:247
bool PesHasPts(const uchar *p)
Definition: remux.h:178
cPatPmtGenerator(const cChannel *Channel=NULL)
Definition: remux.c:384
uchar SetEof(void)
Definition: remux.c:246
int MakeSubtitlingDescriptor(uchar *Target, const char *Language, uchar SubtitlingType, uint16_t CompositionPageId, uint16_t AncillaryPageId)
Definition: remux.c:438
int length
Definition: remux.h:439
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:259
int PesOffset
Definition: remux.h:550
bool isVideo
Definition: remux.h:503
int pmtVersion
Definition: remux.h:354
int numPtsValues
Definition: remux.h:501
cPatPmtParser * pPatPmtParser
Definition: remux.h:589
bool independentFrame
Definition: remux.h:499
int lastLength
Definition: remux.h:442
int MakeAC3Descriptor(uchar *Target, uchar Type)
Definition: remux.c:428
tTeletextSubtitlePage teletextSubtitlePages[MAXTXTPAGES]
Definition: remux.h:373
void GeneratePat(void)
Generates a PAT section for later use with GetPat().
Definition: remux.c:527
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:321
int SectionLength(const uchar *Data, int Length)
Definition: remux.h:375
int Available(void)
Returns the number of raw bytes (including any TS headers) still available in the TS payload handler...
Definition: remux.h:250
int MakeStream(uchar *Target, uchar Type, int Pid)
Definition: remux.c:416
int patCounter
Definition: remux.h:298
uchar pmt[MAX_PMT_TS][TS_SIZE]
Definition: remux.h:296
uchar * lastData
Definition: remux.h:441
bool TsSetPayload(const uchar *p)
Definition: remux.h:66
bool Synced(void)
Returns true if the frame detector has synced on the data stream.
Definition: remux.h:523
bool PesLongEnough(int Length)
Definition: remux.h:158
long long int GetTotalPackets()
Definition: remux.h:607
int64_t TsGetPts(const uchar *p, int l)
Definition: remux.c:147
#define MAX_SECTION_SIZE
Definition: remux.h:290
int TsPid(const uchar *p)
Definition: remux.h:86
long long int DroppedPackets
Definition: remux.h:593
cFrameDetector(int Pid=0, int Type=0)
Sets up a frame detector for the given Pid and stream Type.
Definition: remux.c:1524
double framesPerSecond
Definition: remux.h:504
#define TS_PAYLOAD_EXISTS
Definition: remux.h:41
int PesLength(const uchar *p)
Definition: remux.h:168
void TsSetPcr(uchar *p, int64_t Pcr)
Definition: remux.c:131
void PesDump(const char *Name, const u_char *Data, int Length)
Definition: remux.c:1148
int Dpid(int i) const
Definition: remux.h:417
Definition: remux.h:20
int ppid
Definition: remux.h:357
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:1009
int TsContinuityCounter(const uchar *p)
Definition: remux.h:122
char dlangs[MAXDPIDS][MAXLANGCODE2]
Definition: remux.h:365
void Reset(void)
Resets the converter.
Definition: remux.c:1112
const int * Apids(void) const
Definition: remux.h:413
int ContinuityOffset
Definition: remux.h:545
bool synced
Definition: remux.h:497
uchar TsGetContinuityCounter(const uchar *p)
Definition: remux.h:96
bool PesHasDts(const uchar *p)
Definition: remux.h:183
const char * Alang(int i) const
Definition: remux.h:421
void TsDump(const char *Name, const u_char *Data, int Length)
Definition: remux.c:1133
cPatPmtParser(bool UpdatePrimaryDevice=false)
Definition: remux.c:662
int GetLastIndex(void)
Returns the index into the TS data of the payload byte that has most recently been read...
Definition: remux.c:310
int PesId
Definition: remux.h:549
const int * Spids(void) const
Definition: remux.h:415
cTsPayload(void)
Definition: remux.c:233
int dtypes[MAXDPIDS+1]
Definition: remux.h:364
int dpids[MAXDPIDS+1]
Definition: remux.h:363
const char * Dlang(int i) const
Definition: remux.h:422
void PesSetDts(uchar *p, int64_t Dts)
Definition: remux.c:212
void PutTs(const uchar *Data, int Length)
Puts the payload data of the single TS packet at Data into the converter.
Definition: remux.c:1030
int atypes[MAXAPIDS+1]
Definition: remux.h:361
unsigned int History
Definition: remux.h:541
uchar * GetPmt(int &Index)
Returns a pointer to the Index&#39;th TS packet of the PMT section.
Definition: remux.c:651
void TsSetContinuityCounter(uchar *p, uchar Counter)
Definition: remux.h:101
int numPmtPackets
Definition: remux.h:297
void reset()
Definition: remux.c:1686
void ProcessPayload(unsigned char *Payload, int size, bool PayloadStart, sPayloadInfo &Info)
Definition: remux.c:1698
bool Eof(void) const
Returns true if all available bytes of the TS payload have been processed.
Definition: remux.h:257
~cTsToPes()
Definition: remux.c:1025
int TsGetPayload(const uchar **p)
Definition: remux.h:112
int pmtCounter
Definition: remux.h:299
int LastContinuityOutput
Definition: remux.h:544
long long int TotalPackets
Definition: remux.h:592
void GeneratePmt(const cChannel *Channel)
Generates a PMT section for the given Channel, for later use with GetPmt().
Definition: remux.c:556
uchar pmt[MAX_SECTION_SIZE]
Definition: remux.h:351
Definition: remux.h:25
int length
Definition: remux.h:224
#define TS_CONT_CNT_MASK
Definition: remux.h:42
uint16_t compositionPageIds[MAXSPIDS]
Definition: remux.h:369
void PesSetPts(uchar *p, int64_t Pts)
Definition: remux.c:203
#define MAXLANGCODE2
Definition: channels.h:42
int pmtPids[MAX_PMT_PIDS+1]
Definition: remux.h:355
const tTeletextSubtitlePage * TeletextSubtitlePages() const
Definition: remux.h:427
static void SetBrokenLink(uchar *Data, int Length)
Definition: remux.c:102
uint16_t AncillaryPageId(int i) const
Definition: remux.h:426
int64_t TsGetPcr(const uchar *p)
Definition: remux.h:127
int patVersion
Definition: remux.h:300
cFrameParser * parser
Definition: remux.h:509
void TsSetPts(uchar *p, int l, int64_t Pts)
Definition: remux.c:173
bool ProcessTSPacket(unsigned char *Packet)
Definition: remux.c:1785
int numPacketsOther
Definition: remux.h:228
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:401
#define MAXDPIDS
Definition: channels.h:36
int spids[MAXSPIDS+1]
Definition: remux.h:366
#define MAX_PMT_TS
Definition: remux.h:291
int size
Definition: remux.h:438
#define PCRFACTOR
Definition: remux.h:57
int TotalTeletextSubtitlePages() const
Definition: remux.h:428
#define MAX_PMT_PIDS
Definition: remux.h:347
bool PesHasLength(const uchar *p)
Definition: remux.h:163
uint16_t CompositionPageId(int i) const
Definition: remux.h:425
bool NewFrame(void)
Returns true if the data given to the last call to Analyze() started a new frame. ...
Definition: remux.h:525
bool IndependentFrame(void)
Returns true if a new frame was detected and this is an independent frame (i.e.
Definition: remux.h:528
unsigned char u_char
Definition: headers.h:24
int totalTtxtSubtitlePages
Definition: remux.h:372
bool TsIsScrambled(const uchar *p)
Definition: remux.h:91
int64_t PesGetDts(const uchar *p)
Definition: remux.h:197
ePesHeader
Definition: remux.h:16
void SetByte(uchar Byte, int Index)
Sets the TS data byte at the given Index to the value Byte.
Definition: remux.c:315
int tpid
Definition: remux.h:359
cNaluDumper()
Definition: remux.c:1680
uchar * esInfoLength
Definition: remux.h:303
#define TS_PAYLOAD_START
Definition: remux.h:36
bool updatePrimaryDevice
Definition: remux.h:371
void Reset(void)
Definition: remux.c:252
double FramesPerSecond(void)
Returns the number of frames per second, or 0 if this information is not available.
Definition: remux.h:532
#define MAXSPIDS
Definition: channels.h:37
eNaluFillState NaluFillState
Definition: remux.h:561
bool newFrame
Definition: remux.h:498
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:338
#define TS_SIZE
Definition: remux.h:34
Definition: remux.h:19
void IncVersion(int &Version)
Definition: remux.c:401
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:1059
int TsPayloadOffset(const uchar *p)
Definition: remux.h:106
bool scanning
Definition: remux.h:508
int offset
Definition: remux.h:440
#define TS_ADAPT_PCR
Definition: remux.h:46
int numIFrames
Definition: remux.h:502
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:1107
bool AtTsStart(void)
Returns true if this payload handler is currently pointing to first byte of a TS packet.
Definition: remux.h:244
#define TS_PID_MASK_HI
Definition: remux.h:38
eNaluFillState
Definition: remux.h:554
int64_t PtsDiff(int64_t Pts1, int64_t Pts2)
Returns the difference between two PTS values.
Definition: remux.c:221
void SetPatPmtParser(cPatPmtParser *_pPatPmtParser)
Definition: remux.h:598
void PutBuffer(uchar *Data, int Length)
Definition: remux.c:1878
void Reset(void)
Resets the parser.
Definition: remux.c:668
int Spid(int i) const
Definition: remux.h:418
uchar * data
Definition: remux.h:437
ePesHeader AnalyzePesHeader(const uchar *Data, int Count, int &PesPayloadOffset, bool *ContinuationHeader=NULL)
Definition: remux.c:32
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
Definition: remux.c:645
uchar * GetBuffer(int &OutLength)
Definition: remux.c:1887
int patVersion
Definition: remux.h:353
int vtype
Definition: remux.h:358
int pmtVersion
Definition: remux.h:301
bool SkipPesHeader(void)
Skips all bytes belonging to the PES header of the payload.
Definition: remux.c:305
cTsToPes(void)
Definition: remux.c:1018
int apids[MAXAPIDS+1]
Definition: remux.h:360
#define MAXAPIDS
Definition: channels.h:35
uchar tempBuffer[TS_SIZE]
Definition: remux.h:586
bool tempLengthAtEnd
Definition: remux.h:588