r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / videodevice.h
blob085852a51a1dabadaa53d2990c1008d1f410bd9c
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 // Recording constructor
67 VideoDevice();
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(Picture *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 frame_to_vframe(VFrame *frame, unsigned char *input); // Translate the captured frame to a VFrame
118 int initialize();
119 ArrayList<Channel*>* get_inputs();
120 // Create new input source if it doesn't match device_name.
121 // Otherwise return it.
122 Channel* new_input_source(char *device_name);
123 BC_Bitmap* get_bitmap();
125 // Used by all devices to cause fd's to be not copied in fork operations.
126 int set_cloexec_flag(int desc, int value);
128 // ================================== Playback
129 int open_output(VideoOutConfig *config,
130 float rate,
131 int out_w,
132 int out_h,
133 Canvas *output,
134 int single_frame);
135 void set_cpus(int cpus);
136 // Slippery is only used for hardware compression drivers
137 int start_playback();
138 int interrupt_playback();
139 // Get output buffer for playback using colormodel.
140 // colormodel argument should be as close to best_colormodel as possible
141 void new_output_buffers(VFrame **outputs, int colormodel);
142 int wait_for_startup();
143 int wait_for_completion();
144 int output_visible(); // Whether the output is visible or not.
145 int stop_playback();
146 void goose_input();
147 long current_position(); // last frame rendered
148 // absolute frame of last frame in buffer.
149 // The EDL parameter is passed to Canvas and can be 0.
150 int write_buffer(VFrame **outputs, EDL *edl);
158 // Flag when output is interrupted
159 int interrupt;
160 // Compression format in use by the output device
161 int output_format;
162 int is_playing_back;
163 // Audio device to share data with
164 AudioDevice *adevice;
165 // Reading data from the audio device. This is set by the video device.
166 int sharing;
167 // Synchronize the close devices
168 int done_sharing;
169 Mutex *sharing_lock;
171 // frame rates
172 float orate, irate;
173 // timer for displaying frames in the current buffer
174 Timer buffer_timer;
175 // timer for getting frame rate
176 Timer rate_timer;
177 // size of output frame being fed to device during playback
178 int out_w, out_h;
179 // modes
180 int r, w;
181 // time from start of previous frame to start of next frame in ms
182 long frame_delay;
183 // CPU count for MJPEG compression
184 int cpus;
187 int is_recording; // status of thread
188 float frame_rate; // Frame rate to set in device
189 // Location of input frame in captured frame
190 int frame_in_capture_x1, frame_in_capture_x2, frame_in_capture_y1, frame_in_capture_y2;
191 int capture_in_frame_x1, capture_in_frame_x2, capture_in_frame_y1, capture_in_frame_y2;
192 // Size of raw captured frame
193 int capture_w, capture_h;
194 int input_x, input_y;
195 float input_z;
196 // Captured frame size can only be changed when ready
197 int new_input_x, new_input_y;
198 float new_input_z;
199 int frame_resized;
200 // When the frame is resized, need to clear all the buffer frames.
201 int latency_counter;
202 int capturing;
203 int swap_bytes;
206 // All the input sources on the device
207 ArrayList<Channel*> input_sources;
208 int odd_field_first;
209 // Quality for the JPEG compressor
210 int quality;
211 // Single frame mode for playback
212 int single_frame;
214 // Copy of the most recent channel set by set_channel
215 Channel *channel;
216 // Flag for subdevice to change channels when it has a chance
217 int channel_changed;
218 Mutex *channel_lock;
220 // Copy of the most recent picture controls
221 int picture_changed;
222 Picture *picture;
223 Mutex *picture_lock;
226 // Change the capture size when ready
227 int update_translation();
229 VDeviceBase *input_base;
230 VDeviceBase *output_base;
231 VideoInConfig *in_config;
232 VideoOutConfig *out_config;
233 KeepaliveThread *keepalive;
238 #endif