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);
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 int set_video_picture();
151 // Set screencapture translation
152 void set_translation(int x, int y);
154 // Set the channel in the current batch and the picture controls
155 int set_channel_no(int chan_no);
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);
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;
170 Channel *current_channel;
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();
184 // Copied to each batch for the files
185 Asset *default_asset;
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();
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
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();
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();
243 Condition *init_lock;
244 RecordAudio *record_audio;
245 RecordVideo *record_video;
246 RecordThread *record_thread;
247 RecordBatches record_batches;
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;
260 DriveSync *drivesync;
264 RecordGUI *record_gui;
265 RecordMonitor *record_monitor;
266 AudioDevice *adevice;
267 VideoDevice *vdevice;
271 // File handle of last asset.in current batch
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
284 // Reverse the interlace in the video window display only
285 int reverse_interlace;
286 // Color model for uncompressed device interface
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
296 // check for commercials
297 int commercial_check, skimming_active;
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;
310 // Parameters for video monitor
315 RecordMenuItem *menu_item;
317 int get_time_format();
318 int set_record_mode(int value);
319 int is_behind() { return drop_overrun_frames && behind > 1 ? 1 : 0; }
321 int64_t dc_offset[MAXCHANNELS];
324 int video_window_w; // Width of record video window
326 int input_threads_pausing;
329 class RecordScheduleItem {
334 RecordScheduleItem(time_t st, char *t)
335 : start_time(st), title(strdup(t)) {}
336 RecordScheduleItem() { free(title); }
339 class RecordSchedule : public ArrayList<RecordScheduleItem *> {
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;
346 void sort_times() { qsort(values,size(),sizeof(values[0]),&cmpr); }
348 ~RecordSchedule() { remove_all_objects(); }
351 class RecordRemoteHandler : public RemoteHandler
354 int remote_process_key(RemoteControl *remote_control, int key);
355 int spawn(const char *fmt, ...);
357 RecordRemoteHandler(RemoteControl *remote_control);
358 ~RecordRemoteHandler();
361 class RecordCutAdsStatus : public Thread
365 Condition *wait_lock;
368 void start_waiting();
371 RecordCutAdsStatus(Record *record);
372 ~RecordCutAdsStatus();
375 class RecordBlinkStatus : public Thread
382 void remote_color(int color);
387 RecordBlinkStatus(Record *record);
388 ~RecordBlinkStatus();