2612
|
1 |
--- OpenCV-2.1.0.orig/CMakeLists.txt 2010-04-05 21:24:37.000000000 -0400
|
2630
|
2 |
+++ OpenCV-2.1.0/CMakeLists.txt 2010-05-12 17:19:20.551785342 -0400
|
|
3 |
@@ -201,6 +201,7 @@
|
|
4 |
include(OpenCVFindPkgConfig.cmake OPTIONAL)
|
|
5 |
include(CheckFunctionExists)
|
|
6 |
include(CheckIncludeFile)
|
|
7 |
+ include(CheckIncludeFiles)
|
|
8 |
endif()
|
|
9 |
|
|
10 |
#if(MSVC)
|
|
11 |
@@ -404,7 +405,13 @@
|
|
12 |
if(WITH_V4L)
|
2612
|
13 |
CHECK_MODULE(libv4l1 HAVE_LIBV4L)
|
|
14 |
CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L)
|
2630
|
15 |
- CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2)
|
|
16 |
+ CHECK_INCLUDE_FILES("asm/types.h;linux/videodev2.h" HAVE_LINUX_V4L2)
|
|
17 |
+ if(NOT HAVE_LINUX_V4L2)
|
|
18 |
+ CHECK_INCLUDE_FILES("sys/types.h;sys/ioccom.h;sys/videodev2.h" HAVE_OTHER_V4L2)
|
|
19 |
+ endif()
|
|
20 |
+ if(HAVE_LINUX_V4L2 OR HAVE_OTHER_V4L2)
|
|
21 |
+ set(HAVE_CAMV4L2 TRUE)
|
|
22 |
+ endif()
|
2612
|
23 |
else()
|
|
24 |
set(HAVE_LIBV4L FALSE)
|
|
25 |
set(HAVE_CAMV4L FALSE)
|
|
26 |
--- OpenCV-2.1.0.orig/src/highgui/cvcap.cpp 2010-04-05 21:24:44.000000000 -0400
|
|
27 |
+++ OpenCV-2.1.0/src/highgui/cvcap.cpp 2010-05-09 06:35:20.867721938 -0400
|
|
28 |
@@ -129,7 +129,7 @@
|
|
29 |
for (int i = 0; domains[i] >= 0; i++)
|
|
30 |
{
|
|
31 |
#if defined(HAVE_VIDEOINPUT) || defined(HAVE_TYZX) || defined(HAVE_VFW) || \
|
|
32 |
- defined(HAVE_CAMV4L) || defined (HAVE_CAMV4L2) || defined(HAVE_GSTREAMER) || \
|
2630
|
33 |
+ defined(HAVE_CAMV4L) || defined (HAVE_CAMV4L2) || \
|
2612
|
34 |
defined(HAVE_DC1394_2) || defined(HAVE_DC1394) || defined(HAVE_CMU1394) || \
|
|
35 |
defined(HAVE_GSTREAMER) || defined(HAVE_MIL) || defined(HAVE_QUICKTIME) || \
|
|
36 |
defined(HAVE_UNICAP) || defined(HAVE_PVAPI)
|
|
37 |
--- OpenCV-2.1.0.orig/src/highgui/cvcap_v4l.cpp 2010-04-05 21:24:44.000000000 -0400
|
2630
|
38 |
+++ OpenCV-2.1.0/src/highgui/cvcap_v4l.cpp 2010-05-12 20:38:16.605463073 -0400
|
2612
|
39 |
@@ -202,7 +202,7 @@
|
|
40 |
|
|
41 |
#include "_highgui.h"
|
|
42 |
|
|
43 |
-#if !defined WIN32 && defined HAVE_CAMV4L
|
2630
|
44 |
+#if !defined WIN32 && (defined HAVE_CAMV4L || defined HAVE_CAMV4L2)
|
2612
|
45 |
|
|
46 |
#define CLEAR(x) memset (&(x), 0, sizeof (x))
|
|
47 |
|
2630
|
48 |
@@ -214,17 +214,24 @@
|
2612
|
49 |
#include <sys/types.h>
|
|
50 |
#include <sys/mman.h>
|
|
51 |
|
|
52 |
+#ifdef HAVE_CAMV4L
|
|
53 |
#include <linux/videodev.h>
|
|
54 |
+#endif
|
|
55 |
|
|
56 |
#include <string.h>
|
|
57 |
#include <stdlib.h>
|
|
58 |
-#include <asm/types.h> /* for videodev2.h */
|
|
59 |
#include <assert.h>
|
|
60 |
#include <sys/stat.h>
|
|
61 |
#include <sys/ioctl.h>
|
2630
|
62 |
|
2612
|
63 |
#ifdef HAVE_CAMV4L2
|
2630
|
64 |
+#if defined __linux || defined __linux__
|
|
65 |
+#include <asm/types.h>
|
2612
|
66 |
#include <linux/videodev2.h>
|
2630
|
67 |
+#else
|
2612
|
68 |
+#include <sys/ioccom.h>
|
|
69 |
+#include <sys/videodev2.h>
|
|
70 |
+#endif
|
2630
|
71 |
#endif
|
2612
|
72 |
|
|
73 |
/* Defaults - If your board can do better, set it here. Set for the most common type inputs. */
|
2630
|
74 |
@@ -255,8 +262,6 @@
|
2612
|
75 |
size_t length;
|
|
76 |
};
|
|
77 |
|
|
78 |
-static unsigned int n_buffers = 0;
|
|
79 |
-
|
|
80 |
/* Additional V4L2 pixelformats support for Sonix SN9C10x base webcams */
|
|
81 |
#ifndef V4L2_PIX_FMT_SBGGR8
|
|
82 |
#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */
|
2630
|
83 |
@@ -286,18 +291,25 @@
|
2612
|
84 |
int deviceHandle;
|
|
85 |
int bufferIndex;
|
|
86 |
int FirstCapture;
|
|
87 |
+ bool devicePollable;
|
|
88 |
+
|
|
89 |
+#ifdef HAVE_CAMV4L
|
|
90 |
+
|
|
91 |
struct video_capability capability;
|
|
92 |
struct video_window captureWindow;
|
|
93 |
struct video_picture imageProperties;
|
|
94 |
struct video_mbuf memoryBuffer;
|
|
95 |
struct video_mmap *mmaps;
|
|
96 |
char *memoryMap;
|
|
97 |
+#endif /* HAVE_CAMV4L */
|
|
98 |
+
|
|
99 |
IplImage frame;
|
|
100 |
|
2630
|
101 |
#ifdef HAVE_CAMV4L2
|
2612
|
102 |
|
|
103 |
/* V4L2 variables */
|
|
104 |
buffer buffers[MAX_V4L_BUFFERS + 1];
|
|
105 |
+ unsigned int n_buffers;
|
|
106 |
struct v4l2_capability cap;
|
|
107 |
struct v4l2_input inp;
|
|
108 |
struct v4l2_format form;
|
2630
|
109 |
@@ -391,6 +403,7 @@
|
2612
|
110 |
|
|
111 |
}; /* End icvInitCapture_V4L */
|
|
112 |
|
2630
|
113 |
+#ifdef HAVE_CAMV4L
|
2612
|
114 |
static int
|
|
115 |
try_palette(int fd,
|
|
116 |
struct video_picture *cam_pic,
|
2630
|
117 |
@@ -407,6 +420,7 @@
|
2612
|
118 |
return 1;
|
|
119 |
return 0;
|
|
120 |
}
|
|
121 |
+#endif /* HAVE_CAMV4L */
|
|
122 |
|
2630
|
123 |
#ifdef HAVE_CAMV4L2
|
2612
|
124 |
|
2630
|
125 |
@@ -431,8 +445,9 @@
|
2612
|
126 |
}
|
|
127 |
|
2630
|
128 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
129 |
+#ifdef HAVE_CAMV4L
|
|
130 |
|
|
131 |
-static int try_init_v4l(CvCaptureCAM_V4L* capture, char *deviceName)
|
|
132 |
+static int try_init_v4l(CvCaptureCAM_V4L* capture, const char *deviceName)
|
|
133 |
{
|
|
134 |
|
|
135 |
// if detect = -1 then unable to open device
|
2630
|
136 |
@@ -474,9 +489,10 @@
|
2612
|
137 |
|
|
138 |
}
|
|
139 |
|
|
140 |
+#endif /* HAVE_CAMV4L */
|
2630
|
141 |
#ifdef HAVE_CAMV4L2
|
2612
|
142 |
|
|
143 |
-static int try_init_v4l2(CvCaptureCAM_V4L* capture, char *deviceName)
|
|
144 |
+static int try_init_v4l2(CvCaptureCAM_V4L* capture, const char *deviceName)
|
|
145 |
{
|
|
146 |
|
|
147 |
// if detect = -1 then unable to open device
|
2630
|
148 |
@@ -491,7 +507,6 @@
|
2612
|
149 |
capture->deviceHandle = open (deviceName, O_RDWR /* required */ | O_NONBLOCK, 0);
|
|
150 |
|
|
151 |
|
|
152 |
-
|
|
153 |
if (capture->deviceHandle == 0)
|
|
154 |
{
|
|
155 |
detect = -1;
|
2630
|
156 |
@@ -510,6 +525,8 @@
|
2612
|
157 |
}
|
|
158 |
else
|
|
159 |
{
|
|
160 |
+
|
|
161 |
+#ifdef HAVE_CAMV4L
|
|
162 |
CLEAR (capture->capability);
|
|
163 |
capture->capability.type = capture->cap.capabilities;
|
|
164 |
|
2630
|
165 |
@@ -518,6 +535,10 @@
|
2612
|
166 |
{
|
|
167 |
detect = 1;
|
|
168 |
}
|
|
169 |
+#else
|
|
170 |
+ detect = 1;
|
|
171 |
+#endif /* HAVE_CAMV4L */
|
|
172 |
+
|
|
173 |
}
|
|
174 |
}
|
|
175 |
|
2630
|
176 |
@@ -544,10 +565,6 @@
|
2612
|
177 |
else
|
|
178 |
|
|
179 |
#ifdef HAVE_JPEG
|
|
180 |
-#ifdef __USE_GNU
|
|
181 |
- /* support for MJPEG is only available with libjpeg and gcc,
|
|
182 |
- because it's use libjepg and fmemopen()
|
|
183 |
- */
|
|
184 |
if (try_palette_v4l2(capture, V4L2_PIX_FMT_MJPEG) == 0 ||
|
|
185 |
try_palette_v4l2(capture, V4L2_PIX_FMT_JPEG) == 0)
|
|
186 |
{
|
2630
|
187 |
@@ -555,7 +572,6 @@
|
2612
|
188 |
}
|
|
189 |
else
|
|
190 |
#endif
|
|
191 |
-#endif
|
|
192 |
|
|
193 |
if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUYV) == 0)
|
|
194 |
{
|
2630
|
195 |
@@ -590,6 +606,7 @@
|
2612
|
196 |
}
|
|
197 |
|
2630
|
198 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
199 |
+#ifdef HAVE_CAMV4L
|
|
200 |
|
|
201 |
static int autosetup_capture_mode_v4l(CvCaptureCAM_V4L* capture)
|
|
202 |
{
|
2630
|
203 |
@@ -624,6 +641,7 @@
|
2612
|
204 |
|
|
205 |
}
|
|
206 |
|
|
207 |
+#endif /* HAVE_CAMV4L */
|
2630
|
208 |
#ifdef HAVE_CAMV4L2
|
2612
|
209 |
|
|
210 |
static void v4l2_scan_controls_enumerate_menu(CvCaptureCAM_V4L* capture)
|
2630
|
211 |
@@ -648,7 +666,7 @@
|
2612
|
212 |
static void v4l2_scan_controls(CvCaptureCAM_V4L* capture)
|
|
213 |
{
|
|
214 |
|
|
215 |
- __u32 ctrl_id;
|
|
216 |
+ unsigned int ctrl_id;
|
|
217 |
|
|
218 |
for (ctrl_id = V4L2_CID_BASE;
|
|
219 |
ctrl_id < V4L2_CID_LASTP1;
|
2630
|
220 |
@@ -794,7 +812,111 @@
|
2612
|
221 |
|
|
222 |
}
|
|
223 |
|
|
224 |
-static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName)
|
|
225 |
+static int init_read_v4l2 (CvCaptureCAM_V4L *capture)
|
|
226 |
+{
|
|
227 |
+ unsigned int size = capture->form.fmt.pix.sizeimage;
|
|
228 |
+
|
|
229 |
+ capture->buffers[0].start = malloc( size );
|
|
230 |
+ if (!capture->buffers[0].start) {
|
|
231 |
+ perror ("malloc");
|
|
232 |
+ return -1;
|
|
233 |
+ }
|
|
234 |
+ capture->buffers[0].length = size;
|
|
235 |
+
|
|
236 |
+ capture->buffers[MAX_V4L_BUFFERS].start = malloc( size );
|
|
237 |
+ if (!capture->buffers[MAX_V4L_BUFFERS].start) {
|
|
238 |
+ perror ("malloc");
|
|
239 |
+ return -1;
|
|
240 |
+ }
|
|
241 |
+ capture->buffers[MAX_V4L_BUFFERS].length = size;
|
|
242 |
+
|
|
243 |
+ capture->n_buffers = 0;
|
|
244 |
+
|
|
245 |
+ return 0;
|
|
246 |
+}
|
|
247 |
+
|
|
248 |
+static int init_mmap_v4l2 (CvCaptureCAM_V4L *capture, const char *deviceName)
|
|
249 |
+{
|
|
250 |
+ unsigned int buffer_number = DEFAULT_V4L_BUFFERS;
|
|
251 |
+
|
|
252 |
+ CLEAR (capture->req);
|
|
253 |
+
|
|
254 |
+ try_again:
|
|
255 |
+
|
|
256 |
+ capture->req.count = buffer_number;
|
|
257 |
+ capture->req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
258 |
+ capture->req.memory = V4L2_MEMORY_MMAP;
|
|
259 |
+
|
|
260 |
+ if (-1 == xioctl (capture->deviceHandle, VIDIOC_REQBUFS, &capture->req))
|
|
261 |
+ {
|
|
262 |
+ if (EINVAL == errno)
|
|
263 |
+ {
|
|
264 |
+ fprintf (stderr, "%s does not support memory mapping\n", deviceName);
|
|
265 |
+ } else {
|
|
266 |
+ perror ("VIDIOC_REQBUFS");
|
|
267 |
+ }
|
|
268 |
+ return -1;
|
|
269 |
+ }
|
|
270 |
+
|
|
271 |
+ if (capture->req.count < buffer_number)
|
|
272 |
+ {
|
|
273 |
+ if (buffer_number == 1)
|
|
274 |
+ {
|
|
275 |
+ fprintf (stderr, "Insufficient buffer memory on %s\n", deviceName);
|
|
276 |
+
|
|
277 |
+ return -1;
|
|
278 |
+ } else {
|
|
279 |
+ buffer_number--;
|
|
280 |
+ fprintf (stderr, "Insufficient buffer memory on %s -- decreaseing buffers\n", deviceName);
|
|
281 |
+
|
|
282 |
+ goto try_again;
|
|
283 |
+ }
|
|
284 |
+ }
|
|
285 |
+
|
|
286 |
+ for (unsigned int n_buffers = 0; n_buffers < capture->req.count; ++n_buffers)
|
|
287 |
+ {
|
|
288 |
+ struct v4l2_buffer buf;
|
|
289 |
+
|
|
290 |
+ CLEAR (buf);
|
|
291 |
+
|
|
292 |
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
293 |
+ buf.memory = V4L2_MEMORY_MMAP;
|
|
294 |
+ buf.index = n_buffers;
|
|
295 |
+
|
|
296 |
+ if (-1 == xioctl (capture->deviceHandle, VIDIOC_QUERYBUF, &buf)) {
|
|
297 |
+ perror ("VIDIOC_QUERYBUF");
|
|
298 |
+ return -1;
|
|
299 |
+ }
|
|
300 |
+
|
|
301 |
+ capture->buffers[n_buffers].length = buf.length;
|
|
302 |
+ capture->buffers[n_buffers].start =
|
|
303 |
+ mmap (NULL /* start anywhere */,
|
|
304 |
+ buf.length,
|
|
305 |
+ PROT_READ | PROT_WRITE /* required */,
|
|
306 |
+ MAP_SHARED /* recommended */,
|
|
307 |
+ capture->deviceHandle, buf.m.offset);
|
|
308 |
+
|
|
309 |
+ if (MAP_FAILED == capture->buffers[n_buffers].start) {
|
|
310 |
+ perror ("mmap");
|
|
311 |
+ return -1;
|
|
312 |
+ }
|
|
313 |
+ }
|
|
314 |
+
|
|
315 |
+ unsigned int size = capture->form.fmt.pix.sizeimage;
|
|
316 |
+
|
|
317 |
+ capture->buffers[MAX_V4L_BUFFERS].start = malloc( size );
|
|
318 |
+ if (!capture->buffers[MAX_V4L_BUFFERS].start) {
|
|
319 |
+ perror ("malloc");
|
|
320 |
+ return -1;
|
|
321 |
+ }
|
|
322 |
+ capture->buffers[MAX_V4L_BUFFERS].length = size;
|
|
323 |
+
|
|
324 |
+ capture->n_buffers = capture->req.count;
|
|
325 |
+
|
|
326 |
+ return 0;
|
|
327 |
+}
|
|
328 |
+
|
|
329 |
+static int _capture_V4L2 (CvCaptureCAM_V4L *capture, const char *deviceName)
|
|
330 |
{
|
|
331 |
int detect_v4l2 = 0;
|
|
332 |
|
2630
|
333 |
@@ -870,10 +992,6 @@
|
2612
|
334 |
return -1;
|
|
335 |
}
|
|
336 |
|
|
337 |
- if (V4L2_SUPPORT == 0)
|
|
338 |
- {
|
|
339 |
- }
|
|
340 |
-
|
|
341 |
if (autosetup_capture_mode_v4l2(capture) == -1)
|
|
342 |
return -1;
|
|
343 |
|
2630
|
344 |
@@ -892,90 +1010,28 @@
|
2612
|
345 |
if (capture->form.fmt.pix.sizeimage < min)
|
|
346 |
capture->form.fmt.pix.sizeimage = min;
|
|
347 |
|
|
348 |
- CLEAR (capture->req);
|
|
349 |
-
|
|
350 |
- unsigned int buffer_number = DEFAULT_V4L_BUFFERS;
|
|
351 |
-
|
|
352 |
- try_again:
|
|
353 |
-
|
|
354 |
- capture->req.count = buffer_number;
|
|
355 |
- capture->req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
356 |
- capture->req.memory = V4L2_MEMORY_MMAP;
|
|
357 |
-
|
|
358 |
- if (-1 == xioctl (capture->deviceHandle, VIDIOC_REQBUFS, &capture->req))
|
|
359 |
- {
|
|
360 |
- if (EINVAL == errno)
|
|
361 |
- {
|
|
362 |
- fprintf (stderr, "%s does not support memory mapping\n", deviceName);
|
|
363 |
- } else {
|
|
364 |
- perror ("VIDIOC_REQBUFS");
|
|
365 |
- }
|
|
366 |
- /* free capture, and returns an error code */
|
|
367 |
- icvCloseCAM_V4L (capture);
|
|
368 |
- return -1;
|
|
369 |
- }
|
|
370 |
-
|
|
371 |
- if (capture->req.count < buffer_number)
|
|
372 |
- {
|
|
373 |
- if (buffer_number == 1)
|
|
374 |
- {
|
|
375 |
- fprintf (stderr, "Insufficient buffer memory on %s\n", deviceName);
|
|
376 |
-
|
|
377 |
- /* free capture, and returns an error code */
|
|
378 |
- icvCloseCAM_V4L (capture);
|
|
379 |
- return -1;
|
|
380 |
- } else {
|
|
381 |
- buffer_number--;
|
|
382 |
- fprintf (stderr, "Insufficient buffer memory on %s -- decreaseing buffers\n", deviceName);
|
|
383 |
-
|
|
384 |
- goto try_again;
|
|
385 |
- }
|
|
386 |
- }
|
|
387 |
-
|
|
388 |
- for (n_buffers = 0; n_buffers < capture->req.count; ++n_buffers)
|
|
389 |
- {
|
|
390 |
- struct v4l2_buffer buf;
|
|
391 |
-
|
|
392 |
- CLEAR (buf);
|
|
393 |
-
|
|
394 |
- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
395 |
- buf.memory = V4L2_MEMORY_MMAP;
|
|
396 |
- buf.index = n_buffers;
|
|
397 |
-
|
|
398 |
- if (-1 == xioctl (capture->deviceHandle, VIDIOC_QUERYBUF, &buf)) {
|
|
399 |
- perror ("VIDIOC_QUERYBUF");
|
|
400 |
-
|
|
401 |
- /* free capture, and returns an error code */
|
|
402 |
- icvCloseCAM_V4L (capture);
|
|
403 |
+ if (capture->cap.capabilities & V4L2_CAP_STREAMING) {
|
|
404 |
+ if (-1 == init_mmap_v4l2(capture, deviceName)) {
|
|
405 |
+ icvCloseCAM_V4L(capture);
|
|
406 |
return -1;
|
|
407 |
}
|
|
408 |
-
|
|
409 |
- capture->buffers[n_buffers].length = buf.length;
|
|
410 |
- capture->buffers[n_buffers].start =
|
|
411 |
- mmap (NULL /* start anywhere */,
|
|
412 |
- buf.length,
|
|
413 |
- PROT_READ | PROT_WRITE /* required */,
|
|
414 |
- MAP_SHARED /* recommended */,
|
|
415 |
- capture->deviceHandle, buf.m.offset);
|
|
416 |
-
|
|
417 |
- if (MAP_FAILED == capture->buffers[n_buffers].start) {
|
|
418 |
- perror ("mmap");
|
|
419 |
-
|
|
420 |
- /* free capture, and returns an error code */
|
|
421 |
- icvCloseCAM_V4L (capture);
|
|
422 |
+ } else {
|
|
423 |
+ if (capture->cap.capabilities & V4L2_CAP_READWRITE) {
|
|
424 |
+ if (-1 == init_read_v4l2(capture)) {
|
|
425 |
+ icvCloseCAM_V4L(capture);
|
|
426 |
+ return -1;
|
|
427 |
+ }
|
|
428 |
+ } else {
|
|
429 |
+ fprintf( stderr, "HIGHGUI ERROR: V4L2: device %s does not support either memory mapped or read/write I/O.\n",deviceName);
|
|
430 |
+ icvCloseCAM_V4L(capture);
|
|
431 |
return -1;
|
|
432 |
}
|
|
433 |
-
|
|
434 |
- if (n_buffers == 0) {
|
|
435 |
- capture->buffers[MAX_V4L_BUFFERS].start = malloc( buf.length );
|
|
436 |
- capture->buffers[MAX_V4L_BUFFERS].length = buf.length;
|
|
437 |
- }
|
|
438 |
}
|
|
439 |
|
|
440 |
/* Set up Image data */
|
|
441 |
cvInitImageHeader( &capture->frame,
|
|
442 |
- cvSize( capture->captureWindow.width,
|
|
443 |
- capture->captureWindow.height ),
|
|
444 |
+ cvSize( capture->form.fmt.pix.width,
|
|
445 |
+ capture->form.fmt.pix.height ),
|
|
446 |
IPL_DEPTH_8U, 3, IPL_ORIGIN_TL, 4 );
|
|
447 |
/* Allocate space for RGBA data */
|
|
448 |
capture->frame.imageData = (char *)cvAlloc(capture->frame.imageSize);
|
2630
|
449 |
@@ -984,8 +1040,9 @@
|
2612
|
450 |
}; /* End _capture_V4L2 */
|
|
451 |
|
2630
|
452 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
453 |
+#ifdef HAVE_CAMV4L
|
|
454 |
|
|
455 |
-static int _capture_V4L (CvCaptureCAM_V4L *capture, char *deviceName)
|
|
456 |
+static int _capture_V4L (CvCaptureCAM_V4L *capture, const char *deviceName)
|
|
457 |
{
|
|
458 |
int detect_v4l = 0;
|
|
459 |
|
2630
|
460 |
@@ -1103,6 +1160,8 @@
|
2612
|
461 |
return 1;
|
|
462 |
}; /* End _capture_V4L */
|
|
463 |
|
|
464 |
+#endif /* HAVE_CAMV4L */
|
|
465 |
+
|
|
466 |
static CvCaptureCAM_V4L * icvCaptureFromCAM_V4L (int index)
|
|
467 |
{
|
|
468 |
static int autoindex;
|
2630
|
469 |
@@ -1152,10 +1211,12 @@
|
2612
|
470 |
icvCloseCAM_V4L(capture);
|
|
471 |
V4L2_SUPPORT = 0;
|
2630
|
472 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
473 |
+#ifdef HAVE_CAMV4L
|
|
474 |
if (_capture_V4L (capture, deviceName) == -1) {
|
|
475 |
icvCloseCAM_V4L(capture);
|
|
476 |
return NULL;
|
|
477 |
}
|
|
478 |
+#endif /* HAVE_CAMV4L */
|
2630
|
479 |
#ifdef HAVE_CAMV4L2
|
2612
|
480 |
} else {
|
|
481 |
V4L2_SUPPORT = 1;
|
2630
|
482 |
@@ -1168,6 +1229,26 @@
|
|
483 |
#ifdef HAVE_CAMV4L2
|
2612
|
484 |
|
|
485 |
static int read_frame_v4l2(CvCaptureCAM_V4L* capture) {
|
|
486 |
+ if (-1 == read(capture->deviceHandle,
|
|
487 |
+ capture->buffers[0].start,
|
|
488 |
+ capture->buffers[0].length)) {
|
|
489 |
+ switch (errno) {
|
|
490 |
+ case EAGAIN:
|
|
491 |
+ return 0;
|
|
492 |
+
|
|
493 |
+ case EIO:
|
|
494 |
+ default:
|
|
495 |
+ /* display the error and stop processing */
|
|
496 |
+ perror ("read");
|
|
497 |
+ return 1;
|
|
498 |
+ }
|
|
499 |
+ }
|
|
500 |
+ capture->bufferIndex = 0;
|
|
501 |
+
|
|
502 |
+ return 1;
|
|
503 |
+}
|
|
504 |
+
|
|
505 |
+static int mmap_read_frame_v4l2(CvCaptureCAM_V4L* capture) {
|
|
506 |
struct v4l2_buffer buf;
|
|
507 |
|
|
508 |
CLEAR (buf);
|
2630
|
509 |
@@ -1197,18 +1278,12 @@
|
2612
|
510 |
}
|
|
511 |
}
|
|
512 |
|
|
513 |
- assert(buf.index < capture->req.count);
|
|
514 |
+ assert(buf.index < capture->n_buffers);
|
|
515 |
|
|
516 |
- memcpy(capture->buffers[MAX_V4L_BUFFERS].start,
|
|
517 |
- capture->buffers[buf.index].start,
|
|
518 |
- capture->buffers[MAX_V4L_BUFFERS].length );
|
|
519 |
- capture->bufferIndex = MAX_V4L_BUFFERS;
|
|
520 |
+ capture->bufferIndex = buf.index;
|
|
521 |
//printf("got data in buff %d, len=%d, flags=0x%X, seq=%d, used=%d)\n",
|
|
522 |
// buf.index, buf.length, buf.flags, buf.sequence, buf.bytesused);
|
|
523 |
|
|
524 |
- if (-1 == xioctl (capture->deviceHandle, VIDIOC_QBUF, &buf))
|
|
525 |
- perror ("VIDIOC_QBUF");
|
|
526 |
-
|
|
527 |
return 1;
|
|
528 |
}
|
|
529 |
|
2630
|
530 |
@@ -1218,7 +1293,7 @@
|
2612
|
531 |
count = 1;
|
|
532 |
|
|
533 |
while (count-- > 0) {
|
|
534 |
- for (;;) {
|
|
535 |
+ for (; capture->devicePollable == true;) {
|
|
536 |
fd_set fds;
|
|
537 |
struct timeval tv;
|
|
538 |
int r;
|
2630
|
539 |
@@ -1233,10 +1308,12 @@
|
2612
|
540 |
r = select (capture->deviceHandle+1, &fds, NULL, NULL, &tv);
|
|
541 |
|
|
542 |
if (-1 == r) {
|
|
543 |
- if (EINTR == errno)
|
|
544 |
+ if (EINTR == errno || EAGAIN == errno)
|
|
545 |
continue;
|
|
546 |
-
|
|
547 |
- perror ("select");
|
|
548 |
+ if (ENXIO == errno)
|
|
549 |
+ capture->devicePollable = false;
|
|
550 |
+ else
|
|
551 |
+ perror ("select");
|
|
552 |
}
|
|
553 |
|
|
554 |
if (0 == r) {
|
2630
|
555 |
@@ -1245,7 +1322,12 @@
|
2612
|
556 |
/* end the infinite loop */
|
|
557 |
break;
|
|
558 |
}
|
|
559 |
+ }
|
|
560 |
|
|
561 |
+ if (capture->n_buffers != 0) {
|
|
562 |
+ if (mmap_read_frame_v4l2 (capture))
|
|
563 |
+ break;
|
|
564 |
+ } else {
|
|
565 |
if (read_frame_v4l2 (capture))
|
|
566 |
break;
|
|
567 |
}
|
2630
|
568 |
@@ -1267,9 +1349,7 @@
|
2612
|
569 |
if (V4L2_SUPPORT == 1)
|
|
570 |
{
|
|
571 |
|
|
572 |
- for (capture->bufferIndex = 0;
|
|
573 |
- capture->bufferIndex < ((int)capture->req.count);
|
|
574 |
- ++capture->bufferIndex)
|
|
575 |
+ for (unsigned int n_buffers = 0; n_buffers < capture->n_buffers; ++n_buffers)
|
|
576 |
{
|
|
577 |
|
|
578 |
struct v4l2_buffer buf;
|
2630
|
579 |
@@ -1278,7 +1358,7 @@
|
2612
|
580 |
|
|
581 |
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
582 |
buf.memory = V4L2_MEMORY_MMAP;
|
|
583 |
- buf.index = (unsigned long)capture->bufferIndex;
|
|
584 |
+ buf.index = (unsigned long)n_buffers;
|
|
585 |
|
|
586 |
if (-1 == xioctl (capture->deviceHandle, VIDIOC_QBUF, &buf)) {
|
|
587 |
perror ("VIDIOC_QBUF");
|
2630
|
588 |
@@ -1286,17 +1366,20 @@
|
2612
|
589 |
}
|
|
590 |
}
|
|
591 |
|
|
592 |
- /* enable the streaming */
|
|
593 |
- capture->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
594 |
- if (-1 == xioctl (capture->deviceHandle, VIDIOC_STREAMON,
|
|
595 |
- &capture->type)) {
|
|
596 |
- /* error enabling the stream */
|
|
597 |
- perror ("VIDIOC_STREAMON");
|
|
598 |
- return 0;
|
|
599 |
- }
|
|
600 |
+ if (capture->n_buffers != 0) {
|
|
601 |
+ /* enable the streaming */
|
|
602 |
+ capture->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
603 |
+ if (-1 == xioctl (capture->deviceHandle, VIDIOC_STREAMON,
|
|
604 |
+ &capture->type)) {
|
|
605 |
+ /* error enabling the stream */
|
|
606 |
+ perror ("VIDIOC_STREAMON");
|
|
607 |
+ return 0;
|
|
608 |
+ }
|
|
609 |
+ }
|
|
610 |
} else
|
2630
|
611 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
612 |
{
|
|
613 |
+#ifdef HAVE_CAMV4L
|
|
614 |
|
|
615 |
for (capture->bufferIndex = 0;
|
|
616 |
capture->bufferIndex < (capture->memoryBuffer.frames-1);
|
2630
|
617 |
@@ -1313,9 +1396,12 @@
|
2612
|
618 |
}
|
|
619 |
}
|
|
620 |
|
|
621 |
+#else
|
|
622 |
+ return 0;
|
|
623 |
+#endif /* HAVE_CAMV4L */
|
|
624 |
}
|
|
625 |
|
|
626 |
-#if defined(V4L_ABORT_BADJPEG) && defined(HAVE_CAMV4L2)
|
2630
|
627 |
+#if defined V4L_ABORT_BADJPEG && defined HAVE_CAMV4L2
|
2612
|
628 |
if (V4L2_SUPPORT == 1)
|
|
629 |
{
|
|
630 |
// skip first frame. it is often bad -- this is unnotied in traditional apps,
|
2630
|
631 |
@@ -1338,6 +1424,7 @@
|
2612
|
632 |
} else
|
2630
|
633 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
634 |
{
|
|
635 |
+#ifdef HAVE_CAMV4L
|
|
636 |
|
|
637 |
capture->mmaps[capture->bufferIndex].frame = capture->bufferIndex;
|
|
638 |
capture->mmaps[capture->bufferIndex].width = capture->captureWindow.width;
|
2630
|
639 |
@@ -1355,6 +1442,7 @@
|
2612
|
640 |
capture->bufferIndex = 0;
|
|
641 |
}
|
|
642 |
|
|
643 |
+#endif /* HAVE_CAMV4L */
|
|
644 |
}
|
|
645 |
|
|
646 |
return(1);
|
2630
|
647 |
@@ -2006,8 +2094,7 @@
|
2612
|
648 |
unsigned char *addr;
|
|
649 |
|
|
650 |
if (!init_done) {
|
|
651 |
- /* do sonix_decompress_init first! */
|
|
652 |
- return -1;
|
|
653 |
+ sonix_decompress_init();
|
|
654 |
}
|
|
655 |
|
|
656 |
bitpos = 0;
|
2630
|
657 |
@@ -2074,12 +2161,16 @@
|
2612
|
658 |
if (V4L2_SUPPORT == 0)
|
2630
|
659 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
660 |
{
|
|
661 |
+#ifdef HAVE_CAMV4L
|
|
662 |
|
|
663 |
/* [FD] this really belongs here */
|
|
664 |
if (ioctl(capture->deviceHandle, VIDIOCSYNC, &capture->mmaps[capture->bufferIndex].frame) == -1) {
|
|
665 |
fprintf( stderr, "HIGHGUI ERROR: V4L: Could not SYNC to video stream. %s\n", strerror(errno));
|
|
666 |
}
|
|
667 |
|
|
668 |
+#else
|
|
669 |
+ return 0;
|
|
670 |
+#endif /* HAVE_CAMV4L */
|
|
671 |
}
|
|
672 |
|
|
673 |
/* Now get what has already been captured as a IplImage return */
|
2630
|
674 |
@@ -2104,6 +2195,7 @@
|
2612
|
675 |
} else
|
2630
|
676 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
677 |
{
|
|
678 |
+#if HAVE_CAMV4L
|
|
679 |
|
|
680 |
if((capture->frame.width != capture->mmaps[capture->bufferIndex].width)
|
|
681 |
|| (capture->frame.height != capture->mmaps[capture->bufferIndex].height)) {
|
2630
|
682 |
@@ -2115,6 +2207,7 @@
|
2612
|
683 |
capture->frame.imageData = (char *)cvAlloc(capture->frame.imageSize);
|
|
684 |
}
|
|
685 |
|
|
686 |
+#endif /* HAVE_CAMV4L */
|
|
687 |
}
|
|
688 |
|
2630
|
689 |
#ifdef HAVE_CAMV4L2
|
|
690 |
@@ -2140,10 +2233,6 @@
|
2612
|
691 |
(unsigned char*)capture->frame.imageData);
|
|
692 |
|
|
693 |
#ifdef HAVE_JPEG
|
|
694 |
-#ifdef __USE_GNU
|
|
695 |
- /* support for MJPEG is only available with libjpeg and gcc,
|
|
696 |
- because it's use libjepg and fmemopen()
|
|
697 |
- */
|
|
698 |
if (PALETTE_MJPEG == 1)
|
|
699 |
if (!mjpeg_to_rgb24(capture->form.fmt.pix.width,
|
|
700 |
capture->form.fmt.pix.height,
|
2630
|
701 |
@@ -2153,7 +2242,6 @@
|
2612
|
702 |
(unsigned char*)capture->frame.imageData))
|
|
703 |
return 0;
|
|
704 |
#endif
|
|
705 |
-#endif
|
|
706 |
|
|
707 |
if (PALETTE_YUYV == 1)
|
|
708 |
yuyv_to_rgb24(capture->form.fmt.pix.width,
|
2630
|
709 |
@@ -2177,16 +2265,14 @@
|
2612
|
710 |
|
|
711 |
if (PALETTE_SN9C10X == 1)
|
|
712 |
{
|
|
713 |
- sonix_decompress_init();
|
|
714 |
-
|
|
715 |
sonix_decompress(capture->form.fmt.pix.width,
|
|
716 |
capture->form.fmt.pix.height,
|
|
717 |
(unsigned char*)capture->buffers[capture->bufferIndex].start,
|
|
718 |
- (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start);
|
|
719 |
+ (unsigned char*)capture->buffers[MAX_V4L_BUFFERS].start);
|
|
720 |
|
|
721 |
bayer2rgb24(capture->form.fmt.pix.width,
|
|
722 |
capture->form.fmt.pix.height,
|
|
723 |
- (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start,
|
|
724 |
+ (unsigned char*)capture->buffers[MAX_V4L_BUFFERS].start,
|
|
725 |
(unsigned char*)capture->frame.imageData);
|
|
726 |
}
|
|
727 |
|
2630
|
728 |
@@ -2194,13 +2280,14 @@
|
2612
|
729 |
{
|
|
730 |
sgbrg2rgb24(capture->form.fmt.pix.width,
|
|
731 |
capture->form.fmt.pix.height,
|
|
732 |
- (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start,
|
|
733 |
+ (unsigned char*)capture->buffers[capture->bufferIndex].start,
|
|
734 |
(unsigned char*)capture->frame.imageData);
|
|
735 |
}
|
|
736 |
|
|
737 |
} else
|
2630
|
738 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
739 |
{
|
|
740 |
+#if HAVE_CAMV4L
|
|
741 |
|
|
742 |
switch(capture->imageProperties.palette) {
|
|
743 |
case VIDEO_PALETTE_RGB24:
|
2630
|
744 |
@@ -2234,7 +2321,23 @@
|
2612
|
745 |
return 0;
|
|
746 |
}
|
|
747 |
|
|
748 |
+#endif /* HAVE_CAMV4L */
|
|
749 |
+ }
|
|
750 |
+
|
2630
|
751 |
+#ifdef HAVE_CAMV4L2
|
2612
|
752 |
+ if (capture->n_buffers != 0) {
|
|
753 |
+ struct v4l2_buffer buf;
|
|
754 |
+
|
|
755 |
+ CLEAR (buf);
|
|
756 |
+
|
|
757 |
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
758 |
+ buf.memory = V4L2_MEMORY_MMAP;
|
|
759 |
+ buf.index = (unsigned long)capture->bufferIndex;
|
|
760 |
+
|
|
761 |
+ if (-1 == xioctl (capture->deviceHandle, VIDIOC_QBUF, &buf))
|
|
762 |
+ perror ("VIDIOC_QBUF");
|
|
763 |
}
|
2630
|
764 |
+#endif /* HAVE_CAMV4L2 */
|
2612
|
765 |
|
|
766 |
return(&capture->frame);
|
|
767 |
}
|
2630
|
768 |
@@ -2358,6 +2461,7 @@
|
2612
|
769 |
} else
|
2630
|
770 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
771 |
{
|
|
772 |
+#ifdef HAVE_CAMV4L
|
|
773 |
|
|
774 |
int retval = -1;
|
|
775 |
|
2630
|
776 |
@@ -2413,6 +2517,9 @@
|
2612
|
777 |
/* all was OK, so convert to 0.0 - 1.0 range, and return the value */
|
|
778 |
return float (retval) / 0xFFFF;
|
|
779 |
|
|
780 |
+#else
|
|
781 |
+ return -1;
|
|
782 |
+#endif /* HAVE_CAMV4L */
|
|
783 |
}
|
|
784 |
|
|
785 |
};
|
2630
|
786 |
@@ -2482,6 +2589,7 @@
|
2612
|
787 |
} else
|
2630
|
788 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
789 |
{
|
|
790 |
+#ifdef HAVE_CAMV4L
|
|
791 |
|
|
792 |
if (capture==0) return 0;
|
|
793 |
if (w>capture->capability.maxwidth) {
|
2630
|
794 |
@@ -2506,6 +2614,7 @@
|
2612
|
795 |
|
|
796 |
capture->FirstCapture = 1;
|
|
797 |
|
|
798 |
+#endif /* HAVE_CAMV4L */
|
|
799 |
}
|
|
800 |
|
|
801 |
return 0;
|
2630
|
802 |
@@ -2641,6 +2750,7 @@
|
2612
|
803 |
} else
|
2630
|
804 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
805 |
{
|
|
806 |
+#ifdef HAVE_CAMV4L
|
|
807 |
|
|
808 |
int v4l_value;
|
|
809 |
|
2630
|
810 |
@@ -2683,6 +2793,9 @@
|
2612
|
811 |
icvCloseCAM_V4L(capture);
|
|
812 |
return -1;
|
|
813 |
}
|
|
814 |
+#else
|
|
815 |
+ return -1;
|
|
816 |
+#endif /* HAVE_CAMV4L */
|
|
817 |
}
|
|
818 |
|
|
819 |
/* all was OK */
|
2630
|
820 |
@@ -2745,31 +2858,41 @@
|
2612
|
821 |
if (V4L2_SUPPORT == 0)
|
2630
|
822 |
#endif /* HAVE_CAMV4L2 */
|
2612
|
823 |
{
|
|
824 |
+#ifdef HAVE_CAMV4L
|
|
825 |
|
|
826 |
if (capture->mmaps)
|
|
827 |
free(capture->mmaps);
|
|
828 |
if (capture->memoryMap)
|
|
829 |
munmap(capture->memoryMap, capture->memoryBuffer.size);
|
|
830 |
|
2630
|
831 |
+#endif /* HAVE_CAMV4L */
|
2612
|
832 |
}
|
2630
|
833 |
#ifdef HAVE_CAMV4L2
|
2612
|
834 |
else {
|
|
835 |
capture->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
836 |
- if (ioctl(capture->deviceHandle, VIDIOC_STREAMOFF, &capture->type) < 0) {
|
|
837 |
- perror ("Unable to stop the stream.");
|
|
838 |
+ if (capture->n_buffers != 0) {
|
|
839 |
+ if (ioctl(capture->deviceHandle, VIDIOC_STREAMOFF, &capture->type) < 0) {
|
|
840 |
+ perror ("Unable to stop the stream.");
|
|
841 |
+ }
|
|
842 |
}
|
|
843 |
|
|
844 |
- for (unsigned int n_buffers = 0; n_buffers < capture->req.count; ++n_buffers)
|
|
845 |
+ if (capture->buffers[MAX_V4L_BUFFERS].start != NULL)
|
|
846 |
{
|
|
847 |
- if (-1 == munmap (capture->buffers[n_buffers].start, capture->buffers[n_buffers].length)) {
|
|
848 |
+ free(capture->buffers[MAX_V4L_BUFFERS].start);
|
|
849 |
+ capture->buffers[MAX_V4L_BUFFERS].start = NULL;
|
|
850 |
+ }
|
|
851 |
+
|
|
852 |
+ for (unsigned int n_buffers = 0; n_buffers < capture->n_buffers; ++n_buffers)
|
|
853 |
+ {
|
|
854 |
+ if (-1 == munmap ((char *)capture->buffers[n_buffers].start, capture->buffers[n_buffers].length)) {
|
|
855 |
perror ("munmap");
|
|
856 |
}
|
|
857 |
}
|
|
858 |
|
|
859 |
- if (capture->buffers[MAX_V4L_BUFFERS].start)
|
|
860 |
+ if (capture->n_buffers == 0)
|
|
861 |
{
|
|
862 |
- free(capture->buffers[MAX_V4L_BUFFERS].start);
|
|
863 |
- capture->buffers[MAX_V4L_BUFFERS].start = 0;
|
|
864 |
+ free(capture->buffers[0].start);
|
|
865 |
+ capture->buffers[0].start = NULL;
|
|
866 |
}
|
|
867 |
}
|
2630
|
868 |
#endif /* HAVE_CAMV4L2 */
|
|
869 |
@@ -2848,4 +2971,4 @@
|
|
870 |
return 0;
|
|
871 |
}
|
2612
|
872 |
|
2630
|
873 |
-#endif
|
|
874 |
+#endif /* !WIN32 && (HAVE_CAMV4L || HAVE_CAMV4L2) */
|