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