4 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
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.
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.
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
27 #include "audiodevice.h"
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"
39 #include "filexml.inc"
40 #include "filethread.inc"
41 #include "formatpopup.h"
42 #include "formattools.inc"
44 #include "loadmode.inc"
45 #include "mediadb.inc"
46 #include "mwindow.inc"
47 #include "maxchannels.h"
48 #include "picture.inc"
49 #include "playbackengine.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"
60 #define SESSION (mwindow->edl->session)
64 class RecordMenuItem : public BC_MenuItem
67 RecordMenuItem(MWindow *mwindow);
76 class RecordChannel : public Thread
83 Condition *channel_lock;
84 Condition *change_channel;
86 int set(Channel *channel);
89 RecordChannel(Record *record);
94 class Record : public Thread
97 Record(MWindow *mwindow, RecordMenuItem *menu_item);
101 void stop(int wait=1);
106 int set_current_batch(int i);
108 int set_editing_batch(int i);
109 void delete_index_file(Asset *asset);
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();
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();
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();
134 int start_record(int fd);
135 void start_writing_file();
138 void stop_writing_file();
140 void start_cron_thread();
141 void stop_cron_thread(const char *msg);
142 void set_power_off(int value);
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);
155 // Set the channel in the current batch and the picture controls
156 int set_channel_no(int chan_no);
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);
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;
171 Channel *current_channel;
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();
185 // Copied to each batch for the files
186 Asset *default_asset;
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();
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
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();
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();
244 Condition *init_lock;
245 RecordAudio *record_audio;
246 RecordVideo *record_video;
247 RecordThread *record_thread;
248 RecordBatches record_batches;
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;
261 DriveSync *drivesync;
265 RecordGUI *record_gui;
266 RecordMonitor *record_monitor;
267 AudioDevice *adevice;
268 VideoDevice *vdevice;
272 // File handle of last asset.in current batch
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
285 // Reverse the interlace in the video window display only
286 int reverse_interlace;
287 // record the cursor for screencapture
290 // Color model for uncompressed device interface
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
300 // check for commercials
301 int commercial_check, skimming_active;
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;
314 // Parameters for video monitor
319 RecordMenuItem *menu_item;
321 int get_time_format();
322 int set_record_mode(int value);
323 int is_behind() { return drop_overrun_frames && behind > 1 ? 1 : 0; }
325 int64_t dc_offset[MAXCHANNELS];
328 int video_window_w; // Width of record video window
330 int input_threads_pausing;
333 class RecordScheduleItem {
338 RecordScheduleItem(time_t st, char *t)
339 : start_time(st), title(strdup(t)) {}
340 RecordScheduleItem() { free(title); }
343 class RecordSchedule : public ArrayList<RecordScheduleItem *> {
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;
350 void sort_times() { qsort(values,size(),sizeof(values[0]),&cmpr); }
352 ~RecordSchedule() { remove_all_objects(); }
355 class RecordRemoteHandler : public RemoteHandler
358 int remote_process_key(RemoteControl *remote_control, int key);
359 int spawn(const char *fmt, ...);
361 RecordRemoteHandler(RemoteControl *remote_control);
362 ~RecordRemoteHandler();
365 class RecordCutAdsStatus : public Thread
369 Condition *wait_lock;
372 void start_waiting();
375 RecordCutAdsStatus(Record *record);
376 ~RecordCutAdsStatus();
379 class RecordBlinkStatus : public Thread
386 void remote_color(int color);
391 RecordBlinkStatus(Record *record);
392 ~RecordBlinkStatus();