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)
62 #define RECORD_LACE_NONE 0
63 #define RECORD_LACE_ODD 1
64 #define RECORD_LACE_EVEN 2
68 class RecordMenuItem : public BC_MenuItem
71 RecordMenuItem(MWindow *mwindow);
80 class RecordChannel : public Thread
87 Condition *channel_lock;
88 Condition *change_channel;
90 int set(Channel *channel);
93 RecordChannel(Record *record);
98 class Record : public Thread
101 Record(MWindow *mwindow, RecordMenuItem *menu_item);
105 void stop(int wait=1);
110 int set_current_batch(int i);
112 int set_editing_batch(int i);
113 void delete_index_file(Asset *asset);
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();
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();
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();
138 int start_record(int fd);
139 void start_writing_file();
142 void stop_writing_file();
144 void start_cron_thread();
145 void stop_cron_thread(const char *msg);
146 void set_power_off(int value);
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);
159 // Set the channel in the current batch and the picture controls
160 int set_channel_no(int chan_no);
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);
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;
175 Channel *current_channel;
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();
189 // Copied to each batch for the files
190 Asset *default_asset;
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();
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
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();
235 void add_key(int ch);
236 int record_process_key(RemoteControl *remote_control, int key);
237 int wintv_process_code(int code);
238 int x10tv_process_code(int code);
239 int spawn(const char *fmt, ...);
240 void display_video_text(int x, int y, const char *text, int font,
241 int bg_color, int color, int alpha, double secs, double scale);
242 void display_cut_icon(int x, int y);
243 void display_vframe(VFrame *in, int x, int y, int alpha,
244 double secs, double scale);
245 int display_channel_info();
246 int display_channel_schedule();
247 void undisplay_vframe();
248 DeviceDVBInput *dvb_device();
250 Condition *init_lock;
251 RecordAudio *record_audio;
252 RecordVideo *record_video;
253 RecordThread *record_thread;
254 RecordBatches record_batches;
258 int writing_file; // -1/writing stream, 0/not writing, 1/transcoding
259 int do_audio; // output audio if writing_file
260 int do_video; // output video if writing_file
261 int64_t current_frame, written_frames, total_frames;
262 int64_t current_sample, written_samples, total_samples;
263 double audio_time, video_time;
264 double play_gain, mute_gain;
267 DriveSync *drivesync;
271 RecordGUI *record_gui;
272 RecordMonitor *record_monitor;
273 AudioDevice *adevice;
274 VideoDevice *vdevice;
278 // File handle of last asset.in current batch
281 // Table for LML conversion
282 // unsigned char _601_to_rgb_table[256];
283 // For video synchronization when no audio thread
284 Timer timer, total_time;
285 int64_t session_sample_offset;
286 int64_t device_sample_offset;
287 // Translation of screencapture input
291 // Reverse the interlace in the video window display only
292 int reverse_interlace;
293 // record the cursor for screencapture
296 // Color model for uncompressed device interface
298 // Picture quality and parameters the device supports
299 PictureConfig *picture;
300 // Drop input frames when behind
301 int drop_overrun_frames;
302 // Fill frames with duplicates when behind
303 int fill_underrun_frames;
304 // power off system when batch record ends
306 // check for commercials
307 int commercial_check, skimming_active;
309 int64_t commercial_start_time;
310 SkimDbThread *skim_thread;
311 // cut commerical, update mediadb
312 Deletions *deletions;
313 RecordCutAdsStatus *cutads_status;
314 RecordBlinkStatus *blink_status;
315 ArrayList<int> cut_pids;
320 // Parameters for video monitor
325 RecordMenuItem *menu_item;
327 int get_time_format();
328 int set_record_mode(int value);
329 int is_behind() { return drop_overrun_frames && behind > 1 ? 1 : 0; }
331 int64_t dc_offset[MAXCHANNELS];
334 int video_window_w; // Width of record video window
336 int input_threads_pausing;
340 class RecordScheduleItem {
345 RecordScheduleItem(time_t st, char *t)
346 : start_time(st), title(strdup(t)) {}
347 RecordScheduleItem() { free(title); }
350 class RecordSchedule : public ArrayList<RecordScheduleItem *> {
352 static int cmpr(const void *a, const void*b) {
353 const RecordScheduleItem *ap = *(const RecordScheduleItem **)a;
354 const RecordScheduleItem *bp = *(const RecordScheduleItem **)b;
355 return ap->start_time < bp->start_time ? -1 : 1;
357 void sort_times() { qsort(values,size(),sizeof(values[0]),&cmpr); }
359 ~RecordSchedule() { remove_all_objects(); }
362 class RecordKeyEvHandler : public RemoteHandler
365 int remote_key(int key);
366 int spawn(const char *fmt, ...);
368 RecordKeyEvHandler(RemoteControl *remote_control);
369 ~RecordKeyEvHandler();
370 int is_keytv() { return 1; }
372 RemoteControl *remote_control;
375 class RecordCutAdsStatus : public Thread
379 Condition *wait_lock;
382 void start_waiting();
385 RecordCutAdsStatus(Record *record);
386 ~RecordCutAdsStatus();
389 class RecordBlinkStatus : public Thread
396 void remote_color(int color);
401 RecordBlinkStatus(Record *record);
402 ~RecordBlinkStatus();