Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / 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, int len);
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
113 private:
114         void to_streamchannel(int channel, int &stream_out, int &channel_out);
115         int reset_parameters_derived();
116 // File descriptor for decoder
117         mpeg3_t *fd;
118
119 // Thread for video encoder
120         FileMPEGVideo *video_out;
121 // Command line for video encoder
122         ArrayList<char*> vcommand_line;
123         void append_vcommand_line(const char *string);
124
125 // DVB capture
126         int recd_fd;
127         int record_fd() { return recd_fd; }
128
129 // MJPEGtools encoder
130         FILE *mjpeg_out;        
131         int mjpeg_error;
132         Condition *next_frame_lock;
133         Condition *next_frame_done;
134         int mjpeg_eof;
135         int wrote_header;
136         unsigned char *mjpeg_y; 
137         unsigned char *mjpeg_u; 
138         unsigned char *mjpeg_v; 
139         char mjpeg_command[BCTEXTLEN];
140
141 // skimmer
142         static int skimming(void *vp, int track);
143         skim_fn skim_callback;
144         void *skim_data;
145         int skim_result;
146 // toc scan commercial detection
147         static int toc_nail(void *vp, int track);
148
149 // Temporary for color conversion
150         VFrame *temp_frame;
151
152         unsigned char *twolame_temp, *twolame_out;
153         int twolame_allocation;
154         int twolame_result;
155         FILE *twofp;
156         twolame_options *twopts;
157
158         float *lame_temp[2];
159         int lame_allocation;
160         char *lame_output;
161         int lame_output_allocation;
162         FILE *lame_fd;
163 // Lame puts 0 before stream
164         int lame_started;
165
166         lame_global_flags *lame_global;
167         double *weight;
168 };
169
170
171 class FileMPEGVideo : public Thread
172 {
173 public:
174         FileMPEGVideo(FileMPEG *file);
175         ~FileMPEGVideo();
176
177         void run();
178
179         FileMPEG *file;
180 };
181
182 class MPEGConfigAudioPopup;
183 class MPEGABitrate;
184
185
186 class MPEGConfigAudio : public BC_Window
187 {
188 public:
189         MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
190         ~MPEGConfigAudio();
191
192         void create_objects();
193         int close_event();
194
195         BC_WindowBase *parent_window;
196         MPEGABitrate *bitrate;
197         char string[BCTEXTLEN];
198         Asset *asset;
199 };
200
201
202 class MPEGLayer : public BC_PopupMenu
203 {
204 public:
205         MPEGLayer(int x, int y, MPEGConfigAudio *gui);
206         void create_objects();
207         int handle_event();
208         static int string_to_layer(char *string);
209         static char* layer_to_string(int derivative);
210         
211         MPEGConfigAudio *gui;
212 };
213
214 class MPEGABitrate : public BC_PopupMenu
215 {
216 public:
217         MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
218
219         void create_objects();
220         void set_layer(int layer);
221
222         int handle_event();
223         static int string_to_bitrate(char *string);
224         static char* bitrate_to_string(char *string, int bitrate);
225         
226         MPEGConfigAudio *gui;
227 };
228
229
230
231 class MPEGConfigVideo;
232
233
234
235 class MPEGPreset : public BC_PopupMenu
236 {
237 public:
238         MPEGPreset(int x, int y, MPEGConfigVideo *gui);
239         void create_objects();
240         int handle_event();
241         static int string_to_value(char *string);
242         static char* value_to_string(int value);
243         MPEGConfigVideo *gui;
244 };
245
246 class MPEGColorModel : public BC_PopupMenu
247 {
248 public:
249         MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
250         void create_objects();
251         int handle_event();
252         static int string_to_cmodel(char *string);
253         static char* cmodel_to_string(int cmodel);
254         
255         MPEGConfigVideo *gui;
256 };
257
258
259 class MPEGDerivative : public BC_PopupMenu
260 {
261 public:
262         MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
263         void create_objects();
264         int handle_event();
265         static int string_to_derivative(char *string);
266         static char* derivative_to_string(int derivative);
267         
268         MPEGConfigVideo *gui;
269 };
270
271 class MPEGBitrate : public BC_TextBox
272 {
273 public:
274         MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
275         int handle_event();
276         MPEGConfigVideo *gui;
277 };
278
279 class MPEGQuant : public BC_TumbleTextBox
280 {
281 public:
282         MPEGQuant(int x, int y, MPEGConfigVideo *gui);
283         int handle_event();
284         MPEGConfigVideo *gui;
285 };
286
287 class MPEGIFrameDistance : public BC_TumbleTextBox
288 {
289 public:
290         MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
291         int handle_event();
292         MPEGConfigVideo *gui;
293 };
294
295 class MPEGPFrameDistance : public BC_TumbleTextBox
296 {
297 public:
298         MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
299         int handle_event();
300         MPEGConfigVideo *gui;
301 };
302
303 class MPEGFixedBitrate : public BC_Radial
304 {
305 public:
306         MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
307         int handle_event();
308         MPEGConfigVideo *gui;
309 };
310
311 class MPEGFixedQuant : public BC_Radial
312 {
313 public:
314         MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
315         int handle_event();
316         MPEGConfigVideo *gui;
317 };
318
319 class MPEGSeqCodes : public BC_CheckBox
320 {
321 public:
322         MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
323         int handle_event();
324         MPEGConfigVideo *gui;
325 };
326
327
328
329
330 class MPEGConfigVideo : public BC_Window
331 {
332 public:
333         MPEGConfigVideo(BC_WindowBase *parent_window, 
334                 Asset *asset);
335         ~MPEGConfigVideo();
336
337         void create_objects();
338         int close_event();
339         void delete_cmodel_objs();
340         void reset_cmodel();
341         void update_cmodel_objs();
342
343         BC_WindowBase *parent_window;
344         Asset *asset;
345         MPEGPreset *preset;
346         MPEGColorModel *cmodel;
347         MPEGDerivative *derivative;
348         MPEGBitrate *bitrate;
349         MPEGFixedBitrate *fixed_bitrate;
350         MPEGQuant *quant;
351         MPEGFixedQuant *fixed_quant;
352         MPEGIFrameDistance *iframe_distance;
353         MPEGPFrameDistance *pframe_distance;
354         BC_CheckBox *top_field_first;
355         BC_CheckBox *progressive;
356         BC_CheckBox *denoise;
357         BC_CheckBox *seq_codes;
358
359         ArrayList<BC_Title*> titles;
360         ArrayList<BC_SubWindow*> tools;
361 };
362
363
364 #endif