rework/fixes for paste edits, cinermt suspend uses acpitool
[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 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(int wait=1);
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         void set_video_picture();
151         void set_do_cursor();
152 // Set screencapture translation
153         void set_translation(int x, int y);
154
155 // Set the channel in the current batch and the picture controls
156         int set_channel_no(int chan_no);
157         int channel_down();
158         int channel_up();
159         int set_channel_name(const char *name);
160         int set_channel(Channel *channel);
161         void set_batch_channel_no(int chan_no);
162         void set_dev_channel(Channel *channel);
163         int has_signal();
164         int create_channeldb(ArrayList<Channel*> *channeldb);
165 // User defined TV stations and inputs to record from.
166         ChannelDB *channeldb;
167 // Structure which stores what parameters the device supports
168         Channel *master_channel;
169         RecordChannel *record_channel;
170         Channel *channel;
171         Channel *current_channel;
172
173         void toggle_label();
174         void clear_labels();
175 // Set values in batch structures
176         void configure_batches();
177 // Create first file in batch
178         int open_output_file();
179 // Delete the output file for overwrite if it exists.
180         int delete_output_file();
181 // Get the inputs supported by the device
182         ArrayList<Channel*>* get_video_inputs();
183         int cron_active();
184
185 // Copied to each batch for the files
186         Asset *default_asset;
187         int load_mode;
188         int monitor_audio;
189         int metering_audio;
190         int monitor_video;
191         int video_window_open;
192 // Compression is fixed by the driver
193         int fixed_compression;
194 // Get next batch using activation or -1
195         int get_next_batch(int incr=1);
196 // Information about the current batch.
197         Batch* get_current_batch();
198 // Information about the batch being edited
199         Batch* get_editing_batch();
200         const char* current_mode();
201         const char* current_source();
202         Channel *get_current_channel();
203         Channel *get_editing_channel();
204         Asset* current_asset();
205 // Total number of samples since record sequence started
206         int64_t timer_position();
207         void reset_position(int64_t position);
208         void update_position();
209         int64_t adevice_position();
210         int64_t sync_position();
211         void resync();
212 // Current position for GUI relative to batch
213         double current_display_position();
214         int check_batch_complete();
215 // Rewind the current file in the current batch
216         void start_over();
217
218 // skimming for commericials
219         static int skimming(void *vp, int track);
220         int skimming(int track);
221         void start_skimming();
222         void stop_skimming();
223         void update_skimming(int v);
224         int start_commercial_capture();
225         int mark_commercial_capture(int action);
226         int stop_commercial_capture(int run_job);
227         void set_status_color(int color);
228         void remote_fill_color(int color);
229         int commercial_jobs();
230         void clear_keybfr();
231         void add_key(int ch);
232         int remote_process_key(RemoteControl *remote_control, int key);
233         int spawn(const char *fmt, ...);
234         void display_video_text(int x, int y, const char *text, int font,
235                 int bg_color, int color, int alpha, double secs, double scale);
236         void display_cut_icon(int x, int y);
237         void display_vframe(VFrame *in, int x, int y, int alpha,
238                 double secs, double scale);
239         int display_channel_info();
240         int display_channel_schedule();
241         void undisplay_vframe();
242         DeviceDVBInput *dvb_device();
243
244         Condition *init_lock;
245         RecordAudio *record_audio;
246         RecordVideo *record_video;
247         RecordThread *record_thread;
248         RecordBatches record_batches;
249         int capturing;
250         int recording;
251         int single_frame;
252         int writing_file;  // -1/writing stream, 0/not writing, 1/transcoding
253         int do_audio;      // output audio if writing_file
254         int do_video;      // output video if writing_file
255         int64_t current_frame, written_frames, total_frames;
256         int64_t current_sample, written_samples, total_samples;
257         double audio_time, video_time;
258         double play_gain, mute_gain;
259
260         Mutex *pause_lock;
261         DriveSync *drivesync;
262
263         LoadMode *loadmode;
264         MWindow *mwindow;
265         RecordGUI *record_gui;
266         RecordMonitor *record_monitor;
267         AudioDevice *adevice;
268         VideoDevice *vdevice;
269         Mutex *adevice_lock;
270         Mutex *vdevice_lock;
271         Mutex *batch_lock;
272 // File handle of last asset.in current batch
273         File *file;
274
275 // Table for LML conversion
276 //      unsigned char _601_to_rgb_table[256];
277 // For video synchronization when no audio thread
278         Timer timer, total_time;
279         int64_t session_sample_offset;
280         int64_t device_sample_offset;
281 // Translation of screencapture input
282         int video_x;
283         int video_y;
284         float video_zoom;
285 // Reverse the interlace in the video window display only
286         int reverse_interlace;
287 // record the cursor for screencapture
288         int do_cursor;
289         int do_big_cursor;
290 // Color model for uncompressed device interface
291         int color_model;
292 // Picture quality and parameters the device supports
293         PictureConfig *picture;
294 // Drop input frames when behind
295         int drop_overrun_frames;
296 // Fill frames with duplicates when behind
297         int fill_underrun_frames;
298 // power off system when batch record ends
299         int power_off;
300 // check for commercials
301         int commercial_check, skimming_active;
302         int commercial_fd;
303         int64_t commercial_start_time;
304         SkimDbThread *skim_thread;
305 // cut commerical, update mediadb
306         Deletions *deletions;
307         RecordCutAdsStatus *cutads_status;
308         RecordBlinkStatus *blink_status;
309         ArrayList<int> cut_pids;
310         int status_color;
311         int last_key;
312         char keybfr[8];
313
314 // Parameters for video monitor
315         EDL *edl;
316         Mutex *window_lock;
317         Mutex *timer_lock;
318         Mutex *file_lock;
319         RecordMenuItem *menu_item;
320
321         int get_time_format();
322         int set_record_mode(int value);
323         int is_behind() { return drop_overrun_frames && behind > 1 ? 1 : 0; }
324
325         int64_t dc_offset[MAXCHANNELS];
326         int frame_w;
327         int frame_h;
328         int video_window_w;       // Width of record video window
329         int dropped, behind;
330         int input_threads_pausing;
331 };
332
333 class RecordScheduleItem {
334 public:
335         time_t start_time;
336         char *title;
337
338         RecordScheduleItem(time_t st, char *t)
339          : start_time(st), title(strdup(t)) {}
340         RecordScheduleItem() { free(title); }
341 };
342
343 class RecordSchedule : public ArrayList<RecordScheduleItem *> {
344 public:
345         static int cmpr(const void *a, const void*b) {
346                 const RecordScheduleItem *ap = *(const RecordScheduleItem **)a;
347                 const RecordScheduleItem *bp = *(const RecordScheduleItem **)b;
348                 return ap->start_time < bp->start_time ? -1 : 1;
349         }
350         void sort_times() { qsort(values,size(),sizeof(values[0]),&cmpr); }
351         RecordSchedule() {}
352         ~RecordSchedule() { remove_all_objects(); }
353 };
354
355 class RecordRemoteHandler : public RemoteHandler
356 {
357 public:
358         int remote_process_key(RemoteControl *remote_control, int key);
359         int spawn(const char *fmt, ...);
360
361         RecordRemoteHandler(RemoteControl *remote_control);
362         ~RecordRemoteHandler();
363 };
364
365 class RecordCutAdsStatus : public Thread
366 {
367 public:
368         Record *record;
369         Condition *wait_lock;
370
371         int done;
372         void start_waiting();
373         void run();
374
375         RecordCutAdsStatus(Record *record);
376         ~RecordCutAdsStatus();
377 };
378
379 class RecordBlinkStatus : public Thread
380 {
381         int done;
382         Timer timer;
383 public:
384         Record *record;
385         void update();
386         void remote_color(int color);
387         void start();
388         void stop();
389         void run();
390
391         RecordBlinkStatus(Record *record);
392         ~RecordBlinkStatus();
393 };
394
395 #endif