]> git.vomp.tv Git - vompserver.git/blob - libdvbmpeg/transform.h
Initial import
[vompserver.git] / libdvbmpeg / transform.h
1 /*
2  *  dvb-mpegtools for the Siemens Fujitsu DVB PCI card
3  *
4  * Copyright (C) 2000, 2001 Marcus Metzler 
5  *            for convergence integrated media GmbH
6  * Copyright (C) 2002  Marcus Metzler 
7  * 
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  * 
13
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  * 
19
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24  * 
25
26  * The author can be reached at mocm@metzlerbros.de, 
27
28  */
29
30 #ifndef _TS_TRANSFORM_H_
31 #define _TS_TRANSFORM_H_
32
33 #include <stdint.h>
34 #include <netinet/in.h>
35 #include <stdio.h>
36 #include <unistd.h>
37 #include "remux.h"
38
39 #define PROG_STREAM_MAP  0xBC
40 #ifndef PRIVATE_STREAM1
41 #define PRIVATE_STREAM1  0xBD
42 #endif
43 #define PADDING_STREAM   0xBE
44 #ifndef PRIVATE_STREAM2
45 #define PRIVATE_STREAM2  0xBF
46 #endif
47 #define AUDIO_STREAM_S   0xC0
48 #define AUDIO_STREAM_E   0xDF
49 #define VIDEO_STREAM_S   0xE0
50 #define VIDEO_STREAM_E   0xEF
51 #define ECM_STREAM       0xF0
52 #define EMM_STREAM       0xF1
53 #define DSM_CC_STREAM    0xF2
54 #define ISO13522_STREAM  0xF3
55 #define PROG_STREAM_DIR  0xFF
56
57 #define BUFFYSIZE    10*MAX_PLENGTH
58 #define MAX_PTS      8192
59 #define MAX_FRAME    8192
60 #define MAX_PACK_L   4096
61 #define PS_HEADER_L1    14
62 #define PS_HEADER_L2    (PS_HEADER_L1+18)
63 #define MAX_H_SIZE   (PES_H_MIN + PS_HEADER_L1 + 5)
64 #define PES_MIN         7
65 #define PES_H_MIN       9
66
67 //flags2
68 #define PTS_DTS_FLAGS    0xC0
69 #define ESCR_FLAG        0x20
70 #define ES_RATE_FLAG     0x10
71 #define DSM_TRICK_FLAG   0x08
72 #define ADD_CPY_FLAG     0x04
73 #define PES_CRC_FLAG     0x02
74 #define PES_EXT_FLAG     0x01
75
76 //pts_dts flags 
77 #define PTS_ONLY         0x80
78 #define PTS_DTS          0xC0
79
80 #define TS_SIZE        188
81 #define TRANS_ERROR    0x80
82 #define PAY_START      0x40
83 #define TRANS_PRIO     0x20
84 #define PID_MASK_HI    0x1F
85 //flags
86 #define TRANS_SCRMBL1  0x80
87 #define TRANS_SCRMBL2  0x40
88 #define ADAPT_FIELD    0x20
89 #define PAYLOAD        0x10
90 #define COUNT_MASK     0x0F
91
92 // adaptation flags
93 #define DISCON_IND     0x80
94 #define RAND_ACC_IND   0x40
95 #define ES_PRI_IND     0x20
96 #define PCR_FLAG       0x10
97 #define OPCR_FLAG      0x08
98 #define SPLICE_FLAG    0x04
99 #define TRANS_PRIV     0x02
100 #define ADAP_EXT_FLAG  0x01
101
102 // adaptation extension flags
103 #define LTW_FLAG       0x80
104 #define PIECE_RATE     0x40
105 #define SEAM_SPLICE    0x20
106
107
108 #define MAX_PLENGTH 0xFFFF
109 #define MMAX_PLENGTH (8*MAX_PLENGTH)
110
111 #ifdef __cplusplus
112 extern "C" {
113 #endif                          /* __cplusplus */
114
115 #define P2P_LENGTH 2048
116
117         enum{NOPES, AUDIO, VIDEO, AC3};
118
119         typedef struct p2pstruct {
120                 int found;
121                 uint8_t buf[MMAX_PLENGTH];
122                 uint8_t cid;
123                 uint8_t subid;
124                 uint32_t plength;
125                 uint8_t plen[2];
126                 uint8_t flag1;
127                 uint8_t flag2;
128                 uint8_t hlength;
129                 uint8_t pts[5];
130                 int mpeg;
131                 uint8_t check;
132                 int fd1;
133                 int fd2;
134                 int es;
135                 int filter;
136                 int which;
137                 int done;
138                 int repack;
139                 uint16_t bigend_repack;
140                 void (*func)(uint8_t *buf, int count, void *p);
141                 int startv;
142                 int starta;
143                 int64_t apts;
144                 int64_t vpts;
145                 uint16_t pid;
146                 uint16_t pida;
147                 uint16_t pidv;
148                 uint8_t acounter;
149                 uint8_t vcounter;
150                 uint8_t count0;
151                 uint8_t count1;
152                 void *data;
153         } p2p;
154
155         
156         uint64_t trans_pts_dts(uint8_t *pts);
157         int write_ts_header(uint16_t pid, uint8_t *counter, int pes_start, 
158                             uint8_t *buf, uint8_t length);
159         uint16_t get_pid(uint8_t *pid);
160         void init_p2p(p2p *p, void (*func)(uint8_t *buf, int count, void *p),
161                       int repack);
162         void get_pes (uint8_t *buf, int count, p2p *p, void (*func)(p2p *p));
163         void get_pes (uint8_t *buf, int count, p2p *p, void (*func)(p2p *p));
164         void pes_repack(p2p *p);
165         void setup_pes2ts( p2p *p, uint32_t pida, uint32_t pidv, 
166                            void (*ts_write)(uint8_t *buf, int count, void *p));
167         void kpes_to_ts( p2p *p,uint8_t *buf ,int count );
168         void setup_ts2pes( p2p *pa, p2p *pv, uint32_t pida, uint32_t pidv, 
169                            void (*pes_write)(uint8_t *buf, int count, void *p));
170         void kts_to_pes( p2p *p, uint8_t *buf);
171         void pes_repack(p2p *p);
172         void extract_from_pes(int fdin, int fdout, uint8_t id, int es);
173         int64_t pes_dmx(int fdin, int fdouta, int fdoutv, int es);
174         void pes_to_ts2( int fdin, int fdout, uint16_t pida, uint16_t pidv);
175         void ts_to_pes( int fdin, uint16_t pida, uint16_t pidv, int pad);
176         int get_ainfo(uint8_t *mbuf, int count, AudioInfo *ai, int pr);
177         int get_vinfo(uint8_t *mbuf, int count, VideoInfo *vi, int pr);
178         int get_ac3info(uint8_t *mbuf, int count, AudioInfo *ai, int pr);
179         void filter_audio_from_pes(int fdin, int fdout, uint8_t id, 
180                                    uint8_t subid);
181
182
183 //instant repack
184
185         typedef struct ipack_s {
186                 int size;
187                 int size_orig;
188                 int found;
189                 int ps;
190                 int has_ai;
191                 int has_vi;
192                 AudioInfo ai;
193                 VideoInfo vi;
194                 uint8_t *buf;
195                 uint8_t cid;
196                 uint32_t plength;
197                 uint8_t plen[2];
198                 uint8_t flag1;
199                 uint8_t flag2;
200                 uint8_t hlength;
201                 uint8_t pts[5];
202                 uint8_t last_pts[5];
203                 int mpeg;
204                 uint8_t check;
205                 int which;
206                 int done;
207                 void *data;
208                 void *data2;
209                 void (*func)(uint8_t *buf,  int size, void *priv);
210                 int count;
211                 int start;
212                 int fd;
213                 int fd1;
214                 int fd2;
215                 int ffd;
216                 int playing;
217         } ipack;
218
219         void instant_repack (uint8_t *buf, int count, ipack *p);
220         void init_ipack(ipack *p, int size,
221                         void (*func)(uint8_t *buf,  int size, void *priv),
222                         int pad);
223         void free_ipack(ipack * p);
224         void send_ipack(ipack *p);
225         void reset_ipack(ipack *p);                  
226         void ps_pes(ipack *p);
227         // use with ipack structure, repack size and callback func 
228
229         int64_t ts_demux(int fd_in, int fdv_out,int fda_out,uint16_t pida,
230                           uint16_t pidv, int es);
231
232         void ts2es(int fdin,  uint16_t pidv);
233         void ts2es_opt(int fdin,  uint16_t pidv, ipack *p, int verb);
234         void insert_pat_pmt( int fdin, int fdout);
235         void change_aspect(int fdin, int fdout, int aspect);
236
237 // SV: all made non-static:
238         void pes_in_ts(p2p *p);
239
240 // SV: moved from .c file:
241 #define IPACKS 2048
242
243 #ifdef __cplusplus
244 }
245 #endif                          /* __cplusplus */
246
247 #endif /* _TS_TRANSFORM_H_*/
248
249
250