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