Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / filemov.h
blob1258c5a6dca2322d8518d5de07308f6faae3dce5
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_GC asset, File *file);
39 ~FileMOV();
41 friend class FileMOVThread;
43 static void get_parameters(BC_WindowBase *parent_window,
44 Asset_GC asset,
45 BC_WindowBase* &format_window,
46 int audio_options,
47 int video_options,
48 char *locked_compressor);
49 static int check_sig(Asset_GC 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_GC 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_GC asset);
79 // Check if resolutions match the DV codec when used
80 int check_codec_params(Asset_GC asset);
82 // set programme timecode
83 void set_frame_start(int64_t offset);
85 private:
86 void new_audio_temp(int64_t len);
87 // read raw audio data
88 int read_raw(char *buffer, int64_t samples, int track);
89 // overlay raw frame from the current layer and position
90 int read_raw(VFrame *frame,
91 float in_x1, float in_y1, float in_x2, float in_y2,
92 float out_x1, float out_y1, float out_x2, float out_y2,
93 int use_float, int interpolate);
94 int reset_parameters_derived();
95 int quicktime_atracks;
96 int quicktime_vtracks;
97 // current positions for when the file descriptor doesn't have the right position
98 quicktime_t *fd;
99 int depth; // Depth in bits per pixel
100 int64_t frames_correction; // Correction after 32bit overflow
101 int64_t samples_correction; // Correction after 32bit overflow
103 // An array of frames for threads to look up and compress on their own.
104 ArrayList<ThreadStruct*> threadframes;
106 int total_threadframes; // Number of thread frames in this buffer
107 int current_threadframe; // Next threadframe to compress
108 Mutex *threadframe_lock; // Lock threadframe array.
110 FileMOVThread **threads; // One thread for every CPU
111 char prefix_path[1024]; // Prefix for new file when 2G limit is exceeded
112 int suffix_number; // Number for new file
114 // Temp buffers for converting from double to float
115 float **temp_float;
116 int64_t temp_allocated;
120 // Encoder thread to parallelize certain compression formats, mainly JPEG.
121 // Only works when no alpha.
123 class FileMOVThread : public Thread
125 public:
126 FileMOVThread(FileMOV *filemov, int fields);
127 ~FileMOVThread();
129 int start_encoding();
130 int stop_encoding();
131 int encode_buffer();
132 void run();
134 ThreadStruct *threadframe; // The frame currently being processed.
135 int done;
136 FileMOV *filemov;
137 Condition *input_lock; // Wait for new array of threads or completion.
138 mjpeg_t *mjpeg;
139 int fields;
143 class MOVConfigAudioNum;
144 class MOVConfigAudioPopup;
145 class MOVConfigAudioToggle;
147 class MOVConfigAudio : public BC_Window
149 public:
150 MOVConfigAudio(BC_WindowBase *parent_window, Asset_GC asset);
151 ~MOVConfigAudio();
153 int create_objects();
154 int close_event();
155 void update_parameters();
156 void reset();
158 MOVConfigAudioPopup *compression_popup;
159 ArrayList<BC_ListBoxItem*> compression_items;
160 BC_WindowBase *parent_window;
161 BitsPopup *bits_popup;
162 BC_Title *bits_title;
163 BC_CheckBox *dither;
164 Asset_GC asset;
165 MOVConfigAudioNum *vorbis_min_bitrate;
166 MOVConfigAudioNum *vorbis_bitrate;
167 MOVConfigAudioNum *vorbis_max_bitrate;
168 MOVConfigAudioToggle *vorbis_vbr;
170 MOVConfigAudioNum *mp3_bitrate;
171 MOVConfigAudioNum *mp4a_bitrate;
172 MOVConfigAudioNum *mp4a_quantqual;
174 BC_WidgetGrid *wg, *wg_set;
175 int ok_height;
179 class MOVConfigAudioPopup : public BC_PopupTextBox
181 public:
182 MOVConfigAudioPopup(MOVConfigAudio *popup, int x, int y);
183 int handle_event();
184 MOVConfigAudio *popup;
188 class MOVConfigAudioToggle : public BC_CheckBox
190 public:
191 MOVConfigAudioToggle(MOVConfigAudio *popup,
192 char *title_text,
193 int x,
194 int y,
195 int *output);
196 int handle_event();
197 int *output;
198 MOVConfigAudio *popup;
202 class MOVConfigAudioNum : public BC_TumbleTextBox
204 public:
205 MOVConfigAudioNum(MOVConfigAudio *popup,
206 char *title_text,
207 int x,
208 int y,
209 int *output);
210 ~MOVConfigAudioNum();
212 void create_objects();
213 int handle_event();
214 int *output;
215 MOVConfigAudio *popup;
216 BC_Title *title;
217 char *title_text;
218 int x, y;
222 class MOVConfigVideoPopup;
223 class MOVConfigVideoNum;
224 class MOVConfigVideoFix;
225 class MOVConfigVideoFixBitrate;
226 class MOVConfigVideoFixQuant;
227 class MOVConfigVideoCheckBox;
230 class MOVConfigVideo : public BC_Window
232 public:
233 MOVConfigVideo(BC_WindowBase *parent_window,
234 Asset_GC asset,
235 char *locked_compressor);
236 ~MOVConfigVideo();
238 int create_objects();
239 int close_event();
240 void reset();
242 void update_parameters();
244 ArrayList<BC_ListBoxItem*> compression_items;
245 MOVConfigVideoPopup *compression_popup;
246 BC_WindowBase *parent_window;
247 Asset_GC asset;
248 int param_x, param_y;
249 char *locked_compressor;
251 BC_ISlider *jpeg_quality;
252 BC_Title *jpeg_quality_title;
254 MOVConfigVideoNum *ms_bitrate;
255 MOVConfigVideoNum *ms_bitrate_tolerance;
256 MOVConfigVideoNum *ms_quantization;
257 MOVConfigVideoNum *ms_gop_size;
258 MOVConfigVideoCheckBox *ms_interlaced;
259 MOVConfigVideoFixBitrate *ms_fix_bitrate;
260 MOVConfigVideoFixQuant *ms_fix_quant;
262 MOVConfigVideoNum *divx_bitrate;
263 MOVConfigVideoNum *divx_quantizer;
264 MOVConfigVideoNum *divx_rc_period;
265 MOVConfigVideoNum *divx_rc_reaction_ratio;
266 MOVConfigVideoNum *divx_rc_reaction_period;
267 MOVConfigVideoNum *divx_max_key_interval;
268 MOVConfigVideoNum *divx_max_quantizer;
269 MOVConfigVideoNum *divx_min_quantizer;
270 MOVConfigVideoNum *divx_quality;
271 MOVConfigVideoFixBitrate *divx_fix_bitrate;
272 MOVConfigVideoFixQuant *divx_fix_quant;
274 MOVConfigVideoNum *h264_bitrate;
275 MOVConfigVideoNum *h264_quantizer;
276 MOVConfigVideoFixBitrate *h264_fix_bitrate;
277 MOVConfigVideoFixQuant *h264_fix_quant;
279 BC_WidgetGrid *wg, *wg_set;
280 int ok_height;
283 class MOVConfigVideoPopup : public BC_PopupTextBox
285 public:
286 MOVConfigVideoPopup(MOVConfigVideo *popup, int x, int y);
287 int handle_event();
288 MOVConfigVideo *popup;
291 class MOVConfigVideoFixBitrate : public BC_Radial
293 public:
294 MOVConfigVideoFixBitrate(int x,
295 int y,
296 int *output,
297 int value);
298 int handle_event();
299 BC_Radial *opposite;
300 int *output;
301 int value;
304 class MOVConfigVideoFixQuant : public BC_Radial
306 public:
307 MOVConfigVideoFixQuant(int x,
308 int y,
309 int *output,
310 int value);
311 int handle_event();
312 BC_Radial *opposite;
313 int *output;
314 int value;
317 class MOVConfigVideoCheckBox : public BC_CheckBox
319 public:
320 MOVConfigVideoCheckBox(char *title_text,
321 int x,
322 int y,
323 int *output);
324 int handle_event();
325 int *output;
328 class MOVConfigVideoNum : public BC_TumbleTextBox
330 public:
331 MOVConfigVideoNum(MOVConfigVideo *popup,
332 char *title_text,
333 int x,
334 int y,
335 int *output);
336 MOVConfigVideoNum(MOVConfigVideo *popup,
337 char *title_text,
338 int x,
339 int y,
340 int min,
341 int max,
342 int *output);
343 ~MOVConfigVideoNum();
345 void create_objects();
346 int handle_event();
347 int *output;
348 MOVConfigVideo *popup;
349 BC_Title *title;
350 char *title_text;
351 int x, y;
354 #endif
356 // Local Variables:
357 // mode: C++
358 // c-file-style: "linux"
359 // End: