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