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