18 new shapewipe transitions from rafa, rework savefile/confirm for nested edl edits
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / record.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 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 RECORD_H
23 #define RECORD_H
24
25 #include "asset.inc"
26 #include "assets.inc"
27 #include "audiodevice.h"
28 #include "batch.inc"
29 #include "bchash.inc"
30 #include "bitspopup.h"
31 #include "browsebutton.h"
32 #include "channel.inc"
33 #include "channeldb.inc"
34 #include "commercials.inc"
35 #include "devicedvbinput.inc"
36 #include "drivesync.inc"
37 #include "edl.inc"
38 #include "file.inc"
39 #include "filexml.inc"
40 #include "filethread.inc"
41 #include "formatpopup.h"
42 #include "formattools.inc"
43 #include "guicast.h"
44 #include "loadmode.inc"
45 #include "mediadb.inc"
46 #include "mwindow.inc"
47 #include "maxchannels.h"
48 #include "picture.inc"
49 #include "playbackengine.inc"
50 #include "record.inc"
51 #include "recordbatches.h"
52 #include "recordgui.inc"
53 #include "recordaudio.inc"
54 #include "recordmonitor.inc"
55 #include "recordthread.inc"
56 #include "recordvideo.inc"
57 #include "remotecontrol.h"
58 #include "videodevice.inc"
59
60 #define SESSION (mwindow->edl->session)
61
62 #define RECORD_LACE_NONE 0
63 #define RECORD_LACE_ODD 1
64 #define RECORD_LACE_EVEN 2
65
66 class Record;
67
68 class RecordMenuItem : public BC_MenuItem
69 {
70 public:
71         RecordMenuItem(MWindow *mwindow);
72         ~RecordMenuItem();
73
74         int handle_event();
75
76         Record *record;
77         MWindow *mwindow;
78 };
79
80 class RecordChannel : public Thread
81 {
82 public:
83         int done;
84         Record *record;
85         Channel *new_channel;
86         int audio_drain;
87         Condition *channel_lock;
88         Condition *change_channel;
89         void run();
90         int set(Channel *channel);
91         void drain_audio();
92
93         RecordChannel(Record *record);
94         ~RecordChannel();
95 };
96
97
98 class Record : public Thread
99 {
100 public:
101         Record(MWindow *mwindow, RecordMenuItem *menu_item);
102         ~Record();
103
104         void run();
105         void stop(int wait=1);
106         int load_defaults();
107         int save_defaults();
108         Batch* new_batch();
109         int current_batch();
110         int set_current_batch(int i);
111         int editing_batch();
112         int set_editing_batch(int i);
113         void delete_index_file(Asset *asset);
114         void delete_batch();
115         void activate_batch(int number);
116         void change_editing_batch(int number);
117         void close_output_file();
118         int get_fragment_samples();
119         int get_buffer_samples();
120
121         void close_video_input();
122         void close_audio_input();
123         void close_input_devices();
124         void stop_audio_thread();
125         void stop_video_thread();
126         void stop_input_threads();
127         void stop_playback();
128         void open_audio_input();
129         void open_video_input();
130         void start();
131         void start_audio_thread();
132         void start_video_thread();
133         void start_input_threads();
134         void pause_input_threads();
135         void resume_input_threads();
136         void adevice_drain();
137         int start_toc();
138         int start_record(int fd);
139         void start_writing_file();
140         void flush_buffer();
141         int stop_record();
142         void stop_writing_file();
143         void stop_writing();
144         void start_cron_thread();
145         void stop_cron_thread(const char *msg);
146         void set_power_off(int value);
147
148         void set_audio_monitoring(int mode);
149         void set_audio_metering(int mode);
150         void set_mute_gain(double gain);
151         void set_play_gain(double gain);
152         void set_video_monitoring(int mode);
153         void stop_operation();
154         void set_video_picture();
155         void set_do_cursor();
156 // Set screencapture translation
157         void set_translation(int x, int y);
158
159 // Set the channel in the current batch and the picture controls
160         int set_channel_no(int chan_no);
161         int channel_down();
162         int channel_up();
163         int set_channel_name(const char *name);
164         int set_channel(Channel *channel);
165         void set_batch_channel_no(int chan_no);
166         void set_dev_channel(Channel *channel);
167         int has_signal();
168         int create_channeldb(ArrayList<Channel*> *channeldb);
169 // User defined TV stations and inputs to record from.
170         ChannelDB *channeldb;
171 // Structure which stores what parameters the device supports
172         Channel *master_channel;
173         RecordChannel *record_channel;
174         Channel *channel;
175         Channel *current_channel;
176
177         void toggle_label();
178         void clear_labels();
179 // Set values in batch structures
180         void configure_batches();
181 // Create first file in batch
182         int open_output_file();
183 // Delete the output file for overwrite if it exists.
184         int delete_output_file();
185 // Get the inputs supported by the device
186         ArrayList<Channel*>* get_video_inputs();
187         int cron_active();
188
189 // Copied to each batch for the files
190         Asset *default_asset;
191         int load_mode;
192         int monitor_audio;
193         int metering_audio;
194         int monitor_video;
195         int video_window_open;
196 // Compression is fixed by the driver
197         int fixed_compression;
198 // Get next batch using activation or -1
199         int get_next_batch(int incr=1);
200 // Information about the current batch.
201         Batch* get_current_batch();
202 // Information about the batch being edited
203         Batch* get_editing_batch();
204         const char* current_mode();
205         const char* current_source();
206         Channel *get_current_channel();
207         Channel *get_editing_channel();
208         Asset* current_asset();
209 // Total number of samples since record sequence started
210         int64_t timer_position();
211         void reset_position(int64_t position);
212         void update_position();
213         int64_t adevice_position();
214         int64_t sync_position();
215         void resync();
216 // Current position for GUI relative to batch
217         double current_display_position();
218         int check_batch_complete();
219 // Rewind the current file in the current batch
220         void start_over();
221
222 // skimming for commericials
223         static int skimming(void *vp, int track);
224         int skimming(int track);
225         void start_skimming();
226         void stop_skimming();
227         void update_skimming(int v);
228         int start_commercial_capture();
229         int mark_commercial_capture(int action);
230         int stop_commercial_capture(int run_job);
231         void set_status_color(int color);
232         void remote_fill_color(int color);
233         int commercial_jobs();
234         void clear_keybfr();
235         void add_key(int ch);
236         int record_process_key(RemoteControl *remote_control, int key);
237         int wintv_process_code(int code);
238         int x10tv_process_code(int code);
239         int spawn(const char *fmt, ...);
240         void display_video_text(int x, int y, const char *text, int font,
241                 int bg_color, int color, int alpha, double secs, double scale);
242         void display_cut_icon(int x, int y);
243         void display_vframe(VFrame *in, int x, int y, int alpha,
244                 double secs, double scale);
245         int display_channel_info();
246         int display_channel_schedule();
247         void undisplay_vframe();
248         DeviceDVBInput *dvb_device();
249
250         Condition *init_lock;
251         RecordAudio *record_audio;
252         RecordVideo *record_video;
253         RecordThread *record_thread;
254         RecordBatches record_batches;
255         int capturing;
256         int recording;
257         int single_frame;
258         int writing_file;  // -1/writing stream, 0/not writing, 1/transcoding
259         int do_audio;      // output audio if writing_file
260         int do_video;      // output video if writing_file
261         int64_t current_frame, written_frames, total_frames;
262         int64_t current_sample, written_samples, total_samples;
263         double audio_time, video_time;
264         double play_gain, mute_gain;
265
266         Mutex *pause_lock;
267         DriveSync *drivesync;
268
269         LoadMode *loadmode;
270         MWindow *mwindow;
271         RecordGUI *record_gui;
272         RecordMonitor *record_monitor;
273         AudioDevice *adevice;
274         VideoDevice *vdevice;
275         Mutex *adevice_lock;
276         Mutex *vdevice_lock;
277         Mutex *batch_lock;
278 // File handle of last asset.in current batch
279         File *file;
280
281 // Table for LML conversion
282 //      unsigned char _601_to_rgb_table[256];
283 // For video synchronization when no audio thread
284         Timer timer, total_time;
285         int64_t session_sample_offset;
286         int64_t device_sample_offset;
287 // Translation of screencapture input
288         int video_x;
289         int video_y;
290         float video_zoom;
291 // Reverse the interlace in the video window display only
292         int reverse_interlace;
293 // record the cursor for screencapture
294         int do_cursor;
295         int do_big_cursor;
296 // Color model for uncompressed device interface
297         int color_model;
298 // Picture quality and parameters the device supports
299         PictureConfig *picture;
300 // Drop input frames when behind
301         int drop_overrun_frames;
302 // Fill frames with duplicates when behind
303         int fill_underrun_frames;
304 // power off system when batch record ends
305         int power_off;
306 // check for commercials
307         int commercial_check, skimming_active;
308         int commercial_fd;
309         int64_t commercial_start_time;
310         SkimDbThread *skim_thread;
311 // cut commerical, update mediadb
312         Deletions *deletions;
313         RecordCutAdsStatus *cutads_status;
314         RecordBlinkStatus *blink_status;
315         ArrayList<int> cut_pids;
316         int status_color;
317         int last_key;
318         char keybfr[8];
319
320 // Parameters for video monitor
321         EDL *edl;
322         Mutex *window_lock;
323         Mutex *timer_lock;
324         Mutex *file_lock;
325         RecordMenuItem *menu_item;
326
327         int get_time_format();
328         int set_record_mode(int value);
329         int is_behind() { return drop_overrun_frames && behind > 1 ? 1 : 0; }
330
331         int64_t dc_offset[MAXCHANNELS];
332         int frame_w;
333         int frame_h;
334         int video_window_w;       // Width of record video window
335         int dropped, behind;
336         int input_threads_pausing;
337         int deinterlace;
338 };
339
340 class RecordScheduleItem {
341 public:
342         time_t start_time;
343         char *title;
344
345         RecordScheduleItem(time_t st, char *t)
346          : start_time(st), title(strdup(t)) {}
347         RecordScheduleItem() { free(title); }
348 };
349
350 class RecordSchedule : public ArrayList<RecordScheduleItem *> {
351 public:
352         static int cmpr(const void *a, const void*b) {
353                 const RecordScheduleItem *ap = *(const RecordScheduleItem **)a;
354                 const RecordScheduleItem *bp = *(const RecordScheduleItem **)b;
355                 return ap->start_time < bp->start_time ? -1 : 1;
356         }
357         void sort_times() { qsort(values,size(),sizeof(values[0]),&cmpr); }
358         RecordSchedule() {}
359         ~RecordSchedule() { remove_all_objects(); }
360 };
361
362 class RecordKeyEvHandler : public RemoteHandler
363 {
364 public:
365         int remote_key(int key);
366         int spawn(const char *fmt, ...);
367
368         RecordKeyEvHandler(RemoteControl *remote_control);
369         ~RecordKeyEvHandler();
370         int is_keytv() { return 1; }
371
372         RemoteControl *remote_control;
373 };
374
375 class RecordCutAdsStatus : public Thread
376 {
377 public:
378         Record *record;
379         Condition *wait_lock;
380
381         int done;
382         void start_waiting();
383         void run();
384
385         RecordCutAdsStatus(Record *record);
386         ~RecordCutAdsStatus();
387 };
388
389 class RecordBlinkStatus : public Thread
390 {
391         int done;
392         Timer timer;
393 public:
394         Record *record;
395         void update();
396         void remote_color(int color);
397         void start();
398         void stop();
399         void run();
400
401         RecordBlinkStatus(Record *record);
402         ~RecordBlinkStatus();
403 };
404
405 #endif