shuttle and transportque reworks, new shdmp, titler font textbox tweak
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / fileffmpeg.h
1 #ifndef __FILEFFMPEG_H__
2 #define __FILEFFMPEG_H__
3
4 #include "asset.inc"
5 #include "bcdialog.h"
6 #include "bcwindowbase.inc"
7 #include "bitspopup.inc"
8 #include "edl.inc"
9 #include "ffmpeg.h"
10 #include "filebase.h"
11 #include "fileffmpeg.inc"
12 #include "indexfile.inc"
13 #include "mainprogress.inc"
14 #include "mutex.h"
15 #include "thread.h"
16 #include "vframe.inc"
17
18 #include <stdio.h>
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <string.h>
23
24
25 class FileFFMPEG : public FileBase
26 {
27 public:
28         FFMPEG *ff;
29
30         FileFFMPEG(Asset *asset, File *file);
31         ~FileFFMPEG();
32         static void ff_lock(const char *cp=0);
33         static void ff_unlock();
34
35         static void set_options(char *cp, int len, const char *bp);
36         static void get_parameters(BC_WindowBase *parent_window,
37                 Asset *asset, BC_WindowBase *&format_window,
38                 int audio_options,int video_options, EDL *edl);
39         static int check_sig(Asset *asset);
40         int get_best_colormodel(int driver, int vstream);
41         int get_video_info(int track, int &pid, double &framerate,
42                 int &width, int &height, char *title=0);
43         int get_audio_for_video(int vstream, int astream, int64_t &channel_mask);
44         static void get_info(char *path,char *text,int len);
45         int open_file(int rd,int wr);
46         int get_index(IndexFile *index_file, MainProgressBar *progress_bar);
47         int close_file(void);
48         int write_samples(double **buffer,int64_t len);
49         int write_frames(VFrame ***frames,int len);
50         int read_samples(double *buffer,int64_t len);
51         int read_frame(VFrame *frame);
52         int can_scale_input() { return 1; }
53         int64_t get_memory_usage(void);
54         int colormodel_supported(int colormodel);
55         static int get_best_colormodel(Asset *asset, int driver);
56         int select_video_stream(Asset *asset, int vstream);
57         int select_audio_stream(Asset *asset, int astream);
58 };
59
60 class FFMpegConfigNum : public BC_TumbleTextBox
61 {
62 public:
63         FFMpegConfigNum(BC_Window *window, int x, int y,
64                 char *title_text, int *output);
65         ~FFMpegConfigNum();
66
67         void create_objects();
68         int update_param(const char *param, const char *opts);
69         int handle_event();
70         int *output;
71         BC_Window *window;
72         BC_Title *title;
73         char *title_text;
74         int x, y;
75 };
76
77 class FFMpegAudioNum : public FFMpegConfigNum
78 {
79 public:
80         FFMpegAudioNum(BC_Window *window, int x, int y, char *title_text, int *output);
81         ~FFMpegAudioNum() {}
82
83         FFMPEGConfigAudio *window() { return (FFMPEGConfigAudio *)FFMpegConfigNum::window; }
84 };
85
86 class FFMpegAudioBitrate : public FFMpegAudioNum
87 {
88 public:
89         FFMpegAudioBitrate(BC_Window *window, int x, int y, char *title_text, int *output)
90           : FFMpegAudioNum(window, x, y, title_text, output) {}
91         int handle_event();
92 };
93
94 class FFMpegAudioQuality : public FFMpegAudioNum
95 {
96 public:
97         FFMpegAudioQuality(BC_Window *window, int x, int y, char *title_text, int *output)
98           : FFMpegAudioNum(window, x, y, title_text, output) {}
99         int handle_event();
100 };
101
102 class FFMpegVideoNum : public FFMpegConfigNum
103 {
104 public:
105         FFMpegVideoNum(BC_Window *window, int x, int y, char *title_text, int *output);
106         ~FFMpegVideoNum() {}
107
108         FFMPEGConfigVideo *window() { return (FFMPEGConfigVideo *)FFMpegConfigNum::window; }
109 };
110
111 class FFMpegVideoBitrate : public FFMpegVideoNum
112 {
113 public:
114         FFMpegVideoBitrate(BC_Window *window, int x, int y, char *title_text, int *output)
115           : FFMpegVideoNum(window, x, y, title_text, output) {}
116         int handle_event();
117 };
118
119 class FFMpegVideoQuality : public FFMpegVideoNum
120 {
121 public:
122         FFMpegVideoQuality(BC_Window *window, int x, int y, char *title_text, int *output)
123           : FFMpegVideoNum(window, x, y, title_text, output) {}
124         int handle_event();
125 };
126
127 class FFMpegPixFmtItems : public ArrayList<BC_ListBoxItem*>
128 {
129 public:
130         FFMpegPixFmtItems() {}
131         ~FFMpegPixFmtItems() { remove_all_objects(); }
132 };
133
134 class FFMpegPixelFormat : public BC_PopupTextBox
135 {
136 public:
137         FFMpegPixelFormat(FFMPEGConfigVideo *vid_config, int x, int y, int w, int list_h);
138
139         FFMPEGConfigVideo *vid_config;
140         FFMpegPixFmtItems pixfmts;
141
142         int handle_event();
143         void update_formats();
144 };
145
146 class FFMpegSampleFormat : public BC_PopupTextBox
147 {
148 public:
149         FFMpegSampleFormat(FFMPEGConfigAudio *aud_config, int x, int y, int w, int list_h);
150
151         FFMPEGConfigAudio *aud_config;
152         ArrayList<BC_ListBoxItem*> samplefmts;
153
154         int handle_event();
155         void update_formats();
156 };
157
158 class FFMPEGConfigAudio : public BC_Window
159 {
160 public:
161         FFMPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset, EDL *edl);
162         ~FFMPEGConfigAudio();
163
164         void create_objects();
165         int close_event();
166         void load_options();
167
168         FFMpegSampleFormat *sample_format;
169         ArrayList<BC_ListBoxItem*> presets;
170         FFMPEGConfigAudioPopup *preset_popup;
171         FFMpegAudioBitrate *bitrate;
172         FFMpegAudioQuality *quality;
173         FFAudioOptions *audio_options;
174         BC_WindowBase *parent_window;
175         Asset *asset;
176         EDL *edl;
177         FFOptionsDialog *ff_options_dialog;
178 };
179
180 class FFAudioOptions : public BC_ScrollTextBox
181 {
182 public:
183         FFAudioOptions(FFMPEGConfigAudio *audio_popup,
184                 int x, int y, int w, int rows, int size, char *text);
185
186         FFMPEGConfigAudio *audio_popup;
187 };
188
189
190 class FFMPEGConfigAudioPopup : public BC_PopupTextBox
191 {
192 public:
193         FFMPEGConfigAudioPopup(FFMPEGConfigAudio *popup, int x, int y);
194         int handle_event();
195         FFMPEGConfigAudio *popup;
196 };
197
198
199 class FFMPEGConfigAudioToggle : public BC_CheckBox
200 {
201 public:
202         FFMPEGConfigAudioToggle(FFMPEGConfigAudio *popup,
203                 char *title_text, int x, int y, int *output);
204         int handle_event();
205         int *output;
206         FFMPEGConfigAudio *popup;
207 };
208
209 class FFMPEGConfigVideo : public BC_Window
210 {
211 public:
212         FFMPEGConfigVideo(BC_WindowBase *parent_window, Asset *asset, EDL *edl);
213         ~FFMPEGConfigVideo();
214
215         void create_objects();
216         int close_event();
217         void load_options();
218
219         FFMpegPixelFormat *pixel_format;
220         ArrayList<BC_ListBoxItem*> presets;
221         FFMPEGConfigVideoPopup *preset_popup;
222         BC_WindowBase *parent_window;
223         FFMpegVideoBitrate *bitrate;
224         FFMpegVideoQuality *quality;
225         FFVideoOptions *video_options;
226         Asset *asset;
227         EDL *edl;
228         FFOptionsDialog *ff_options_dialog;
229 };
230
231 class FFVideoOptions : public BC_ScrollTextBox
232 {
233 public:
234         FFVideoOptions(FFMPEGConfigVideo *video_popup,
235                 int x, int y, int w, int rows, int size, char *text);
236
237         FFMPEGConfigVideo *video_popup;
238 };
239
240 class FFMPEGConfigVideoPopup : public BC_PopupTextBox
241 {
242 public:
243         FFMPEGConfigVideoPopup(FFMPEGConfigVideo *popup, int x, int y);
244         int handle_event();
245         FFMPEGConfigVideo *popup;
246 };
247
248 class FFMPEGConfigVideoToggle : public BC_CheckBox
249 {
250 public:
251         FFMPEGConfigVideoToggle(FFMPEGConfigVideo *popup,
252                 char *title_text, int x, int y, int *output);
253         int handle_event();
254         int *output;
255         FFMPEGConfigVideo *popup;
256 };
257
258 class FFMPEGScanProgress : public Thread
259 {
260 public:
261         IndexFile *index_file;
262         MainProgressBar *progress_bar;
263         char progress_title[BCTEXTLEN];
264         int64_t length, *position;
265         int done, *canceled;
266
267         FFMPEGScanProgress(IndexFile *index_file, MainProgressBar *progress_bar,
268                 const char *title, int64_t length, int64_t *position, int *canceled);
269         ~FFMPEGScanProgress();
270         void run();
271 };
272
273
274 class FFOptions_OptName : public BC_ListBoxItem {
275 public:
276         FFOptions_Opt *opt;
277
278         FFOptions_OptName(FFOptions_Opt *opt, const char *nm);
279         ~FFOptions_OptName();
280
281 };
282
283 class FFOptions_OptValue : public BC_ListBoxItem {
284 public:
285         FFOptions_Opt *opt;
286
287         void update();
288         void update(const char *v);
289         FFOptions_OptValue(FFOptions_Opt *opt);
290 };
291
292 class FFOptions_Opt {
293 public:
294         FFOptions *options;
295         const AVOption *opt;
296         FFOptions_OptName *item_name;
297         FFOptions_OptValue *item_value;
298
299         char *get(char *vp, int sz=-1);
300         void set(const char *val);
301         int types(char *rp);
302         int scalar(double d, char *rp);
303         int ranges(char *rp);
304         int units(ArrayList<const char *> &opts);
305         const char *unit_name(int id);
306         int units(char *rp);
307         const char *tip();
308
309         FFOptions_Opt(FFOptions *options, const AVOption *opt, const char *nm);
310         ~FFOptions_Opt();
311 };
312
313 class FFOptions : public ArrayList<FFOptions_Opt *>
314 {
315 public:
316         FFOptions();
317         ~FFOptions();
318         FFOptionsWindow *win;
319         AVCodecContext *avctx;
320         const void *obj;
321
322         void initialize(FFOptionsWindow *win, int k);
323         static int cmpr(const void *a, const void *b);
324         int update();
325         void dump(FILE *fp);
326 };
327
328 class FFOptions_OptPanel : public BC_ListBox {
329 public:
330         FFOptions_OptPanel(FFOptionsWindow *fwin, int x, int y, int w, int h);
331         ~FFOptions_OptPanel();
332         void create_objects();
333         int cursor_leave_event();
334
335         FFOptionsWindow *fwin;
336         ArrayList<BC_ListBoxItem*> items[2];
337         ArrayList<BC_ListBoxItem*> &opts;
338         ArrayList<BC_ListBoxItem*> &vals;
339         char tip_text[BCTEXTLEN];
340
341         int selection_changed();
342         int update();
343         void show_tip(const char *tip);
344 };
345
346 class FFOptionsKindItem : public BC_MenuItem
347 {
348 public:
349         FFOptionsKind *kind;
350         int idx;
351         int handle_event();
352         void show_label();
353
354         FFOptionsKindItem(FFOptionsKind *kind, const char *name, int idx);
355         ~FFOptionsKindItem();
356 };
357
358 class FFOptionsKind : public BC_PopupMenu
359 {
360         static const char *kinds[];
361 public:
362         FFOptionsWindow *fwin;
363         int kind;
364
365         void create_objects();
366         int handle_event();
367         void set(int k);
368
369         FFOptionsKind(FFOptionsWindow *fwin, int x, int y, int w);
370         ~FFOptionsKind();
371 };
372
373 class FFOptionsUnits : public BC_PopupMenu {
374 public:
375         FFOptionsWindow *fwin;
376
377         FFOptionsUnits(FFOptionsWindow *fwin, int x, int y, int w);
378         ~FFOptionsUnits();
379         int handle_event();
380 };
381
382 class FFOptionsText : public BC_TextBox {
383 public:
384         FFOptionsWindow *fwin;
385
386         FFOptionsText(FFOptionsWindow *fwin, int x, int y, int w);
387         ~FFOptionsText();
388         int handle_event();
389 };
390
391 class FFOptionsApply : public BC_GenericButton {
392 public:
393         FFOptionsWindow *fwin;
394
395         FFOptionsApply(FFOptionsWindow *fwin, int x, int y);
396         ~FFOptionsApply();
397         int handle_event();
398 };
399
400 class FFOptionsWindow : public BC_Window
401 {
402 public:
403         FFOptionsWindow(FFOptionsDialog *dialog);
404         ~FFOptionsWindow();
405
406         void create_objects();
407         void update(FFOptions_Opt *oip);
408         void draw();
409         int resize_event(int w, int h);
410
411         FFOptionsDialog *dialog;
412         FFOptions options;
413
414         FFOptions_OptPanel *panel;
415         int panel_x, panel_y, panel_w, panel_h;
416         BC_Title *type, *range, *kind_title;
417         FFOptions_Opt *selected;
418
419         FFOptionsKind *kind;
420         FFOptionsUnits *units;
421         FFOptionsText *text;
422         FFOptionsApply *apply;
423 };
424
425 class FFOptionsDialog : public BC_DialogThread
426 {
427 public:
428         FFOptionsDialog();
429         ~FFOptionsDialog();
430         virtual void update_options(const char *options) = 0;
431
432         void load_options(const char *bp, int len);
433         void store_options(char *cp, int len);
434         void start(const char *format_name, const char *codec_name,
435                 AVCodec *codec, const char *options, int len);
436         BC_Window* new_gui();
437         void handle_done_event(int result);
438
439         FFOptionsWindow *options_window;
440         const char *format_name, *codec_name;
441         AVCodec *codec;
442         AVDictionary *ff_opts;
443         int ff_len;
444 };
445
446 class FFOptionsAudioDialog : public FFOptionsDialog
447 {
448 public:
449         FFMPEGConfigAudio *aud_config;
450         void update_options(const char *options);
451
452         FFOptionsAudioDialog(FFMPEGConfigAudio *aud_config);
453         ~FFOptionsAudioDialog();
454 };
455
456 class FFOptionsVideoDialog : public FFOptionsDialog
457 {
458 public:
459         FFMPEGConfigVideo *vid_config;
460         void update_options(const char *options);
461
462         FFOptionsVideoDialog(FFMPEGConfigVideo *vid_config);
463         ~FFOptionsVideoDialog();
464 };
465
466 class FFOptionsViewAudio: public BC_GenericButton
467 {
468 public:
469         FFOptionsViewAudio(FFMPEGConfigAudio *aud_config, int x, int y, const char *text);
470         ~FFOptionsViewAudio();
471
472         int handle_event();
473         FFMPEGConfigAudio *aud_config;
474 };
475
476 class FFOptionsViewVideo : public BC_GenericButton
477 {
478 public:
479         FFOptionsViewVideo(FFMPEGConfigVideo *vid_config, int x, int y, const char *text);
480         ~FFOptionsViewVideo();
481
482         int handle_event();
483         FFMPEGConfigVideo *vid_config;
484 };
485
486 #endif