Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / vdevicev4l2.h
blob3a7b5c1373747543524614976c6b70359e5758fb
1 #ifndef VDEVICEV4L2_H
2 #define VDEVICEV4L2_H
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif
8 #ifdef HAVE_VIDEO4LINUX2
10 #include "vdevicebase.h"
11 #include <linux/types.h>
12 #include <linux/videodev2.h>
13 #include "videodevice.inc"
14 #include "vdevicev4l2.inc"
17 // Short delay is necessary whenn capturing a lousy source.
18 //#define BUFFER_TIMEOUT 250000
20 // Long delay is necessary to avoid losing synchronization due to spurrious
21 // resets.
22 #define BUFFER_TIMEOUT 10000000
25 // Isolate the application from the grabbing operation.
26 // Used by VDeviceV4L2 and VDeviceV4L2JPEG
27 // Color_model determines whether it uses compressed mode or not.
28 class VDeviceV4L2Thread : public Thread
30 public:
31 VDeviceV4L2Thread(VideoDevice *device, int color_model);
32 ~VDeviceV4L2Thread();
34 void start();
35 void run();
36 VFrame* get_buffer(int *timed_out);
37 void put_buffer();
38 void allocate_buffers(int number);
40 Mutex *buffer_lock;
41 // Some of the drivers in 2.6.7 can't handle simultaneous QBUF and DQBUF calls.
42 Mutex *ioctl_lock;
43 Condition *video_lock;
44 VideoDevice *device;
45 VFrame **device_buffers;
46 int *buffer_valid;
47 int total_valid;
48 int total_buffers;
49 int current_inbuffer;
50 int current_outbuffer;
51 // Don't block if first frame not recieved yet.
52 // This frees up the GUI during driver initialization.
53 int first_frame;
54 int done;
55 int input_fd;
56 // COMPRESSED or another color model the device should use.
57 int color_model;
58 VDeviceV4L2Put *put_thread;
62 // Another thread which puts back buffers asynchronously of the buffer
63 // grabber. Because 2.6.7 drivers block the buffer enqueuer.
64 class VDeviceV4L2Put : public Thread
66 public:
67 VDeviceV4L2Put(VDeviceV4L2Thread *thread);
68 ~VDeviceV4L2Put();
69 void run();
70 // Release buffer for capturing.
71 void put_buffer(int number);
72 VDeviceV4L2Thread *thread;
73 // List of buffers to requeue
74 Mutex *lock;
75 Condition *more_buffers;
76 int *putbuffers;
77 int total;
78 int done;
83 class VDeviceV4L2 : public VDeviceBase
85 public:
86 VDeviceV4L2(VideoDevice *device);
87 ~VDeviceV4L2();
89 int close_all();
90 int open_input();
91 int initialize();
92 int get_best_colormodel(Asset_GC asset);
93 int read_buffer(VFrame *frame);
94 int has_signal();
95 static int cmodel_to_device(int color_model);
96 static int get_sources(VideoDevice *device,
97 char *path);
99 VDeviceV4L2Thread *thread;
102 #endif
103 #endif
105 // Local Variables:
106 // mode: C++
107 // c-file-style: "linux"
108 // End: