Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / cinelerra / videodevice.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 VIDEODEVICE_H
23 #define VIDEODEVICE_H
24
25 #include "asset.inc"
26 #include "assets.inc"
27 #include "audiodevice.inc"
28 #include "bccapture.inc"
29 #include "bctimer.h"
30 #include "canvas.inc"
31 #include "channel.inc"
32 #include "channeldb.inc"
33 #include "device1394output.inc"
34 #include "devicempeginput.inc"
35 #include "edl.inc"
36 #include "file.inc"
37 #include "guicast.h"
38 #include "mwindow.inc"
39 #include "mutex.inc"
40 #include "preferences.inc"
41 #include "recordmonitor.inc"
42 #include "thread.h"
43 #include "picture.inc"
44 #include "vdevicebase.inc"
45 #include "vdevicebuz.inc"
46 #include "vdevicelml.inc"
47 #include "vdevicev4l.inc"
48 #include "vdevicex11.inc"
49 #include "videoconfig.inc"
50 #include "videowindow.inc"
51 #ifdef HAVE_FIREWIRE
52 #include "audio1394.inc"
53 #include "device1394output.inc"
54 #include "vdevice1394.inc"
55 #endif
56
57
58 // The keepalive thread runs continuously during recording.
59 // If the recording thread doesn't reset still_alive, failed is incremented.
60 // Failed is set to 0 if the recording thread resets still_alive.
61 // It calls goose_input in the VideoDevice.  The input driver should
62 // trap goose_input and restart itself asynchronous of the recording thread.
63
64 // Number of seconds for keepalive to freak out
65 #define KEEPALIVE_DELAY 0.5
66
67 class VideoDevice;
68
69 class KeepaliveThread : public Thread
70 {
71 public:
72         KeepaliveThread(VideoDevice *device);
73         ~KeepaliveThread();
74
75         void run();
76         int reset_keepalive();   // Call after frame capture to reset counter
77         int get_failed();
78         int start_keepalive();
79         int stop();
80
81         Timer timer;
82         int still_alive;
83         int failed;
84         int interrupted;
85         VideoDevice *device;
86         Mutex *startup_lock;
87         int capturing;
88 };
89
90 class VideoDevice
91 {
92 public:
93 // MWindow is required where picture settings are used, to get the defaults.
94         VideoDevice(MWindow *mwindow = 0);
95         ~VideoDevice();
96
97         int close_all();
98
99 // ===================================== Recording
100         int open_input(VideoInConfig *config,
101                 int input_x,
102                 int input_y,
103                 float input_z,
104                 double frame_rate);
105
106 // Call the constructor of the desired device.
107 // Used by fix_asset and open_input
108         VDeviceBase* new_device_base();
109
110 // Used for dvb interface
111         VDeviceBase* get_input_base();
112 // Used for calling OpenGL functions
113         VDeviceBase* get_output_base();
114
115 // Return 1 if the data is compressed.
116 // Called by Record::run to determine if compression option is fixed.
117 // Called by RecordVideo::rewind_file to determine if FileThread should call
118 // write_compressed_frames or write_frames.
119         static int is_compressed(int driver, int use_file, int use_fixed);
120         int is_compressed(int use_file, int use_fixed);
121
122 // Load the specific channeldb for the device type
123         static void load_channeldb(ChannelDB *channeldb, VideoInConfig *vconfig_in);
124         static void save_channeldb(ChannelDB *channeldb, VideoInConfig *vconfig_in);
125
126
127 // Return codec to store on disk if compressed
128         void fix_asset(Asset *asset, int driver);
129         static const char* drivertostr(int driver);
130 // Get the best colormodel for recording given the file format.
131 // Must be called between open_input and read_buffer.
132         int get_best_colormodel(Asset *asset);
133 // drop frames
134         int drop_frames(int frames);
135 // Specify the audio device opened concurrently with this video device
136         int set_adevice(AudioDevice *adevice);
137 // Return 1 if capturing locked up
138         int get_failed();
139 // Interrupt a crashed DV device
140         int interrupt_crash();
141 // Schedule capture size to be changed.
142         int set_translation(int input_x, int input_y);
143 // Change the channel
144         int set_channel(Channel *channel);
145         int set_captioning(int mode);
146 // Set the quality of the JPEG compressor
147         void set_quality(int quality);
148 // Change field order
149         int set_field_order(int odd_field_first);
150 // Set frames to clear after translation change.
151         int set_latency_counter(int value);
152 // Values from -100 to 100
153         int set_picture(PictureConfig *picture);
154         int capture_frame(int frame_number);  // Start the frame_number capturing
155         int read_buffer(VFrame *frame);  // Read the next frame off the device
156         int has_signal();
157         int create_channeldb(ArrayList<Channel*> *channeldb);
158         int frame_to_vframe(VFrame *frame, unsigned char *input); // Translate the captured frame to a VFrame
159         int initialize();
160         ArrayList<Channel*>* get_inputs();
161 // Create new input source if it doesn't match device_name.
162 // Otherwise return it.
163         Channel* new_input_source(char *device_name);
164         BC_Bitmap* get_bitmap();
165         DeviceMPEGInput *mpeg_device();
166
167 // Used by all devices to cause fd's to be not copied in fork operations.
168         int set_cloexec_flag(int desc, int value);
169
170 // ================================== Playback
171         int open_output(VideoOutConfig *config,
172                                         float rate,
173                                         int out_w,
174                                         int out_h,
175                                         Canvas *output,
176                                         int single_frame);
177         void set_cpus(int cpus);
178 // Slippery is only used for hardware compression drivers
179         int start_playback();
180         int interrupt_playback();
181 // Get output buffer for playback using colormodel.
182 // colormodel argument should be as close to best_colormodel as possible
183         void new_output_buffer(VFrame **output, int colormodel);
184         int wait_for_startup();
185         int wait_for_completion();
186         int output_visible();     // Whether the output is visible or not.
187         int stop_playback();
188         void goose_input();
189         long current_position();     // last frame rendered
190         double get_timestamp();      // timestamp last frame
191         double device_timestamp();   // device presentation timestamp
192 // absolute frame of last frame in buffer.
193 // The EDL parameter is passed to Canvas and can be 0.
194         int write_buffer(VFrame *output, EDL *edl);
195 // record menu auto config update
196         void auto_update(double rate, int width, int height);
197         int config_updated();
198         void config_update();
199         int get_iwidth() { return capture_w; }
200         int get_iheight() { return capture_h; }
201         double get_irate() { return frame_rate; }
202 // record raw stream on file descr fd, to close use fd=-1
203 //  bsz records up to bsz bytes of past buffer data in first_write
204         int start_toc(const char *path, const char *toc_path);
205         int start_record(int fd, int bsz=0);
206         int stop_record();
207         int total_video_streams();
208 // skimming
209         int get_video_pid(int track);
210         int get_video_info(int track, int &pid, double &framerate,
211                 int &width, int &height, char *title=0);
212         int get_thumbnail(int stream, int64_t &position,
213                 unsigned char *&thumbnail, int &ww, int &hh);
214         int set_skimming(int track, int skim, skim_fn fn, void *vp);
215
216 // Flag when output is interrupted
217         int interrupt;
218 // Compression format in use by the output device
219         int output_format;   
220         int is_playing_back;
221 // Audio device to share data with
222         AudioDevice *adevice;
223 // Reading data from the audio device.  This is set by the video device.
224         int sharing;
225 // Synchronize the close devices
226         int done_sharing;
227         Mutex *sharing_lock;
228
229 // frame rates
230         float orate, irate;
231 // timer for displaying frames in the current buffer
232         Timer buffer_timer;
233 // timer for getting frame rate
234         Timer rate_timer;
235 // size of output frame being fed to device during playback
236         int out_w, out_h;
237 // modes
238         int r, w;
239 // time from start of previous frame to start of next frame in ms
240         long frame_delay;
241 // CPU count for MJPEG compression
242         int cpus;
243
244
245         int is_recording; // status of thread
246         double frame_rate; // Frame rate to set in device
247         double timestamp;
248 // Location of input frame in captured frame
249         int frame_in_capture_x1, frame_in_capture_x2, frame_in_capture_y1, frame_in_capture_y2;
250         int capture_in_frame_x1, capture_in_frame_x2, capture_in_frame_y1, capture_in_frame_y2;
251 // Size of raw captured frame
252         int capture_w, capture_h;
253         int input_x, input_y;
254         float input_z;
255 // Captured frame size can only be changed when ready
256         int new_input_x, new_input_y;
257         float new_input_z;
258         int frame_resized;
259 // When the frame is resized, need to clear all the buffer frames.
260         int latency_counter;
261         int capturing;
262         int swap_bytes;
263         int in_config_updated;
264
265
266 // All the input sources on the device
267         ArrayList<Channel*> input_sources;
268         int odd_field_first;
269 // Quality for the JPEG compressor
270         int quality;
271 // Single frame mode for playback
272         int single_frame;
273
274 // Copy of the most recent channel set by set_channel
275         Channel *channel;
276 // Flag for subdevice to change channels when it has a chance
277         int channel_changed;
278         Mutex *channel_lock;
279
280 // Copy of the most recent picture controls
281         int picture_changed;
282         PictureConfig *picture;
283         Mutex *picture_lock;
284
285
286 // Change the capture size when ready
287         int update_translation();  
288
289         VDeviceBase *input_base;
290         VDeviceBase *output_base;
291         VideoInConfig *in_config;
292         VideoOutConfig *out_config;
293         KeepaliveThread *keepalive;
294         MWindow *mwindow;
295 };
296
297
298
299 #endif