rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.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
25 #include "bitspopup.inc"
26 #include "condition.inc"
27 #include "file.inc"
28 #include "filebase.h"
29 #include "indexfile.inc"
30 #include "twolame.h"
31 #include "lame/lame.h"
32 #include "libzmpeg3.h"
33 #include "mainprogress.inc"
34 #include "thread.h"
35
36
37 extern "C"
38 {
39
40
41 // Mpeg2enc prototypes
42 void mpeg2enc_init_buffers();
43 int mpeg2enc(int argc, char *argv[]);
44 void mpeg2enc_set_w(int width);
45 void mpeg2enc_set_h(int height);
46 void mpeg2enc_set_rate(double rate);
47 void mpeg2enc_set_input_buffers(int eof, char *y, char *u, char *v);
48
49
50
51
52
53 }
54
55 class FileMPEGVideo;
56
57 class FileMPEG : public FileBase
58 {
59 public:
60         FileMPEG(Asset *asset, File *file);
61         ~FileMPEG();
62
63         friend class FileMPEGVideo;
64
65         static void get_parameters(BC_WindowBase *parent_window, 
66                 Asset *asset, 
67                 BC_WindowBase* &format_window,
68                 int audio_options,
69                 int video_options);
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
114 private:
115         void to_streamchannel(int channel, int &stream_out, int &channel_out);
116         int reset_parameters_derived();
117 // File descriptor for decoder
118         mpeg3_t *fd;
119
120 // Thread for video encoder
121         FileMPEGVideo *video_out;
122 // Command line for video encoder
123         ArrayList<char*> vcommand_line;
124         void append_vcommand_line(const char *string);
125
126 // DVB capture
127         int recd_fd;
128         int record_fd() { return recd_fd; }
129
130 // MJPEGtools encoder
131         FILE *mjpeg_out;        
132         int mjpeg_error;
133         Condition *next_frame_lock;
134         Condition *next_frame_done;
135         int mjpeg_eof;
136         int wrote_header;
137         unsigned char *mjpeg_y; 
138         unsigned char *mjpeg_u; 
139         unsigned char *mjpeg_v; 
140         char mjpeg_command[BCTEXTLEN];
141
142 // skimmer
143         static int skimming(void *vp, int track);
144         skim_fn skim_callback;
145         void *skim_data;
146         int skim_result;
147 // toc scan commercial detection
148         static int toc_nail(void *vp, int track);
149
150 // Temporary for color conversion
151         VFrame *temp_frame;
152
153         unsigned char *twolame_temp, *twolame_out;
154         int twolame_allocation;
155         int twolame_result;
156         FILE *twofp;
157         twolame_options *twopts;
158
159         float *lame_temp[2];
160         int lame_allocation;
161         char *lame_output;
162         int lame_output_allocation;
163         FILE *lame_fd;
164 // Lame puts 0 before stream
165         int lame_started;
166
167         lame_global_flags *lame_global;
168         double *weight;
169 };
170
171
172 class FileMPEGVideo : public Thread
173 {
174 public:
175         FileMPEGVideo(FileMPEG *file);
176         ~FileMPEGVideo();
177
178         void run();
179
180         FileMPEG *file;
181 };
182
183 class MPEGConfigAudioPopup;
184 class MPEGABitrate;
185
186
187 class MPEGConfigAudio : public BC_Window
188 {
189 public:
190         MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
191         ~MPEGConfigAudio();
192
193         void create_objects();
194         int close_event();
195
196         BC_WindowBase *parent_window;
197         MPEGABitrate *bitrate;
198         char string[BCTEXTLEN];
199         Asset *asset;
200 };
201
202
203 class MPEGLayer : public BC_PopupMenu
204 {
205 public:
206         MPEGLayer(int x, int y, MPEGConfigAudio *gui);
207         void create_objects();
208         int handle_event();
209         static int string_to_layer(char *string);
210         static char* layer_to_string(int derivative);
211         
212         MPEGConfigAudio *gui;
213 };
214
215 class MPEGABitrate : public BC_PopupMenu
216 {
217 public:
218         MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
219
220         void create_objects();
221         void set_layer(int layer);
222
223         int handle_event();
224         static int string_to_bitrate(char *string);
225         static char* bitrate_to_string(char *string, int bitrate);
226         
227         MPEGConfigAudio *gui;
228 };
229
230
231
232 class MPEGConfigVideo;
233
234
235
236 class MPEGPreset : public BC_PopupMenu
237 {
238 public:
239         MPEGPreset(int x, int y, MPEGConfigVideo *gui);
240         void create_objects();
241         int handle_event();
242         static int string_to_value(char *string);
243         static char* value_to_string(int value);
244         MPEGConfigVideo *gui;
245 };
246
247 class MPEGColorModel : public BC_PopupMenu
248 {
249 public:
250         MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
251         void create_objects();
252         int handle_event();
253         static int string_to_cmodel(char *string);
254         static char* cmodel_to_string(int cmodel);
255         
256         MPEGConfigVideo *gui;
257 };
258
259
260 class MPEGDerivative : public BC_PopupMenu
261 {
262 public:
263         MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
264         void create_objects();
265         int handle_event();
266         static int string_to_derivative(char *string);
267         static char* derivative_to_string(int derivative);
268         
269         MPEGConfigVideo *gui;
270 };
271
272 class MPEGBitrate : public BC_TextBox
273 {
274 public:
275         MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
276         int handle_event();
277         MPEGConfigVideo *gui;
278 };
279
280 class MPEGQuant : public BC_TumbleTextBox
281 {
282 public:
283         MPEGQuant(int x, int y, MPEGConfigVideo *gui);
284         int handle_event();
285         MPEGConfigVideo *gui;
286 };
287
288 class MPEGIFrameDistance : public BC_TumbleTextBox
289 {
290 public:
291         MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
292         int handle_event();
293         MPEGConfigVideo *gui;
294 };
295
296 class MPEGPFrameDistance : public BC_TumbleTextBox
297 {
298 public:
299         MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
300         int handle_event();
301         MPEGConfigVideo *gui;
302 };
303
304 class MPEGFixedBitrate : public BC_Radial
305 {
306 public:
307         MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
308         int handle_event();
309         MPEGConfigVideo *gui;
310 };
311
312 class MPEGFixedQuant : public BC_Radial
313 {
314 public:
315         MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
316         int handle_event();
317         MPEGConfigVideo *gui;
318 };
319
320 class MPEGSeqCodes : public BC_CheckBox
321 {
322 public:
323         MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
324         int handle_event();
325         MPEGConfigVideo *gui;
326 };
327
328
329
330
331 class MPEGConfigVideo : public BC_Window
332 {
333 public:
334         MPEGConfigVideo(BC_WindowBase *parent_window, 
335                 Asset *asset);
336         ~MPEGConfigVideo();
337
338         void create_objects();
339         int close_event();
340         void delete_cmodel_objs();
341         void reset_cmodel();
342         void update_cmodel_objs();
343
344         BC_WindowBase *parent_window;
345         Asset *asset;
346         MPEGPreset *preset;
347         MPEGColorModel *cmodel;
348         MPEGDerivative *derivative;
349         MPEGBitrate *bitrate;
350         MPEGFixedBitrate *fixed_bitrate;
351         MPEGQuant *quant;
352         MPEGFixedQuant *fixed_quant;
353         MPEGIFrameDistance *iframe_distance;
354         MPEGPFrameDistance *pframe_distance;
355         BC_CheckBox *top_field_first;
356         BC_CheckBox *progressive;
357         BC_CheckBox *denoise;
358         BC_CheckBox *seq_codes;
359
360         ArrayList<BC_Title*> titles;
361         ArrayList<BC_SubWindow*> tools;
362 };
363
364
365 #endif