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 <cstdint>
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 struct ps_packet {
56  uint8_t scr[6];
57  uint8_t mux_rate[3];
58  uint8_t stuff_length;
59  uint8_t *data;
60  uint8_t sheader_llength[2];
62  uint8_t rate_bound[3];
63  uint8_t audio_bound;
64  uint8_t video_bound;
65  uint8_t reserved;
66  int npes;
67 };
68 
69 
70 struct pes_in_t {
71  int type;
72  unsigned int found;
73  int withbuf;
74  uint8_t *buf;
76  uint8_t hbuf[260];
77  int ini_pos;
78  uint8_t cid;
79  uint32_t plength;
80  uint8_t plen[4];
81  uint8_t flag1;
82  uint8_t flag2;
83  uint8_t hlength;
84  uint8_t pts[5];
85  uint8_t dts[5];
86  int mpeg;
87  bool done;
88  int which;
89  void *priv;
90 };
91 
92 
93 void init_pes_in(pes_in_t *p, int type, ringbuffer *rb, int wi);
94 void get_pes (pes_in_t *p, uint8_t *buf, int count, void (*func)(pes_in_t *p));
95 void printpts(int64_t pts);
96 void printptss(int64_t pts);
97 int64_t ptsdiff(uint64_t pts1, uint64_t pts2);
98 uint64_t uptsdiff(uint64_t pts1, uint64_t pts2);
99 int ptscmp(uint64_t pts1, uint64_t pts2);
100 uint64_t ptsadd(uint64_t pts1, uint64_t pts2);
101 
102 
103 int write_pes_header(uint8_t id, int length , uint64_t PTS, uint64_t DTS,
104  uint8_t *obuf, int stuffing, uint8_t ptsdts);
105 void write_padding_pes( int pack_size, int extcnt,
106  uint64_t SCR, uint64_t muxr, uint8_t *buf);
107 int write_ac3_pes( int pack_size, int extcnt, int n, uint64_t pts,
108  uint64_t SCR,
109  uint32_t muxr, uint8_t *buf, int *alength, uint8_t ptsdts,
110  int nframes,int ac3_off, ringbuffer *ac3rbuffer);
111 int write_audio_pes( int pack_size, int extcnt, int n, uint64_t pts,
112  uint64_t SCR, uint32_t muxr, uint8_t *buf, int *alength,
113  uint8_t ptsdts, ringbuffer *arbuffer);
114 int write_video_pes( int pack_size, int extcnt, uint64_t vpts,
115  uint64_t vdts, uint64_t SCR, uint64_t muxr,
116  uint8_t *buf, int *vlength,
117  uint8_t ptsdts, ringbuffer *vrbuffer);
118 int write_nav_pack(int pack_size, int extcnt, uint64_t SCR, uint32_t muxr,
119  uint8_t *buf);
120 
121 
122 static inline void ptsdec(uint64_t *pts1, uint64_t pts2)
123 {
124  *pts1= uptsdiff(*pts1, pts2);
125 }
126 
127 static inline void ptsinc(uint64_t *pts1, uint64_t pts2)
128 {
129  *pts1 = (*pts1 + pts2)%MAX_PTS2;
130 }
131 
132 #endif /* PES_H */
pes_in_t::priv
void * priv
Definition: pes.h:89
write_padding_pes
void write_padding_pes(int pack_size, int extcnt, uint64_t SCR, uint64_t muxr, uint8_t *buf)
Definition: pes.cpp:677
ringbuffer.h
pes_in_t::hbuf
uint8_t hbuf[260]
Definition: pes.h:76
ptsdec
static void ptsdec(uint64_t *pts1, uint64_t pts2)
Definition: pes.h:122
pes_in_t::dts
uint8_t dts[5]
Definition: pes.h:85
ptsadd
uint64_t ptsadd(uint64_t pts1, uint64_t pts2)
Definition: pes.cpp:139
ringbuffer
Definition: ringbuffer.h:39
get_pes
void get_pes(pes_in_t *p, uint8_t *buf, int count, void(*func)(pes_in_t *p))
Definition: pes.cpp:164
pes_in_t::type
int type
Definition: pes.h:71
printpts
void printpts(int64_t pts)
Definition: pes.cpp:43
pes_in_t::hlength
uint8_t hlength
Definition: pes.h:83
ps_packet
Definition: pes.h:55
ps_packet::stuff_length
uint8_t stuff_length
Definition: pes.h:58
ps_packet::reserved
uint8_t reserved
Definition: pes.h:65
pes_in_t::pts
uint8_t pts[5]
Definition: pes.h:84
ptsinc
static void ptsinc(uint64_t *pts1, uint64_t pts2)
Definition: pes.h:127
pes_in_t::rbuf
ringbuffer * rbuf
Definition: pes.h:75
ps_packet::data
uint8_t * data
Definition: pes.h:59
ps_packet::sheader_length
int sheader_length
Definition: pes.h:61
pes_in_t::buf
uint8_t * buf
Definition: pes.h:74
write_nav_pack
int write_nav_pack(int pack_size, int extcnt, uint64_t SCR, uint32_t muxr, uint8_t *buf)
Definition: pes.cpp:837
uptsdiff
uint64_t uptsdiff(uint64_t pts1, uint64_t pts2)
Definition: pes.cpp:104
pes_in_t::found
unsigned int found
Definition: pes.h:72
pes_in_t::plen
uint8_t plen[4]
Definition: pes.h:80
MAX_PTS2
#define MAX_PTS2
Definition: pes.h:53
write_ac3_pes
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.cpp:784
hardwareprofile.config.p
p
Definition: config.py:33
write_video_pes
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.cpp:689
write_audio_pes
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.cpp:739
ps_packet::scr
uint8_t scr[6]
Definition: pes.h:56
pes_in_t::which
int which
Definition: pes.h:88
printptss
void printptss(int64_t pts)
Definition: pes.cpp:60
ps_packet::npes
int npes
Definition: pes.h:66
pes_in_t::flag1
uint8_t flag1
Definition: pes.h:81
pes_in_t::done
bool done
Definition: pes.h:87
write_pes_header
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.cpp:602
ps_packet::sheader_llength
uint8_t sheader_llength[2]
Definition: pes.h:60
ps_packet::video_bound
uint8_t video_bound
Definition: pes.h:64
pes_in_t::flag2
uint8_t flag2
Definition: pes.h:82
init_pes_in
void init_pes_in(pes_in_t *p, int type, ringbuffer *rb, int wi)
Definition: pes.cpp:146
ptsdiff
int64_t ptsdiff(uint64_t pts1, uint64_t pts2)
Definition: pes.cpp:78
pes_in_t::mpeg
int mpeg
Definition: pes.h:86
pes_in_t::ini_pos
int ini_pos
Definition: pes.h:77
pes_in_t
Definition: pes.h:70
pes_in_t::plength
uint32_t plength
Definition: pes.h:79
ps_packet::mux_rate
uint8_t mux_rate[3]
Definition: pes.h:57
ps_packet::audio_bound
uint8_t audio_bound
Definition: pes.h:63
ps_packet::rate_bound
uint8_t rate_bound[3]
Definition: pes.h:62
ptscmp
int ptscmp(uint64_t pts1, uint64_t pts2)
Definition: pes.cpp:114
pes_in_t::withbuf
int withbuf
Definition: pes.h:73
pes_in_t::cid
uint8_t cid
Definition: pes.h:78