MythTV  master
pes.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 Marcus Metzler (mocm@metzlerbros.de)
3 
4 */
5 
6 #ifndef _PES_H_
7 #define _PES_H_
8 
9 #include <stdint.h>
10 #include "ringbuffer.h"
11 
12 #define TS_HEADER_MIN 4
13 #define PS_HEADER_L1 14
14 #define PS_HEADER_L2 (PS_HEADER_L1+24)
15 #define PES_MIN 7
16 #define PES_H_MIN 9
17 
18 #define SYSTEM_START_CODE_S 0xB9
19 #define SYSTEM_START_CODE_E 0xFF
20 #define PACK_START 0xBA
21 #define SYS_START 0xBB
22 #define PROG_STREAM_MAP 0xBC
23 #define PRIVATE_STREAM1 0xBD
24 #define PADDING_STREAM 0xBE
25 #define PRIVATE_STREAM2 0xBF
26 #define AUDIO_STREAM_S 0xC0
27 #define AUDIO_STREAM_E 0xDF
28 #define VIDEO_STREAM_S 0xE0
29 #define VIDEO_STREAM_E 0xEF
30 #define ECM_STREAM 0xF0
31 #define EMM_STREAM 0xF1
32 #define DSM_CC_STREAM 0xF2
33 #define ISO13522_STREAM 0xF3
34 #define PROG_STREAM_DIR 0xFF
35 
36 //flags2
37 #define PTS_DTS_FLAGS 0xC0
38 #define ESCR_FLAG 0x20
39 #define ES_RATE_FLAG 0x10
40 #define DSM_TRICK_FLAG 0x08
41 #define ADD_CPY_FLAG 0x04
42 #define PES_CRC_FLAG 0x02
43 #define PES_EXT_FLAG 0x01
44 
45 //pts_dts flags
46 #define PTS_ONLY 0x80
47 #define PTS_DTS 0xC0
48 
49 #define MAX_PLENGTH 0xFFFF
50 #define MMAX_PLENGTH (8*MAX_PLENGTH)
51 
52 #define MAX_PTS (0x0000000200000000ULL)
53 #define MAX_PTS2 (300* MAX_PTS)
54 
55 typedef
56 struct ps_packet_{
57  uint8_t scr[6];
58  uint8_t mux_rate[3];
59  uint8_t stuff_length;
60  uint8_t *data;
61  uint8_t sheader_llength[2];
63  uint8_t rate_bound[3];
64  uint8_t audio_bound;
65  uint8_t video_bound;
66  uint8_t reserved;
67  int npes;
68 } ps_packet;
69 
70 
71 typedef
72 struct pes_in_s{
73  int type;
74  unsigned int found;
75  int withbuf;
76  uint8_t *buf;
78  uint8_t hbuf[260];
79  int ini_pos;
80  uint8_t cid;
81  uint32_t plength;
82  uint8_t plen[4];
83  uint8_t flag1;
84  uint8_t flag2;
85  uint8_t hlength;
86  uint8_t pts[5];
87  uint8_t dts[5];
88  int mpeg;
89  int done;
90  int which;
91  void *priv;
92 } pes_in_t;
93 
94 
95 void init_pes_in(pes_in_t *p, int type, ringbuffer *rb, int wi);
96 void get_pes (pes_in_t *p, uint8_t *buf, int count, void (*func)(pes_in_t *p));
97 void printpts(int64_t pts);
98 void printptss(int64_t pts);
99 int64_t ptsdiff(uint64_t pts1, uint64_t pts2);
100 uint64_t uptsdiff(uint64_t pts1, uint64_t pts2);
101 int ptscmp(uint64_t pts1, uint64_t pts2);
102 uint64_t ptsadd(uint64_t pts1, uint64_t pts2);
103 
104 
105 int write_pes_header(uint8_t id, int length , uint64_t PTS, uint64_t DTS,
106  uint8_t *obuf, int stuffing, uint8_t ptsdts);
107 void write_padding_pes( int pack_size, int extcnt,
108  uint64_t SCR, uint64_t muxr, uint8_t *buf);
109 int write_ac3_pes( int pack_size, int extcnt, int n, uint64_t pts,
110  uint64_t SCR,
111  uint32_t muxr, uint8_t *buf, int *alength, uint8_t ptsdts,
112  int nframes,int ac3_off, ringbuffer *ac3rbuffer);
113 int write_audio_pes( int pack_size, int extcnt, int n, uint64_t pts,
114  uint64_t SCR, uint32_t muxr, uint8_t *buf, int *alength,
115  uint8_t ptsdts, ringbuffer *arbuffer);
116 int write_video_pes( int pack_size, int extcnt, uint64_t vpts,
117  uint64_t vdts, uint64_t SCR, uint64_t muxr,
118  uint8_t *buf, int *vlength,
119  uint8_t ptsdts, ringbuffer *vrbuffer);
120 int write_nav_pack(int pack_size, int extcnt, uint64_t SCR, uint32_t muxr,
121  uint8_t *buf);
122 
123 
124 static inline void ptsdec(uint64_t *pts1, uint64_t pts2)
125 {
126  *pts1= uptsdiff(*pts1, pts2);
127 }
128 
129 static inline void ptsinc(uint64_t *pts1, uint64_t pts2)
130 {
131  *pts1 = (*pts1 + pts2)%MAX_PTS2;
132 }
133 
134 
135 
136 
137 #endif /*_PES_H_*/
int sheader_length
Definition: pes.h:62
static void ptsdec(uint64_t *pts1, uint64_t pts2)
Definition: pes.h:124
uint8_t video_bound
Definition: pes.h:65
uint8_t scr[6]
Definition: pes.h:57
uint64_t uptsdiff(uint64_t pts1, uint64_t pts2)
Definition: pes.c:104
void printptss(int64_t pts)
Definition: pes.c:59
void get_pes(pes_in_t *p, uint8_t *buf, int count, void(*func)(pes_in_t *p))
Definition: pes.c:165
uint8_t plen[4]
Definition: pes.h:82
uint8_t flag1
Definition: pes.h:83
void write_padding_pes(int pack_size, int extcnt, uint64_t SCR, uint64_t muxr, uint8_t *buf)
Definition: pes.c:687
int ini_pos
Definition: pes.h:79
uint8_t * buf
Definition: pes.h:76
void * priv
Definition: pes.h:91
int type
Definition: pes.h:73
uint8_t cid
Definition: pes.h:80
uint8_t rate_bound[3]
Definition: pes.h:63
ringbuffer * rbuf
Definition: pes.h:77
int mpeg
Definition: pes.h:88
int npes
Definition: pes.h:67
uint8_t audio_bound
Definition: pes.h:64
uint8_t dts[5]
Definition: pes.h:87
int write_ac3_pes(int pack_size, int extcnt, int n, uint64_t pts, uint64_t SCR, uint32_t muxr, uint8_t *buf, int *alength, uint8_t ptsdts, int nframes, int ac3_off, ringbuffer *ac3rbuffer)
Definition: pes.c:801
int write_audio_pes(int pack_size, int extcnt, int n, uint64_t pts, uint64_t SCR, uint32_t muxr, uint8_t *buf, int *alength, uint8_t ptsdts, ringbuffer *arbuffer)
Definition: pes.c:753
int write_pes_header(uint8_t id, int length, uint64_t PTS, uint64_t DTS, uint8_t *obuf, int stuffing, uint8_t ptsdts)
Definition: pes.c:607
uint8_t reserved
Definition: pes.h:66
void init_pes_in(pes_in_t *p, int type, ringbuffer *rb, int wi)
Definition: pes.c:147
uint8_t sheader_llength[2]
Definition: pes.h:61
int write_nav_pack(int pack_size, int extcnt, uint64_t SCR, uint32_t muxr, uint8_t *buf)
Definition: pes.c:857
uint8_t mux_rate[3]
Definition: pes.h:58
uint8_t hlength
Definition: pes.h:85
unsigned int found
Definition: pes.h:74
int which
Definition: pes.h:90
Definition: pes.h:71
uint8_t pts[5]
Definition: pes.h:86
int withbuf
Definition: pes.h:75
#define MAX_PTS2
Definition: pes.h:53
uint8_t hbuf[260]
Definition: pes.h:78
Definition: pes.h:55
struct pes_in_s pes_in_t
uint8_t * data
Definition: pes.h:60
uint8_t flag2
Definition: pes.h:84
int64_t ptsdiff(uint64_t pts1, uint64_t pts2)
Definition: pes.c:78
int done
Definition: pes.h:89
int ptscmp(uint64_t pts1, uint64_t pts2)
Definition: pes.c:116
struct ps_packet_ ps_packet
uint64_t ptsadd(uint64_t pts1, uint64_t pts2)
Definition: pes.c:140
void printpts(int64_t pts)
Definition: pes.c:42
int write_video_pes(int pack_size, int extcnt, uint64_t vpts, uint64_t vdts, uint64_t SCR, uint64_t muxr, uint8_t *buf, int *vlength, uint8_t ptsdts, ringbuffer *vrbuffer)
Definition: pes.c:700
uint8_t stuff_length
Definition: pes.h:59
uint32_t plength
Definition: pes.h:81
static void ptsinc(uint64_t *pts1, uint64_t pts2)
Definition: pes.h:129