4 * Copyright (C) 2008 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.inc"
28 #include "bccapture.inc"
31 #include "channel.inc"
32 #include "channeldb.inc"
33 #include "device1394output.inc"
34 #include "devicempeginput.inc"
38 #include "mwindow.inc"
40 #include "preferences.inc"
41 #include "recordmonitor.inc"
43 #include "picture.inc"
44 #include "vdevicebase.inc"
45 #include "vdevicex11.inc"
46 #include "videoconfig.inc"
47 #include "videowindow.inc"
49 #include "audio1394.inc"
50 #include "device1394output.inc"
51 #include "vdevice1394.inc"
55 // The keepalive thread runs continuously during recording.
56 // If the recording thread doesn't reset still_alive, failed is incremented.
57 // Failed is set to 0 if the recording thread resets still_alive.
58 // It calls goose_input in the VideoDevice. The input driver should
59 // trap goose_input and restart itself asynchronous of the recording thread.
61 // Number of seconds for keepalive to freak out
62 #define KEEPALIVE_DELAY 0.5
66 class KeepaliveThread : public Thread
69 KeepaliveThread(VideoDevice *device);
73 int reset_keepalive(); // Call after frame capture to reset counter
75 int start_keepalive();
90 // MWindow is required where picture settings are used, to get the defaults.
91 VideoDevice(MWindow *mwindow = 0);
96 // ===================================== Recording
97 int open_input(VideoInConfig *config,
103 // Call the constructor of the desired device.
104 // Used by fix_asset and open_input
105 VDeviceBase* new_device_base();
107 // Used for dvb interface
108 VDeviceBase* get_input_base();
109 // Used for calling OpenGL functions
110 VDeviceBase* get_output_base();
112 // Return 1 if the data is compressed.
113 // Called by Record::run to determine if compression option is fixed.
114 // Called by RecordVideo::rewind_file to determine if FileThread should call
115 // write_compressed_frames or write_frames.
116 static int is_compressed(int driver, int use_file, int use_fixed);
117 int is_compressed(int use_file, int use_fixed);
119 // Load the specific channeldb for the device type
120 static void load_channeldb(ChannelDB *channeldb, VideoInConfig *vconfig_in);
121 static void save_channeldb(ChannelDB *channeldb, VideoInConfig *vconfig_in);
124 // Return codec to store on disk if compressed
125 void fix_asset(Asset *asset, int driver);
126 static const char* drivertostr(int driver);
127 // Get the best colormodel for recording given the file format.
128 // Must be called between open_input and read_buffer.
129 int get_best_colormodel(Asset *asset);
131 int drop_frames(int frames);
132 // Specify the audio device opened concurrently with this video device
133 int set_adevice(AudioDevice *adevice);
134 // Return 1 if capturing locked up
136 // Interrupt a crashed DV device
137 int interrupt_crash();
138 // Schedule capture size to be changed.
139 int set_translation(int input_x, int input_y);
140 // Change the channel
141 int set_channel(Channel *channel);
142 int set_captioning(int mode);
143 // Set the quality of the JPEG compressor
144 void set_quality(int quality);
145 // Change field order
146 int set_field_order(int odd_field_first);
147 void set_do_cursor(int do_cursor, int do_big_cursor);
148 // Set frames to clear after translation change.
149 int set_latency_counter(int value);
150 // Values from -100 to 100
151 int set_picture(PictureConfig *picture);
152 int capture_frame(int frame_number); // Start the frame_number capturing
153 int read_buffer(VFrame *frame); // Read the next frame off the device
155 int create_channeldb(ArrayList<Channel*> *channeldb);
156 int frame_to_vframe(VFrame *frame, unsigned char *input); // Translate the captured frame to a VFrame
158 ArrayList<Channel*>* get_inputs();
159 // Create new input source if it doesn't match device_name.
160 // Otherwise return it.
161 Channel* new_input_source(char *device_name);
162 BC_Bitmap* get_bitmap();
163 DeviceMPEGInput *mpeg_device();
165 // Used by all devices to cause fd's to be not copied in fork operations.
166 int set_cloexec_flag(int desc, int value);
168 // ================================== Playback
169 int open_output(VideoOutConfig *config,
175 void set_cpus(int cpus);
176 // Slippery is only used for hardware compression drivers
177 int start_playback();
178 int interrupt_playback();
179 // Get output buffer for playback using colormodel.
180 // colormodel argument should be as close to best_colormodel as possible
181 void new_output_buffer(VFrame **output, int colormodel, EDL *edl);
182 int wait_for_startup();
183 int wait_for_completion();
184 int output_visible(); // Whether the output is visible or not.
187 long current_position(); // last frame rendered
188 double get_timestamp(); // timestamp last frame
189 double device_timestamp(); // device presentation timestamp
190 // absolute frame of last frame in buffer.
191 // The EDL parameter is passed to Canvas and can be 0.
192 int write_buffer(VFrame *output, EDL *edl);
193 // record menu auto config update
194 void auto_update(double rate, int width, int height);
195 int config_updated();
196 void config_update();
197 int get_iwidth() { return capture_w; }
198 int get_iheight() { return capture_h; }
199 double get_irate() { return frame_rate; }
200 // record raw stream on file descr fd, to close use fd=-1
201 // bsz records up to bsz bytes of past buffer data in first_write
202 int start_toc(const char *path, const char *toc_path);
203 int start_record(int fd, int bsz=0);
205 int total_video_streams();
207 int get_video_pid(int track);
208 int get_video_info(int track, int &pid, double &framerate,
209 int &width, int &height, char *title=0);
210 int get_thumbnail(int stream, int64_t &position,
211 unsigned char *&thumbnail, int &ww, int &hh);
212 int set_skimming(int track, int skim, skim_fn fn, void *vp);
214 // Flag when output is interrupted
216 // Compression format in use by the output device
219 // Audio device to share data with
220 AudioDevice *adevice;
221 // Reading data from the audio device. This is set by the video device.
223 // Synchronize the close devices
229 // timer for displaying frames in the current buffer
231 // timer for getting frame rate
233 // size of output frame being fed to device during playback
237 // time from start of previous frame to start of next frame in ms
239 // CPU count for MJPEG compression
243 int is_recording; // status of thread
244 double frame_rate; // Frame rate to set in device
246 // Location of input frame in captured frame
247 int frame_in_capture_x1, frame_in_capture_x2, frame_in_capture_y1, frame_in_capture_y2;
248 int capture_in_frame_x1, capture_in_frame_x2, capture_in_frame_y1, capture_in_frame_y2;
249 // Size of raw captured frame
250 int capture_w, capture_h;
251 int input_x, input_y;
253 // Captured frame size can only be changed when ready
254 int new_input_x, new_input_y;
257 // When the frame is resized, need to clear all the buffer frames.
261 int in_config_updated;
264 // All the input sources on the device
265 ArrayList<Channel*> input_sources;
268 // Quality for the JPEG compressor
270 // Single frame mode for playback
273 // Copy of the most recent channel set by set_channel
275 // Flag for subdevice to change channels when it has a chance
279 // Copy of the most recent picture controls
281 PictureConfig *picture;
285 // Change the capture size when ready
286 int update_translation();
288 VDeviceBase *input_base;
289 VDeviceBase *output_base;
290 VideoInConfig *in_config;
291 VideoOutConfig *out_config;
292 KeepaliveThread *keepalive;