r870: Merge 2.1:
[cinelerra_cv.git] / cinelerra / filemov.h
blob81f7d68a5d7fb66821d59fce0656bcb5f716497e
1 #ifndef FILEMOV_H
2 #define FILEMOV_H
4 #include "bitspopup.inc"
5 #include "condition.inc"
6 #include "filebase.h"
7 #include "file.inc"
9 #ifdef HAVE_STDLIB_H
10 #undef HAVE_STDLIB_H
11 #endif
13 #include "libmjpeg.h"
14 #include "mutex.inc"
15 #include "quicktime.h"
16 #include "thread.h"
18 class FileMOVThread;
20 class ThreadStruct
22 public:
23 ThreadStruct();
24 ~ThreadStruct();
26 void load_output(mjpeg_t *mjpeg);
28 VFrame *input;
29 unsigned char *output; // Output buffer
30 int64_t output_size; // Size of output buffer
31 int64_t output_allocated; // Allocation of output buffer
32 Condition *completion_lock;
35 class FileMOV : public FileBase
37 public:
38 FileMOV(Asset *asset, File *file);
39 ~FileMOV();
41 friend class FileMOVThread;
43 static void get_parameters(BC_WindowBase *parent_window,
44 Asset *asset,
45 BC_WindowBase* &format_window,
46 int audio_options,
47 int video_options,
48 char *locked_compressor);
49 static int check_sig(Asset *asset);
51 int open_file(int rd, int wr);
52 int close_file();
53 void asset_to_format();
54 void format_to_asset();
55 int64_t get_video_length();
56 int64_t get_audio_length();
57 int set_video_position(int64_t x);
58 int set_audio_position(int64_t x);
59 int write_samples(double **buffer,
60 int64_t len);
61 int write_frames(VFrame ***frames, int len);
62 int64_t compressed_frame_size();
63 int read_compressed_frame(VFrame *buffer);
64 int write_compressed_frame(VFrame *buffer);
66 int read_frame(VFrame *frame);
67 int read_samples(double *buffer, int64_t len);
69 // Direct copy routines
70 static int get_best_colormodel(Asset *asset, int driver);
71 int64_t get_memory_usage();
72 int colormodel_supported(int colormodel);
73 int can_copy_from(Edit *edit, int64_t position); // This file can copy frames directly from the asset
74 static char *strtocompression(char *string);
75 static char *compressiontostr(char *string);
77 // Fix codec to what AVI or MOV support
78 static void fix_codecs(Asset *asset);
80 // set programme timecode
81 void set_frame_start(int64_t offset);
83 private:
84 void new_audio_temp(int64_t len);
85 // read raw audio data
86 int read_raw(char *buffer, int64_t samples, int track);
87 // overlay raw frame from the current layer and position
88 int read_raw(VFrame *frame,
89 float in_x1, float in_y1, float in_x2, float in_y2,
90 float out_x1, float out_y1, float out_x2, float out_y2,
91 int use_float, int interpolate);
92 int reset_parameters_derived();
93 int quicktime_atracks;
94 int quicktime_vtracks;
95 // current positions for when the file descriptor doesn't have the right position
96 quicktime_t *fd;
97 int depth; // Depth in bits per pixel
98 int64_t frames_correction; // Correction after 32bit overflow
99 int64_t samples_correction; // Correction after 32bit overflow
101 // An array of frames for threads to look up and compress on their own.
102 ArrayList<ThreadStruct*> threadframes;
104 int total_threadframes; // Number of thread frames in this buffer
105 int current_threadframe; // Next threadframe to compress
106 Mutex *threadframe_lock; // Lock threadframe array.
108 FileMOVThread **threads; // One thread for every CPU
109 char prefix_path[1024]; // Prefix for new file when 2G limit is exceeded
110 int suffix_number; // Number for new file
112 // Temp buffers for converting from double to float
113 float **temp_float;
114 int64_t temp_allocated;
118 // Encoder thread to parallelize certain compression formats, mainly JPEG.
119 // Only works when no alpha.
121 class FileMOVThread : public Thread
123 public:
124 FileMOVThread(FileMOV *filemov, int fields);
125 ~FileMOVThread();
127 int start_encoding();
128 int stop_encoding();
129 int encode_buffer();
130 void run();
132 ThreadStruct *threadframe; // The frame currently being processed.
133 int done;
134 FileMOV *filemov;
135 Condition *input_lock; // Wait for new array of threads or completion.
136 mjpeg_t *mjpeg;
137 int fields;
141 class MOVConfigAudioNum;
142 class MOVConfigAudioPopup;
143 class MOVConfigAudioToggle;
145 class MOVConfigAudio : public BC_Window
147 public:
148 MOVConfigAudio(BC_WindowBase *parent_window, Asset *asset);
149 ~MOVConfigAudio();
151 int create_objects();
152 int close_event();
153 void update_parameters();
154 void reset();
156 MOVConfigAudioPopup *compression_popup;
157 ArrayList<BC_ListBoxItem*> compression_items;
158 BC_WindowBase *parent_window;
159 BitsPopup *bits_popup;
160 BC_Title *bits_title;
161 BC_CheckBox *dither;
162 Asset *asset;
163 MOVConfigAudioNum *vorbis_min_bitrate;
164 MOVConfigAudioNum *vorbis_bitrate;
165 MOVConfigAudioNum *vorbis_max_bitrate;
166 MOVConfigAudioToggle *vorbis_vbr;
168 MOVConfigAudioNum *mp3_bitrate;
169 MOVConfigAudioNum *mp4a_bitrate;
170 MOVConfigAudioNum *mp4a_quantqual;
174 class MOVConfigAudioPopup : public BC_PopupTextBox
176 public:
177 MOVConfigAudioPopup(MOVConfigAudio *popup, int x, int y);
178 int handle_event();
179 MOVConfigAudio *popup;
183 class MOVConfigAudioToggle : public BC_CheckBox
185 public:
186 MOVConfigAudioToggle(MOVConfigAudio *popup,
187 char *title_text,
188 int x,
189 int y,
190 int *output);
191 int handle_event();
192 int *output;
193 MOVConfigAudio *popup;
197 class MOVConfigAudioNum : public BC_TumbleTextBox
199 public:
200 MOVConfigAudioNum(MOVConfigAudio *popup,
201 char *title_text,
202 int x,
203 int y,
204 int *output);
205 ~MOVConfigAudioNum();
207 void create_objects();
208 int handle_event();
209 int *output;
210 MOVConfigAudio *popup;
211 BC_Title *title;
212 char *title_text;
213 int x, y;
217 class MOVConfigVideoPopup;
218 class MOVConfigVideoNum;
219 class MOVConfigVideoFix;
220 class MOVConfigVideoFixBitrate;
221 class MOVConfigVideoFixQuant;
222 class MOVConfigVideoCheckBox;
225 class MOVConfigVideo : public BC_Window
227 public:
228 MOVConfigVideo(BC_WindowBase *parent_window,
229 Asset *asset,
230 char *locked_compressor);
231 ~MOVConfigVideo();
233 int create_objects();
234 int close_event();
235 void reset();
237 void update_parameters();
239 ArrayList<BC_ListBoxItem*> compression_items;
240 MOVConfigVideoPopup *compression_popup;
241 BC_WindowBase *parent_window;
242 Asset *asset;
243 int param_x, param_y;
244 char *locked_compressor;
246 BC_ISlider *jpeg_quality;
247 BC_Title *jpeg_quality_title;
249 MOVConfigVideoNum *ms_bitrate;
250 MOVConfigVideoNum *ms_bitrate_tolerance;
251 MOVConfigVideoNum *ms_quantization;
252 MOVConfigVideoNum *ms_gop_size;
253 MOVConfigVideoCheckBox *ms_interlaced;
254 MOVConfigVideoFixBitrate *ms_fix_bitrate;
255 MOVConfigVideoFixQuant *ms_fix_quant;
257 MOVConfigVideoNum *divx_bitrate;
258 MOVConfigVideoNum *divx_quantizer;
259 MOVConfigVideoNum *divx_rc_period;
260 MOVConfigVideoNum *divx_rc_reaction_ratio;
261 MOVConfigVideoNum *divx_rc_reaction_period;
262 MOVConfigVideoNum *divx_max_key_interval;
263 MOVConfigVideoNum *divx_max_quantizer;
264 MOVConfigVideoNum *divx_min_quantizer;
265 MOVConfigVideoNum *divx_quality;
266 MOVConfigVideoFixBitrate *divx_fix_bitrate;
267 MOVConfigVideoFixQuant *divx_fix_quant;
269 MOVConfigVideoNum *h264_bitrate;
270 MOVConfigVideoNum *h264_quantizer;
271 MOVConfigVideoFixBitrate *h264_fix_bitrate;
272 MOVConfigVideoFixQuant *h264_fix_quant;
275 class MOVConfigVideoPopup : public BC_PopupTextBox
277 public:
278 MOVConfigVideoPopup(MOVConfigVideo *popup, int x, int y);
279 int handle_event();
280 MOVConfigVideo *popup;
283 class MOVConfigVideoFixBitrate : public BC_Radial
285 public:
286 MOVConfigVideoFixBitrate(int x,
287 int y,
288 int *output,
289 int value);
290 int handle_event();
291 BC_Radial *opposite;
292 int *output;
293 int value;
296 class MOVConfigVideoFixQuant : public BC_Radial
298 public:
299 MOVConfigVideoFixQuant(int x,
300 int y,
301 int *output,
302 int value);
303 int handle_event();
304 BC_Radial *opposite;
305 int *output;
306 int value;
309 class MOVConfigVideoCheckBox : public BC_CheckBox
311 public:
312 MOVConfigVideoCheckBox(char *title_text,
313 int x,
314 int y,
315 int *output);
316 int handle_event();
317 int *output;
320 class MOVConfigVideoNum : public BC_TumbleTextBox
322 public:
323 MOVConfigVideoNum(MOVConfigVideo *popup,
324 char *title_text,
325 int x,
326 int y,
327 int *output);
328 MOVConfigVideoNum(MOVConfigVideo *popup,
329 char *title_text,
330 int x,
331 int y,
332 int min,
333 int max,
334 int *output);
335 ~MOVConfigVideoNum();
337 void create_objects();
338 int handle_event();
339 int *output;
340 MOVConfigVideo *popup;
341 BC_Title *title;
342 char *title_text;
343 int x, y;
346 #endif