initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / filempeg.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #ifndef FILEMPEG_H
23 #define FILEMPEG_H
24
25 #include "bitspopup.inc"
26 #include "condition.inc"
27 #include "file.inc"
28 #include "filebase.h"
29 #include "twolame.h"
30 #include "lame/lame.h"
31 #include "libzmpeg3.h"
32 #include "thread.h"
33
34
35 extern "C"
36 {
37
38
39 // Mpeg2enc prototypes
40 void mpeg2enc_init_buffers();
41 int mpeg2enc(int argc, char *argv[]);
42 void mpeg2enc_set_w(int width);
43 void mpeg2enc_set_h(int height);
44 void mpeg2enc_set_rate(double rate);
45 void mpeg2enc_set_input_buffers(int eof, char *y, char *u, char *v);
46
47
48
49
50
51 }
52
53 class FileMPEGVideo;
54
55 class FileMPEG : public FileBase
56 {
57 public:
58         FileMPEG(Asset *asset, File *file);
59         ~FileMPEG();
60
61         friend class FileMPEGVideo;
62
63         static void get_parameters(BC_WindowBase *parent_window, 
64                 Asset *asset, 
65                 BC_WindowBase* &format_window,
66                 int audio_options,
67                 int video_options);
68
69         static int check_sig(Asset *asset);
70
71 // Get extra info for info dialog.
72         static void get_info(char *title_path, char *path, char *text);
73         int open_file(int rd, int wr);
74         int close_file();
75         int create_index();
76
77
78         int get_index(char *index_path);
79         int set_video_position(int64_t x);
80         int set_audio_position(int64_t x);
81         int write_samples(double **buffer, 
82                         int64_t len);
83         int write_frames(VFrame ***frames, int len);
84
85         int read_frame(VFrame *frame);
86         int read_samples(double *buffer, int64_t len);
87
88         int64_t get_memory_usage();
89         int set_program(int no);
90         int get_cell_time(int no, double &time);
91         int get_system_time(int64_t &tm);
92         int get_video_pid(int track);
93         int get_video_info(int track, int &pid, double &framerate,
94                 int &width, int &height, char *title=0);
95         int select_video_stream(Asset *asset, int vstream);
96         int select_audio_stream(Asset *asset, int astream);
97         int get_thumbnail(int stream,
98                 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh);
99         int set_skimming(int track, int skim, skim_fn fn, void *vp);
100         int skim_video(int track, void *vp, skim_fn fn);
101         int get_audio_for_video(int vstream, int astream, int64_t &channel_mask);
102
103 // Direct copy routines
104         static int get_best_colormodel(Asset *asset, int driver);
105         int colormodel_supported(int colormodel);
106 // zmpeg3<->BC colormodels
107         static int zmpeg3_cmdl(int colormodel);
108         static int bc_colormodel(int cmdl);
109         static const char *zmpeg3_cmdl_name(int cmdl);
110 // This file can copy frames directly from the asset
111         int can_copy_from(Asset *asset, int64_t position); 
112         static const char *strtocompression(char *string);
113         static const char *compressiontostr(char *string);
114
115
116 private:
117         void to_streamchannel(int channel, int &stream_out, int &channel_out);
118         int reset_parameters_derived();
119 // File descriptor for decoder
120         mpeg3_t *fd;
121
122 // Thread for video encoder
123         FileMPEGVideo *video_out;
124 // Command line for video encoder
125         ArrayList<char*> vcommand_line;
126         void append_vcommand_line(const char *string);
127
128 // DVB capture
129         int recd_fd;
130         int record_fd() { return recd_fd; }
131
132 // MJPEGtools encoder
133         FILE *mjpeg_out;        
134         int mjpeg_error;
135         Condition *next_frame_lock;
136         Condition *next_frame_done;
137         int mjpeg_eof;
138         int wrote_header;
139         unsigned char *mjpeg_y; 
140         unsigned char *mjpeg_u; 
141         unsigned char *mjpeg_v; 
142         char mjpeg_command[BCTEXTLEN];
143
144 // skimmer
145         static int skimming(void *vp, int track);
146         skim_fn skim_callback;
147         void *skim_data;
148         int skim_result;
149 // toc scan commercial detection
150         static int toc_nail(void *vp, int track);
151
152 // Temporary for color conversion
153         VFrame *temp_frame;
154
155         unsigned char *twolame_temp, *twolame_out;
156         int twolame_allocation;
157         int twolame_result;
158         FILE *twofp;
159         twolame_options *twopts;
160
161         float *lame_temp[2];
162         int lame_allocation;
163         char *lame_output;
164         int lame_output_allocation;
165         FILE *lame_fd;
166 // Lame puts 0 before stream
167         int lame_started;
168
169         lame_global_flags *lame_global;
170         double *weight;
171 };
172
173
174 class FileMPEGVideo : public Thread
175 {
176 public:
177         FileMPEGVideo(FileMPEG *file);
178         ~FileMPEGVideo();
179
180         void run();
181
182         FileMPEG *file;
183 };
184
185 class MPEGConfigAudioPopup;
186 class MPEGABitrate;
187
188
189 class MPEGConfigAudio : public BC_Window
190 {
191 public:
192         MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
193         ~MPEGConfigAudio();
194
195         void create_objects();
196         int close_event();
197
198         BC_WindowBase *parent_window;
199         MPEGABitrate *bitrate;
200         char string[BCTEXTLEN];
201         Asset *asset;
202 };
203
204
205 class MPEGLayer : public BC_PopupMenu
206 {
207 public:
208         MPEGLayer(int x, int y, MPEGConfigAudio *gui);
209         void create_objects();
210         int handle_event();
211         static int string_to_layer(char *string);
212         static char* layer_to_string(int derivative);
213         
214         MPEGConfigAudio *gui;
215 };
216
217 class MPEGABitrate : public BC_PopupMenu
218 {
219 public:
220         MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
221
222         void create_objects();
223         void set_layer(int layer);
224
225         int handle_event();
226         static int string_to_bitrate(char *string);
227         static char* bitrate_to_string(char *string, int bitrate);
228         
229         MPEGConfigAudio *gui;
230 };
231
232
233
234 class MPEGConfigVideo;
235
236
237
238 class MPEGPreset : public BC_PopupMenu
239 {
240 public:
241         MPEGPreset(int x, int y, MPEGConfigVideo *gui);
242         void create_objects();
243         int handle_event();
244         static int string_to_value(char *string);
245         static char* value_to_string(int value);
246         MPEGConfigVideo *gui;
247 };
248
249 class MPEGColorModel : public BC_PopupMenu
250 {
251 public:
252         MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
253         void create_objects();
254         int handle_event();
255         static int string_to_cmodel(char *string);
256         static char* cmodel_to_string(int cmodel);
257         
258         MPEGConfigVideo *gui;
259 };
260
261
262 class MPEGDerivative : public BC_PopupMenu
263 {
264 public:
265         MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
266         void create_objects();
267         int handle_event();
268         static int string_to_derivative(char *string);
269         static char* derivative_to_string(int derivative);
270         
271         MPEGConfigVideo *gui;
272 };
273
274 class MPEGBitrate : public BC_TextBox
275 {
276 public:
277         MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
278         int handle_event();
279         MPEGConfigVideo *gui;
280 };
281
282 class MPEGQuant : public BC_TumbleTextBox
283 {
284 public:
285         MPEGQuant(int x, int y, MPEGConfigVideo *gui);
286         int handle_event();
287         MPEGConfigVideo *gui;
288 };
289
290 class MPEGIFrameDistance : public BC_TumbleTextBox
291 {
292 public:
293         MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
294         int handle_event();
295         MPEGConfigVideo *gui;
296 };
297
298 class MPEGPFrameDistance : public BC_TumbleTextBox
299 {
300 public:
301         MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
302         int handle_event();
303         MPEGConfigVideo *gui;
304 };
305
306 class MPEGFixedBitrate : public BC_Radial
307 {
308 public:
309         MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
310         int handle_event();
311         MPEGConfigVideo *gui;
312 };
313
314 class MPEGFixedQuant : public BC_Radial
315 {
316 public:
317         MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
318         int handle_event();
319         MPEGConfigVideo *gui;
320 };
321
322 class MPEGSeqCodes : public BC_CheckBox
323 {
324 public:
325         MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
326         int handle_event();
327         MPEGConfigVideo *gui;
328 };
329
330
331
332
333 class MPEGConfigVideo : public BC_Window
334 {
335 public:
336         MPEGConfigVideo(BC_WindowBase *parent_window, 
337                 Asset *asset);
338         ~MPEGConfigVideo();
339
340         void create_objects();
341         int close_event();
342         void delete_cmodel_objs();
343         void reset_cmodel();
344         void update_cmodel_objs();
345
346         BC_WindowBase *parent_window;
347         Asset *asset;
348         MPEGPreset *preset;
349         MPEGColorModel *cmodel;
350         MPEGDerivative *derivative;
351         MPEGBitrate *bitrate;
352         MPEGFixedBitrate *fixed_bitrate;
353         MPEGQuant *quant;
354         MPEGFixedQuant *fixed_quant;
355         MPEGIFrameDistance *iframe_distance;
356         MPEGPFrameDistance *pframe_distance;
357         BC_CheckBox *top_field_first;
358         BC_CheckBox *progressive;
359         BC_CheckBox *denoise;
360         BC_CheckBox *seq_codes;
361
362         ArrayList<BC_Title*> titles;
363         ArrayList<BC_SubWindow*> tools;
364 };
365
366
367 #endif