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