r956: README.BUILD - add more library recommendations
[cinelerra_cv/ct.git] / cinelerra / videodevice.h
blob4473ea7a0b0b92a5e6518cdaef95135958a8a42b
1 #ifndef VIDEODEVICE_H
2 #define VIDEODEVICE_H
4 #include "asset.inc"
5 #include "assets.inc"
6 #include "audiodevice.inc"
7 #include "bccapture.inc"
8 #include "bctimer.h"
9 #include "canvas.inc"
10 #include "channel.inc"
11 #include "channeldb.inc"
12 #include "device1394output.inc"
13 #include "edl.inc"
14 #include "guicast.h"
15 #include "mwindow.inc"
16 #include "mutex.inc"
17 #include "preferences.inc"
18 #include "recordmonitor.inc"
19 #include "thread.h"
20 #include "picture.inc"
21 #include "vdevicebase.inc"
22 #include "vdevicebuz.inc"
23 #include "vdevicelml.inc"
24 #include "vdevicev4l.inc"
25 #include "vdevicex11.inc"
26 #include "videoconfig.inc"
27 #include "videowindow.inc"
28 #ifdef HAVE_FIREWIRE
29 #include "audio1394.inc"
30 #include "device1394output.inc"
31 #include "vdevice1394.inc"
32 #endif
35 // The keepalive thread runs continuously during recording.
36 // If the recording thread doesn't reset still_alive, failed is incremented.
37 // Failed is set to 0 if the recording thread resets still_alive.
38 // It calls goose_input in the VideoDevice. The input driver should
39 // trap goose_input and restart itself asynchronous of the recording thread.
41 // Number of seconds for keepalive to freak out
42 #define KEEPALIVE_DELAY 0.5
44 class VideoDevice;
46 class KeepaliveThread : public Thread
48 public:
49 KeepaliveThread(VideoDevice *device);
50 ~KeepaliveThread();
52 void run();
53 int reset_keepalive(); // Call after frame capture to reset counter
54 int get_failed();
55 int start_keepalive();
56 int stop();
58 Timer timer;
59 int still_alive;
60 int failed;
61 int interrupted;
62 VideoDevice *device;
63 Mutex *startup_lock;
64 int capturing;
67 class VideoDevice
69 public:
70 // MWindow is required where picture settings are used, to get the defaults.
71 VideoDevice(MWindow *mwindow = 0);
72 ~VideoDevice();
74 int close_all();
76 // ===================================== Recording
77 int open_input(VideoInConfig *config,
78 int input_x,
79 int input_y,
80 float input_z,
81 double frame_rate);
83 // Call the constructor of the desired device.
84 // Used by fix_asset and open_input
85 VDeviceBase* new_device_base();
88 // Used for calling OpenGL functions
89 VDeviceBase* get_output_base();
91 // Return 1 if the data is compressed.
92 // Called by Record::run to determine if compression option is fixed.
93 // Called by RecordVideo::rewind_file to determine if FileThread should call
94 // write_compressed_frames or write_frames.
95 static int is_compressed(int driver, int use_file, int use_fixed);
96 int is_compressed(int use_file, int use_fixed);
98 // Load the specific channeldb for the device type
99 static void load_channeldb(ChannelDB *channeldb, VideoInConfig *vconfig_in);
100 static void save_channeldb(ChannelDB *channeldb, VideoInConfig *vconfig_in);
103 // Return codec to store on disk if compressed
104 void fix_asset(Asset *asset, int driver);
105 static char* drivertostr(int driver);
106 // Get the best colormodel for recording given the file format.
107 // Must be called between open_input and read_buffer.
108 int get_best_colormodel(Asset *asset);
110 // Specify the audio device opened concurrently with this video device
111 int set_adevice(AudioDevice *adevice);
112 // Return 1 if capturing locked up
113 int get_failed();
114 // Interrupt a crashed DV device
115 int interrupt_crash();
116 // Schedule capture size to be changed.
117 int set_translation(int input_x, int input_y);
118 // Change the channel
119 int set_channel(Channel *channel);
120 // Set the quality of the JPEG compressor
121 void set_quality(int quality);
122 // Change field order
123 int set_field_order(int odd_field_first);
124 // Set frames to clear after translation change.
125 int set_latency_counter(int value);
126 // Values from -100 to 100
127 int set_picture(PictureConfig *picture);
128 int capture_frame(int frame_number); // Start the frame_number capturing
129 int read_buffer(VFrame *frame); // Read the next frame off the device
130 int has_signal();
131 int frame_to_vframe(VFrame *frame, unsigned char *input); // Translate the captured frame to a VFrame
132 int initialize();
133 ArrayList<Channel*>* get_inputs();
134 // Create new input source if it doesn't match device_name.
135 // Otherwise return it.
136 Channel* new_input_source(char *device_name);
137 BC_Bitmap* get_bitmap();
139 // Used by all devices to cause fd's to be not copied in fork operations.
140 int set_cloexec_flag(int desc, int value);
142 // ================================== Playback
143 int open_output(VideoOutConfig *config,
144 float rate,
145 int out_w,
146 int out_h,
147 Canvas *output,
148 int single_frame);
149 void set_cpus(int cpus);
150 // Slippery is only used for hardware compression drivers
151 int start_playback();
152 int interrupt_playback();
153 // Get output buffer for playback using colormodel.
154 // colormodel argument should be as close to best_colormodel as possible
155 void new_output_buffer(VFrame **output, int colormodel);
156 int wait_for_startup();
157 int wait_for_completion();
158 int output_visible(); // Whether the output is visible or not.
159 int stop_playback();
160 void goose_input();
161 long current_position(); // last frame rendered
162 // absolute frame of last frame in buffer.
163 // The EDL parameter is passed to Canvas and can be 0.
164 int write_buffer(VFrame *output, EDL *edl);
172 // Flag when output is interrupted
173 int interrupt;
174 // Compression format in use by the output device
175 int output_format;
176 int is_playing_back;
177 // Audio device to share data with
178 AudioDevice *adevice;
179 // Reading data from the audio device. This is set by the video device.
180 int sharing;
181 // Synchronize the close devices
182 int done_sharing;
183 Mutex *sharing_lock;
185 // frame rates
186 float orate, irate;
187 // timer for displaying frames in the current buffer
188 Timer buffer_timer;
189 // timer for getting frame rate
190 Timer rate_timer;
191 // size of output frame being fed to device during playback
192 int out_w, out_h;
193 // modes
194 int r, w;
195 // time from start of previous frame to start of next frame in ms
196 long frame_delay;
197 // CPU count for MJPEG compression
198 int cpus;
201 int is_recording; // status of thread
202 double frame_rate; // Frame rate to set in device
203 // Location of input frame in captured frame
204 int frame_in_capture_x1, frame_in_capture_x2, frame_in_capture_y1, frame_in_capture_y2;
205 int capture_in_frame_x1, capture_in_frame_x2, capture_in_frame_y1, capture_in_frame_y2;
206 // Size of raw captured frame
207 int capture_w, capture_h;
208 int input_x, input_y;
209 float input_z;
210 // Captured frame size can only be changed when ready
211 int new_input_x, new_input_y;
212 float new_input_z;
213 int frame_resized;
214 // When the frame is resized, need to clear all the buffer frames.
215 int latency_counter;
216 int capturing;
217 int swap_bytes;
220 // All the input sources on the device
221 ArrayList<Channel*> input_sources;
222 int odd_field_first;
223 // Quality for the JPEG compressor
224 int quality;
225 // Single frame mode for playback
226 int single_frame;
228 // Copy of the most recent channel set by set_channel
229 Channel *channel;
230 // Flag for subdevice to change channels when it has a chance
231 int channel_changed;
232 Mutex *channel_lock;
234 // Copy of the most recent picture controls
235 int picture_changed;
236 PictureConfig *picture;
237 Mutex *picture_lock;
240 // Change the capture size when ready
241 int update_translation();
243 VDeviceBase *input_base;
244 VDeviceBase *output_base;
245 VideoInConfig *in_config;
246 VideoOutConfig *out_config;
247 KeepaliveThread *keepalive;
248 MWindow *mwindow;
253 #endif