]> git.vomp.tv Git - vompserver.git/blob - libdvbmpeg/cpptools.hh
Initial import
[vompserver.git] / libdvbmpeg / cpptools.hh
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 #include <fstream>
30 #include <sstream>
31 #include <iostream>
32 #include <iomanip>
33 using namespace std;
34
35
36 #ifndef _CPPTOOLS_HH_
37 #define _CPPTOOLS_HH_
38
39 #include "ctools.h"
40
41
42 class PES_Packet{
43         int info;
44         pes_packet p;
45 public:
46         PES_Packet(){
47                 info = 0;
48                 init_pes(&p);
49         }
50
51         ~PES_Packet(){
52                 if (p.pack_header)
53                         delete [] p.pack_header;
54                 if (p.pes_ext)
55                         delete [] p.pes_ext;
56                 if (p.pes_pckt_data)
57                         delete [] p.pes_pckt_data;
58                 if (p.mpeg1_headr)
59                         delete [] p.mpeg1_headr;
60         }
61         
62         inline void init(){
63                 if (p.pack_header)
64                         delete [] p.pack_header;
65                 if (p.pes_ext)
66                         delete [] p.pes_ext;
67                 if (p.pes_pckt_data)
68                         delete [] p.pes_pckt_data;
69                 if (p.mpeg1_headr)
70                         delete [] p.mpeg1_headr;
71
72                 info = 0;
73                 init_pes(&p);
74         }
75
76         inline pes_packet *P(){
77                 return &p;
78         }
79
80         inline void setlength(){
81                 setlength_pes(&p);
82                 if (p.length)
83                         p.pes_pckt_data = new uint8_t[p.length];
84         }
85
86         inline void Nlength(){
87                 nlength_pes(&p);
88                 p.pes_pckt_data = new uint8_t[p.length];
89         }
90
91
92         inline uint8_t &Stream_ID(){
93                 return p.stream_id;
94         }
95
96         inline uint8_t &Flags1(){
97                 return p.flags1;
98         }
99
100         inline uint8_t &Flags2(){
101                 return p.flags2;
102         }
103
104         inline uint32_t &Length(){
105                 return p.length;
106         }
107         
108         inline uint8_t &HLength(){
109                 return p.pes_hlength;
110         }
111
112         inline uint8_t &Stuffing(){
113                 return p.stuffing;
114         }
115
116         inline uint8_t *Data(){
117                 return p.pes_pckt_data;
118         }
119         
120         inline int has_pts(){
121                 return (p.flags2 & PTS_DTS);
122         }
123
124         inline int &MPEG(){
125                 return p.mpeg;
126         }
127         inline uint8_t *PTS(){
128                 return p.pts;
129         }
130
131         inline uint8_t *DTS(){
132                 return p.dts;
133         }
134
135         inline int &Info(){
136                 return info;
137         }
138   
139   
140
141         inline uint8_t high_pts(){
142                 if (has_pts())
143                         return ((p.pts[0] & 0x08)>>3);
144                 else
145                         return 0;
146         }
147
148         inline uint8_t high_dts(){
149                 return ((p.dts[0] & 0x08)>>3);
150         }
151
152         inline int WDTS(){
153                 int w_dts;
154                 w_dts = (int)trans_pts_dts(p.dts);
155                 return w_dts;
156         }
157
158         inline int WPTS(){
159                 int w_dts;
160                 w_dts = (int)trans_pts_dts(p.pts);
161                 return w_dts;
162         }
163
164         friend ostream & operator << (ostream & stream, PES_Packet & x);
165         friend istream & operator >> (istream & stream, PES_Packet & x);
166
167 };
168
169
170 class TS_Packet{
171         ts_packet p;
172         int info;
173
174 public:
175         TS_Packet(){
176                 init_ts(&p);
177                 info = 0;
178         }
179
180         ~TS_Packet(){
181                 if (p.priv_dat)
182                         delete [] p.priv_dat;
183         }
184         
185         inline void init(){
186                 if (p.priv_dat)
187                         delete [] p.priv_dat;
188
189                 init_ts(&p);
190                 info = 0;
191         }
192
193         inline ts_packet *P(){
194                 return &p;
195         }
196                 
197         inline int &Rest(){
198                 return p.rest;
199         }
200
201         inline uint8_t *Data(){
202                 return p.data;
203         }
204
205         inline short PID(){
206                 return pid_ts(&p);
207         }
208
209         inline uint8_t FLAG1(){
210                 return (p.pid[0] & ~PID_MASK_HI);
211         }
212
213         inline int &Info(){
214                 return info;
215         }
216
217         friend ostream & operator << (ostream & stream, TS_Packet & x);
218         friend istream & operator >> (istream & stream, TS_Packet & x);
219 };
220
221
222 class PS_Packet{
223         int info;
224         ps_packet p;
225 public:
226
227         PS_Packet(){
228                 init_ps(&p);
229                 info = 0;
230         }
231         
232         ~PS_Packet(){
233                 if (p.data)
234                         delete [] p.data;
235         }
236
237         inline void init(){
238                 if (p.data)
239                         delete [] p.data;
240
241                 init_ps(&p);
242                 info = 0;
243         }
244
245         inline ps_packet *P(){
246                 return &p;
247         }
248
249         inline int MUX(){
250                 return mux_ps(&p);
251         }
252
253         inline int Rate(){
254                 return rate_ps(&p);
255         }
256
257         inline void setlength(){
258                 setlength_ps(&p);
259                 p.data = new uint8_t[p.sheader_length];
260         }
261
262         inline int Stuffing(){
263                 return p.stuff_length & PACK_STUFF_MASK;
264         }
265
266         inline int NPES(){
267                 return p.npes;
268         }
269
270         inline int &MPEG(){
271                 return p.mpeg;
272         }
273
274         inline uint8_t &operator()(int l){
275                 return p.data[l];
276         }
277
278         inline char * Data() {
279                 return (char *)p.data+p.stuff_length;
280         }
281
282         inline int &SLENGTH(){
283                 return p.sheader_length;
284         }
285         
286         inline int &Info(){
287                 return info;
288         }
289         
290         uint32_t SCR_base(){
291                 return scr_base_ps(&p);
292         }
293
294         uint16_t SCR_ext(){
295                 return scr_ext_ps(&p);
296         }
297
298         friend ostream & operator << (ostream & stream, PS_Packet & x);
299         friend istream & operator >> (istream & stream, PS_Packet & x);
300 };
301
302
303 typedef void (* FILTER)(istream &in, ostream &out);
304
305 typedef struct thread_args_{
306         FILTER function;
307         int *fd;
308         int in;
309         int out;
310 } thread_args;
311
312
313 void extract_audio_from_PES(istream &in, ostream &out);
314 void extract_video_from_PES(istream &in, ostream &out);
315 void extract_es_audio_from_PES(istream &in, ostream &out);
316 void extract_es_video_from_PES(istream &in, ostream &out);
317 int TS_PIDS(istream &in, ostream &out);
318 int ifilter (istream &in, FILTER function);
319 int ofilter (istream &in, FILTER function);
320 int itfilter (int in, FILTER function);
321 int otfilter (istream &in, FILTER function);
322 int stream_type(int fd);
323 int stream_type(istream &stream);
324 int tv_norm(istream &fin);
325
326 void analyze(istream &fin);
327
328
329 #endif //_CPPTOOLS_HH_
330