r665: Merged the official release 2.0.
[cinelerra_cv.git] / cinelerra / filempeg.h
blobcceb78734f250349917bf41ec5a4124fbc8b7841
1 #ifndef FILEMPEG_H
2 #define FILEMPEG_H
4 #include "bitspopup.inc"
5 #include "condition.inc"
6 #include "file.inc"
7 #include "filebase.h"
8 #include <lame/lame.h>
9 #include "libmpeg3.h"
10 #include "thread.h"
13 extern "C"
17 // Mpeg2enc prototypes
18 void mpeg2enc_init_buffers();
19 int mpeg2enc(int argc, char *argv[]);
20 void mpeg2enc_set_w(int width);
21 void mpeg2enc_set_h(int height);
22 void mpeg2enc_set_rate(double rate);
23 void mpeg2enc_set_input_buffers(int eof, char *y, char *u, char *v);
27 // Toolame prototypes
28 void toolame_init_buffers();
29 int toolame(int argc, char **argv);
30 int toolame_send_buffer(char *data, int bytes);
35 class FileMPEGVideo;
36 class FileMPEGAudio;
38 class FileMPEG : public FileBase
40 public:
41 FileMPEG(Asset *asset, File *file);
42 ~FileMPEG();
44 friend class FileMPEGVideo;
45 friend class FileMPEGAudio;
47 static void get_parameters(BC_WindowBase *parent_window,
48 Asset *asset,
49 BC_WindowBase* &format_window,
50 int audio_options,
51 int video_options);
53 static int check_sig(Asset *asset);
54 int open_file(int rd, int wr);
55 int close_file();
56 int create_index();
59 int get_index(char *index_path);
60 int set_video_position(int64_t x);
61 int set_audio_position(int64_t x);
62 int write_samples(double **buffer,
63 int64_t len);
64 int write_frames(VFrame ***frames, int len);
66 int read_frame(VFrame *frame);
67 int read_samples(double *buffer, int64_t len);
68 int read_samples_float(float *buffer, int64_t len);
69 int prefer_samples_float();
71 // Direct copy routines
72 static int get_best_colormodel(Asset *asset, int driver);
73 int colormodel_supported(int colormodel);
74 // This file can copy frames directly from the asset
75 int can_copy_from(Edit *edit, int64_t position);
76 static char *strtocompression(char *string);
77 static char *compressiontostr(char *string);
80 private:
81 void to_streamchannel(int channel, int &stream_out, int &channel_out);
82 int reset_parameters_derived();
83 // File descriptor for decoder
84 mpeg3_t *fd;
86 // Thread for video encoder
87 FileMPEGVideo *video_out;
88 // Command line for video encoder
89 ArrayList<char*> vcommand_line;
90 void append_vcommand_line(const char *string);
97 // MJPEGtools encoder
98 FILE *mjpeg_out;
99 int mjpeg_error;
100 Condition *next_frame_lock;
101 Condition *next_frame_done;
102 int mjpeg_eof;
103 int wrote_header;
104 unsigned char *mjpeg_y;
105 unsigned char *mjpeg_u;
106 unsigned char *mjpeg_v;
107 char mjpeg_command[BCTEXTLEN];
114 // Thread for audio encoder
115 FileMPEGAudio *audio_out;
116 // Command line for audio encoder
117 ArrayList<char*> acommand_line;
118 void append_acommand_line(const char *string);
121 // Temporary for color conversion
122 VFrame *temp_frame;
124 unsigned char *toolame_temp;
125 int toolame_allocation;
126 int toolame_result;
129 float *lame_temp[2];
130 int lame_allocation;
131 char *lame_output;
132 int lame_output_allocation;
133 FILE *lame_fd;
134 // Lame puts 0 before stream
135 int lame_started;
137 lame_global_flags *lame_global;
141 class FileMPEGVideo : public Thread
143 public:
144 FileMPEGVideo(FileMPEG *file);
145 ~FileMPEGVideo();
147 void run();
149 FileMPEG *file;
152 class FileMPEGAudio : public Thread
154 public:
155 FileMPEGAudio(FileMPEG *file);
156 ~FileMPEGAudio();
158 void run();
160 FileMPEG *file;
164 class MPEGConfigAudioPopup;
165 class MPEGABitrate;
168 class MPEGConfigAudio : public BC_Window
170 public:
171 MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
172 ~MPEGConfigAudio();
174 int create_objects();
175 int close_event();
177 BC_WindowBase *parent_window;
178 MPEGABitrate *bitrate;
179 char string[BCTEXTLEN];
180 Asset *asset;
184 class MPEGLayer : public BC_PopupMenu
186 public:
187 MPEGLayer(int x, int y, MPEGConfigAudio *gui);
188 void create_objects();
189 int handle_event();
190 static int string_to_layer(char *string);
191 static char* layer_to_string(int derivative);
193 MPEGConfigAudio *gui;
196 class MPEGABitrate : public BC_PopupMenu
198 public:
199 MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
201 void create_objects();
202 void set_layer(int layer);
204 int handle_event();
205 static int string_to_bitrate(char *string);
206 static char* bitrate_to_string(char *string, int bitrate);
208 MPEGConfigAudio *gui;
213 class MPEGConfigVideo;
217 class MPEGPreset : public BC_PopupMenu
219 public:
220 MPEGPreset(int x, int y, MPEGConfigVideo *gui);
221 void create_objects();
222 int handle_event();
223 static int string_to_value(char *string);
224 static char* value_to_string(int value);
225 MPEGConfigVideo *gui;
228 class MPEGColorModel : public BC_PopupMenu
230 public:
231 MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
232 void create_objects();
233 int handle_event();
234 static int string_to_cmodel(char *string);
235 static char* cmodel_to_string(int cmodel);
237 MPEGConfigVideo *gui;
241 class MPEGDerivative : public BC_PopupMenu
243 public:
244 MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
245 void create_objects();
246 int handle_event();
247 static int string_to_derivative(char *string);
248 static char* derivative_to_string(int derivative);
250 MPEGConfigVideo *gui;
253 class MPEGBitrate : public BC_TextBox
255 public:
256 MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
257 int handle_event();
258 MPEGConfigVideo *gui;
261 class MPEGQuant : public BC_TumbleTextBox
263 public:
264 MPEGQuant(int x, int y, MPEGConfigVideo *gui);
265 int handle_event();
266 MPEGConfigVideo *gui;
269 class MPEGIFrameDistance : public BC_TumbleTextBox
271 public:
272 MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
273 int handle_event();
274 MPEGConfigVideo *gui;
277 class MPEGPFrameDistance : public BC_TumbleTextBox
279 public:
280 MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
281 int handle_event();
282 MPEGConfigVideo *gui;
285 class MPEGFixedBitrate : public BC_Radial
287 public:
288 MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
289 int handle_event();
290 MPEGConfigVideo *gui;
293 class MPEGFixedQuant : public BC_Radial
295 public:
296 MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
297 int handle_event();
298 MPEGConfigVideo *gui;
301 class MPEGSeqCodes : public BC_CheckBox
303 public:
304 MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
305 int handle_event();
306 MPEGConfigVideo *gui;
312 class MPEGConfigVideo : public BC_Window
314 public:
315 MPEGConfigVideo(BC_WindowBase *parent_window,
316 Asset *asset);
317 ~MPEGConfigVideo();
319 int create_objects();
320 int close_event();
321 void delete_cmodel_objs();
322 void reset_cmodel();
323 void update_cmodel_objs();
325 BC_WindowBase *parent_window;
326 Asset *asset;
327 MPEGPreset *preset;
328 MPEGColorModel *cmodel;
329 MPEGDerivative *derivative;
330 MPEGBitrate *bitrate;
331 MPEGFixedBitrate *fixed_bitrate;
332 MPEGQuant *quant;
333 MPEGFixedQuant *fixed_quant;
334 MPEGIFrameDistance *iframe_distance;
335 MPEGPFrameDistance *pframe_distance;
336 BC_CheckBox *top_field_first;
337 BC_CheckBox *progressive;
338 BC_CheckBox *denoise;
339 BC_CheckBox *seq_codes;
341 ArrayList<BC_Title*> titles;
342 ArrayList<BC_SubWindow*> tools;
346 #endif