4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
25 #include "bitspopup.inc"
26 #include "condition.inc"
36 #include "quicktime.h"
47 void load_output(mjpeg_t *mjpeg);
50 unsigned char *output; // Output buffer
51 int64_t output_size; // Size of output buffer
52 int64_t output_allocated; // Allocation of output buffer
53 Condition *completion_lock;
56 class FileMOV : public FileBase
59 FileMOV(Asset *asset, File *file);
62 friend class FileMOVThread;
64 static void get_parameters(BC_WindowBase *parent_window,
66 BC_WindowBase* &format_window,
69 const char *locked_compressor);
70 static int check_sig(Asset *asset);
72 int open_file(int rd, int wr);
74 void asset_to_format();
75 void format_to_asset();
76 int64_t get_video_length();
77 int64_t get_audio_length();
78 int set_video_position(int64_t x);
79 int set_audio_position(int64_t x);
80 int write_samples(double **buffer,
82 int write_frames(VFrame ***frames, int len);
83 int64_t compressed_frame_size();
84 int read_compressed_frame(VFrame *buffer);
85 int write_compressed_frame(VFrame *buffer);
87 int read_frame(VFrame *frame);
88 int read_samples(double *buffer, int64_t len);
90 // Direct copy routines
91 static int get_best_colormodel(Asset *asset, int driver);
92 int64_t get_memory_usage();
93 int colormodel_supported(int colormodel);
94 int can_copy_from(Edit *edit, int64_t position); // This file can copy frames directly from the asset
95 static const char *strtocompression(const char *string);
96 static const char *compressiontostr(const char *string);
98 // Fix codec to what AVI or MOV support
99 static void fix_codecs(Asset *asset);
100 // Check if resolutions match the DV codec when used
101 int check_codec_params(Asset *asset);
103 // set programme timecode
104 void set_frame_start(int64_t offset);
107 void new_audio_temp(int64_t len);
108 // read raw audio data
109 int read_raw(char *buffer, int64_t samples, int track);
110 // overlay raw frame from the current layer and position
111 int read_raw(VFrame *frame,
112 float in_x1, float in_y1, float in_x2, float in_y2,
113 float out_x1, float out_y1, float out_x2, float out_y2,
114 int use_float, int interpolate);
115 int reset_parameters_derived();
116 int quicktime_atracks;
117 int quicktime_vtracks;
118 // current positions for when the file descriptor doesn't have the right position
120 int depth; // Depth in bits per pixel
121 int64_t frames_correction; // Correction after 32bit overflow
122 int64_t samples_correction; // Correction after 32bit overflow
124 // An array of frames for threads to look up and compress on their own.
125 ArrayList<ThreadStruct*> threadframes;
127 int total_threadframes; // Number of thread frames in this buffer
128 int current_threadframe; // Next threadframe to compress
129 Mutex *threadframe_lock; // Lock threadframe array.
131 FileMOVThread **threads; // One thread for every CPU
132 char prefix_path[1024]; // Prefix for new file when 2G limit is exceeded
133 int suffix_number; // Number for new file
135 // Temp buffers for converting from double to float
137 int64_t temp_allocated;
141 // Encoder thread to parallelize certain compression formats, mainly JPEG.
142 // Only works when no alpha.
144 class FileMOVThread : public Thread
147 FileMOVThread(FileMOV *filemov, int fields);
150 int start_encoding();
155 ThreadStruct *threadframe; // The frame currently being processed.
158 Condition *input_lock; // Wait for new array of threads or completion.
164 class MOVConfigAudioNum;
165 class MOVConfigAudioPopup;
166 class MOVConfigAudioToggle;
168 class MOVConfigAudio : public BC_Window
171 MOVConfigAudio(BC_WindowBase *parent_window, Asset *asset);
174 void create_objects();
176 void update_parameters();
179 MOVConfigAudioPopup *compression_popup;
180 ArrayList<BC_ListBoxItem*> compression_items;
181 BC_WindowBase *parent_window;
182 BitsPopup *bits_popup;
183 BC_Title *bits_title;
186 MOVConfigAudioNum *vorbis_min_bitrate;
187 MOVConfigAudioNum *vorbis_bitrate;
188 MOVConfigAudioNum *vorbis_max_bitrate;
189 MOVConfigAudioToggle *vorbis_vbr;
191 MOVConfigAudioNum *mp3_bitrate;
192 MOVConfigAudioNum *mp4a_bitrate;
193 MOVConfigAudioNum *mp4a_quantqual;
197 class MOVConfigAudioPopup : public BC_PopupTextBox
200 MOVConfigAudioPopup(MOVConfigAudio *popup, int x, int y);
202 MOVConfigAudio *popup;
206 class MOVConfigAudioToggle : public BC_CheckBox
209 MOVConfigAudioToggle(MOVConfigAudio *popup,
216 MOVConfigAudio *popup;
220 class MOVConfigAudioNum : public BC_TumbleTextBox
223 MOVConfigAudioNum(MOVConfigAudio *popup,
228 ~MOVConfigAudioNum();
230 void create_objects();
233 MOVConfigAudio *popup;
240 class MOVConfigVideoPopup;
241 class MOVConfigVideoNum;
242 class MOVConfigVideoFix;
243 class MOVConfigVideoFixBitrate;
244 class MOVConfigVideoFixQuant;
245 class MOVConfigVideoCheckBox;
248 class MOVConfigVideo : public BC_Window
251 MOVConfigVideo(BC_WindowBase *parent_window,
253 const char *locked_compressor);
256 void create_objects();
260 void update_parameters();
262 ArrayList<BC_ListBoxItem*> compression_items;
263 MOVConfigVideoPopup *compression_popup;
264 BC_WindowBase *parent_window;
266 int param_x, param_y;
267 const char *locked_compressor;
269 BC_ISlider *jpeg_quality;
270 BC_Title *jpeg_quality_title;
272 MOVConfigVideoNum *ms_bitrate;
273 MOVConfigVideoNum *ms_bitrate_tolerance;
274 MOVConfigVideoNum *ms_quantization;
275 MOVConfigVideoNum *ms_gop_size;
276 MOVConfigVideoCheckBox *ms_interlaced;
277 MOVConfigVideoFixBitrate *ms_fix_bitrate;
278 MOVConfigVideoFixQuant *ms_fix_quant;
280 MOVConfigVideoNum *divx_bitrate;
281 MOVConfigVideoNum *divx_quantizer;
282 MOVConfigVideoNum *divx_rc_period;
283 MOVConfigVideoNum *divx_rc_reaction_ratio;
284 MOVConfigVideoNum *divx_rc_reaction_period;
285 MOVConfigVideoNum *divx_max_key_interval;
286 MOVConfigVideoNum *divx_max_quantizer;
287 MOVConfigVideoNum *divx_min_quantizer;
288 MOVConfigVideoNum *divx_quality;
289 MOVConfigVideoFixBitrate *divx_fix_bitrate;
290 MOVConfigVideoFixQuant *divx_fix_quant;
292 MOVConfigVideoNum *h264_bitrate;
293 MOVConfigVideoNum *h264_quantizer;
294 MOVConfigVideoFixBitrate *h264_fix_bitrate;
295 MOVConfigVideoFixQuant *h264_fix_quant;
298 class MOVConfigVideoPopup : public BC_PopupTextBox
301 MOVConfigVideoPopup(MOVConfigVideo *popup, int x, int y);
303 MOVConfigVideo *popup;
306 class MOVConfigVideoFixBitrate : public BC_Radial
309 MOVConfigVideoFixBitrate(int x,
319 class MOVConfigVideoFixQuant : public BC_Radial
322 MOVConfigVideoFixQuant(int x,
332 class MOVConfigVideoCheckBox : public BC_CheckBox
335 MOVConfigVideoCheckBox(char *title_text,
343 class MOVConfigVideoNum : public BC_TumbleTextBox
346 MOVConfigVideoNum(MOVConfigVideo *popup,
351 MOVConfigVideoNum(MOVConfigVideo *popup,
358 ~MOVConfigVideoNum();
360 void create_objects();
363 MOVConfigVideo *popup;