add haupauge-1657 dual usb capture support, add deinterlace to recordmonitor, asset...
[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 remote_process_key(RemoteControl *remote_control, int key);
237         int spawn(const char *fmt, ...);
238         void display_video_text(int x, int y, const char *text, int font,
239                 int bg_color, int color, int alpha, double secs, double scale);
240         void display_cut_icon(int x, int y);
241         void display_vframe(VFrame *in, int x, int y, int alpha,
242                 double secs, double scale);
243         int display_channel_info();
244         int display_channel_schedule();
245         void undisplay_vframe();
246         DeviceDVBInput *dvb_device();
247
248         Condition *init_lock;
249         RecordAudio *record_audio;
250         RecordVideo *record_video;
251         RecordThread *record_thread;
252         RecordBatches record_batches;
253         int capturing;
254         int recording;
255         int single_frame;
256         int writing_file;  // -1/writing stream, 0/not writing, 1/transcoding
257         int do_audio;      // output audio if writing_file
258         int do_video;      // output video if writing_file
259         int64_t current_frame, written_frames, total_frames;
260         int64_t current_sample, written_samples, total_samples;
261         double audio_time, video_time;
262         double play_gain, mute_gain;
263
264         Mutex *pause_lock;
265         DriveSync *drivesync;
266
267         LoadMode *loadmode;
268         MWindow *mwindow;
269         RecordGUI *record_gui;
270         RecordMonitor *record_monitor;
271         AudioDevice *adevice;
272         VideoDevice *vdevice;
273         Mutex *adevice_lock;
274         Mutex *vdevice_lock;
275         Mutex *batch_lock;
276 // File handle of last asset.in current batch
277         File *file;
278
279 // Table for LML conversion
280 //      unsigned char _601_to_rgb_table[256];
281 // For video synchronization when no audio thread
282         Timer timer, total_time;
283         int64_t session_sample_offset;
284         int64_t device_sample_offset;
285 // Translation of screencapture input
286         int video_x;
287         int video_y;
288         float video_zoom;
289 // Reverse the interlace in the video window display only
290         int reverse_interlace;
291 // record the cursor for screencapture
292         int do_cursor;
293         int do_big_cursor;
294 // Color model for uncompressed device interface
295         int color_model;
296 // Picture quality and parameters the device supports
297         PictureConfig *picture;
298 // Drop input frames when behind
299         int drop_overrun_frames;
300 // Fill frames with duplicates when behind
301         int fill_underrun_frames;
302 // power off system when batch record ends
303         int power_off;
304 // check for commercials
305         int commercial_check, skimming_active;
306         int commercial_fd;
307         int64_t commercial_start_time;
308         SkimDbThread *skim_thread;
309 // cut commerical, update mediadb
310         Deletions *deletions;
311         RecordCutAdsStatus *cutads_status;
312         RecordBlinkStatus *blink_status;
313         ArrayList<int> cut_pids;
314         int status_color;
315         int last_key;
316         char keybfr[8];
317
318 // Parameters for video monitor
319         EDL *edl;
320         Mutex *window_lock;
321         Mutex *timer_lock;
322         Mutex *file_lock;
323         RecordMenuItem *menu_item;
324
325         int get_time_format();
326         int set_record_mode(int value);
327         int is_behind() { return drop_overrun_frames && behind > 1 ? 1 : 0; }
328
329         int64_t dc_offset[MAXCHANNELS];
330         int frame_w;
331         int frame_h;
332         int video_window_w;       // Width of record video window
333         int dropped, behind;
334         int input_threads_pausing;
335         int deinterlace;
336 };
337
338 class RecordScheduleItem {
339 public:
340         time_t start_time;
341         char *title;
342
343         RecordScheduleItem(time_t st, char *t)
344          : start_time(st), title(strdup(t)) {}
345         RecordScheduleItem() { free(title); }
346 };
347
348 class RecordSchedule : public ArrayList<RecordScheduleItem *> {
349 public:
350         static int cmpr(const void *a, const void*b) {
351                 const RecordScheduleItem *ap = *(const RecordScheduleItem **)a;
352                 const RecordScheduleItem *bp = *(const RecordScheduleItem **)b;
353                 return ap->start_time < bp->start_time ? -1 : 1;
354         }
355         void sort_times() { qsort(values,size(),sizeof(values[0]),&cmpr); }
356         RecordSchedule() {}
357         ~RecordSchedule() { remove_all_objects(); }
358 };
359
360 class RecordRemoteHandler : public RemoteHandler
361 {
362 public:
363         int remote_process_key(RemoteControl *remote_control, int key);
364         int spawn(const char *fmt, ...);
365
366         RecordRemoteHandler(RemoteControl *remote_control);
367         ~RecordRemoteHandler();
368 };
369
370 class RecordCutAdsStatus : public Thread
371 {
372 public:
373         Record *record;
374         Condition *wait_lock;
375
376         int done;
377         void start_waiting();
378         void run();
379
380         RecordCutAdsStatus(Record *record);
381         ~RecordCutAdsStatus();
382 };
383
384 class RecordBlinkStatus : public Thread
385 {
386         int done;
387         Timer timer;
388 public:
389         Record *record;
390         void update();
391         void remote_color(int color);
392         void start();
393         void stop();
394         void run();
395
396         RecordBlinkStatus(Record *record);
397         ~RecordBlinkStatus();
398 };
399
400 #endif