r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / videodevice.h
blobdac5f65833fa6a46fe5c53ab069047359813de92
1 #ifndef VIDEODEVICE_H
2 #define VIDEODEVICE_H
4 #include "assets.inc"
5 #include "audio1394.inc"
6 #include "audiodevice.inc"
7 #include "guicast.h"
8 #include "bccapture.inc"
9 #include "canvas.inc"
10 #include "channel.inc"
11 #include "edl.inc"
12 #include "mwindow.inc"
13 #include "mutex.h"
14 #include "preferences.inc"
15 #include "recordmonitor.inc"
16 #include "thread.h"
17 #include "timer.h"
18 #include "vdevicebase.inc"
19 #include "vdevice1394.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"
28 // The keepalive thread runs continuously during recording.
29 // If the recording thread doesn't reset still_alive, failed is incremented.
30 // Failed is set to 0 if the recording thread resets still_alive.
31 // It calls goose_input in the VideoDevice. The input driver should
32 // trap goose_input and restart itself asynchronous of the recording thread.
34 // Number of seconds for keepalive to freak out
35 #define KEEPALIVE_DELAY 0.5
37 class VideoDevice;
39 class KeepaliveThread : public Thread
41 public:
42 KeepaliveThread(VideoDevice *device);
43 ~KeepaliveThread();
45 void run();
46 int reset_keepalive(); // Call after frame capture to reset counter
47 int get_failed();
48 int start_keepalive();
49 int stop();
51 Timer timer;
52 int still_alive;
53 int failed;
54 int interrupted;
55 VideoDevice *device;
56 Mutex startup_lock;
57 int capturing;
60 class VideoDevice
62 public:
63 // Recording constructor
64 VideoDevice();
65 ~VideoDevice();
67 friend class VDeviceLML;
68 friend class VDeviceX11;
69 friend class VDevice1394;
70 friend class VDeviceBUZInput;
71 friend class VDeviceBUZ;
72 friend class VDeviceBase;
73 friend class VDeviceV4L;
74 friend class Audio1394;
76 int close_all();
77 // Create a default channeldb, erasing the old one
78 void create_channeldb(ArrayList<Channel*> *channeldb);
80 // ===================================== Recording
81 int open_input(VideoInConfig *config,
82 int input_x,
83 int input_y,
84 float input_z,
85 float frame_rate);
86 // Return if the data is compressed
87 static int is_compressed(int driver);
88 // Return codec to store on disk if compressed
89 static char* get_vcodec(int driver);
90 static char* drivertostr(int driver);
91 int is_compressed();
92 // Get the best colormodel for recording given the file format
93 // Must be called between open_input and read_buffer
94 int get_best_colormodel(Asset *asset);
96 // Unlocks the device if being shared with audio
97 // int stop_sharing();
98 // Specify the audio device opened concurrently with this video device
99 int set_adevice(AudioDevice *adevice);
100 // Called by the audio device to share a buffer
101 // int get_shared_data(unsigned char *data, long size);
102 // Return 1 if capturing locked up
103 int get_failed();
104 // Interrupt a crashed DV device
105 int interrupt_crash();
106 // Schedule capture size to be changed.
107 int set_translation(int input_x, int input_y);
108 // Change the channel
109 int set_channel(Channel *channel);
110 // Set the quality of the JPEG compressor
111 void set_quality(int quality);
112 // Change field order
113 int set_field_order(int odd_field_first);
114 // Set frames to clear after translation change.
115 int set_latency_counter(int value);
116 // Values from -100 to 100
117 int set_picture(int brightness,
118 int hue,
119 int color,
120 int contrast,
121 int whiteness);
122 int capture_frame(int frame_number); // Start the frame_number capturing
123 int read_buffer(VFrame *frame); // Read the next frame off the device
124 int frame_to_vframe(VFrame *frame, unsigned char *input); // Translate the captured frame to a VFrame
125 int initialize();
126 ArrayList<char *>* get_inputs();
127 BC_Bitmap* get_bitmap();
130 // ================================== Playback
131 int open_output(VideoOutConfig *config,
132 float rate,
133 int out_w,
134 int out_h,
135 Canvas *output,
136 int single_frame);
137 void set_cpus(int cpus);
138 // Slippery is only used for hardware compression drivers
139 int start_playback();
140 int interrupt_playback();
141 // Get output buffer for playback using colormodel.
142 // colormodel argument should be as close to best_colormodel as possible
143 void new_output_buffers(VFrame **outputs, int colormodel);
144 int wait_for_startup();
145 int wait_for_completion();
146 int output_visible(); // Whether the output is visible or not.
147 int stop_playback();
148 void goose_input();
149 long current_position(); // last frame rendered
150 // absolute frame of last frame in buffer.
151 // The EDL parameter is passed to Canvas and can be 0.
152 int write_buffer(VFrame **outputs, EDL *edl);
154 // Flag when output is interrupted
155 int interrupt;
156 // Compression format in use by the output device
157 int output_format;
158 int is_playing_back;
159 // Audio device to share data with
160 AudioDevice *adevice;
161 // Reading data from the audio device. This is set by the video device.
162 int sharing;
163 // Synchronize the close devices
164 int done_sharing;
165 Mutex sharing_lock;
167 // frame rates
168 float orate, irate;
169 // timer for displaying frames in the current buffer
170 Timer buffer_timer;
171 // timer for getting frame rate
172 Timer rate_timer;
173 // size of output frame being fed to device during playback
174 int out_w, out_h;
175 // modes
176 int r, w;
177 // time from start of previous frame to start of next frame in ms
178 long frame_delay;
179 // CPU count for MJPEG compression
180 int cpus;
183 int is_recording; // status of thread
184 float frame_rate; // Frame rate to set in device
185 // Location of input frame in captured frame
186 int frame_in_capture_x1, frame_in_capture_x2, frame_in_capture_y1, frame_in_capture_y2;
187 int capture_in_frame_x1, capture_in_frame_x2, capture_in_frame_y1, capture_in_frame_y2;
188 // Size of raw captured frame
189 int capture_w, capture_h;
190 int input_x, input_y;
191 float input_z;
192 // Captured frame size can only be changed when ready
193 int new_input_x, new_input_y;
194 float new_input_z;
195 int frame_resized;
196 // When the frame is resized, need to clear all the buffer frames.
197 int latency_counter;
198 int capturing;
199 int swap_bytes;
200 // All the input sources on the device
201 ArrayList<char *> input_sources;
202 int odd_field_first;
203 // Quality for the JPEG compressor
204 int quality;
205 // Single frame mode for playback
206 int single_frame;
208 private:
209 // Change the capture size when ready
210 int update_translation();
212 VDeviceBase *input_base;
213 VDeviceBase *output_base;
214 VideoInConfig *in_config;
215 VideoOutConfig *out_config;
216 KeepaliveThread *keepalive;
221 #endif