From d90b8d615cd3e8fa881954e8831b998b8d663bd6 Mon Sep 17 00:00:00 2001 From: Patrick Welche Date: Mon, 17 Sep 2012 11:08:37 +0200 Subject: [PATCH 1/5] NetBSD video(4) support, patch 1 of 3 The video(4) driver provides a Video4Linux2 compatible API for various video peripherals. This patch propagates HAVE_VIDEOIO if the sys/videoio.h include file is found, which is the signature of video(4). --- CMakeLists.txt | 2 +- cmake/OpenCVFindLibsVideo.cmake | 1 + cmake/templates/cvconfig.h.cmake | 3 +++ modules/highgui/CMakeLists.txt | 2 +- modules/highgui/src/cap.cpp | 3 ++- modules/highgui/src/cap_v4l.cpp | 7 ++++++- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e5cd9ec03..c977f97662 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -722,7 +722,7 @@ if(DEFINED WITH_V4L) else() set(HAVE_CAMV4L_STR "NO") endif() - if(HAVE_CAMV4L2) + if(HAVE_CAMV4L2 OR HAVE_VIDEOIO) set(HAVE_CAMV4L2_STR "YES") else() set(HAVE_CAMV4L2_STR "NO") diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index fdc9ea27f7..cfa4dcab97 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -90,6 +90,7 @@ if(WITH_V4L) CHECK_MODULE(libv4l1 HAVE_LIBV4L) CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L) CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2) + CHECK_INCLUDE_FILE(sys/videoio.h HAVE_VIDEOIO) endif(WITH_V4L) # --- OpenNI --- diff --git a/cmake/templates/cvconfig.h.cmake b/cmake/templates/cvconfig.h.cmake index 368905fd9c..e44e1359a2 100644 --- a/cmake/templates/cvconfig.h.cmake +++ b/cmake/templates/cvconfig.h.cmake @@ -19,6 +19,9 @@ /* V4L2 capturing support */ #cmakedefine HAVE_CAMV4L2 +/* V4L2 capturing support in videoio.h */ +#cmakedefine HAVE_VIDEOIO + /* V4L/V4L2 capturing support via libv4l */ #cmakedefine HAVE_LIBV4L diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index b4b2896d7a..3c8f9ba9ab 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -131,7 +131,7 @@ endif(HAVE_UNICAP) if(HAVE_LIBV4L) list(APPEND highgui_srcs src/cap_libv4l.cpp) -elseif(HAVE_CAMV4L OR HAVE_CAMV4L2) +elseif(HAVE_CAMV4L OR HAVE_CAMV4L2 OR HAVE_VIDEOIO) list(APPEND highgui_srcs src/cap_v4l.cpp) endif() diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index f8d32e7eee..821478f1b3 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -173,6 +173,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) defined(HAVE_VFW) || \ defined(HAVE_LIBV4L) || \ (defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2)) || \ + defined(HAVE_VIDEOIO) || \ defined(HAVE_GSTREAMER) || \ defined(HAVE_DC1394_2) || \ defined(HAVE_DC1394) || \ @@ -216,7 +217,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) return capture; #endif -#if defined HAVE_LIBV4L || (defined (HAVE_CAMV4L) && defined (HAVE_CAMV4L2)) +#if defined HAVE_LIBV4L || (defined (HAVE_CAMV4L) && defined (HAVE_CAMV4L2)) || defined HAVE_VIDEOIO capture = cvCreateCameraCapture_V4L (index); if (capture) return capture; diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index 2ab4567d15..33e0f386aa 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -202,7 +202,7 @@ make & enjoy! #include "precomp.hpp" -#if !defined WIN32 && defined HAVE_CAMV4L && defined HAVE_CAMV4L2 +#if !defined WIN32 && ((defined HAVE_CAMV4L && defined HAVE_CAMV4L2) || defined HAVE_VIDEOIO) #define CLEAR(x) memset (&(x), 0, sizeof (x)) @@ -227,6 +227,11 @@ make & enjoy! #include #endif +#ifdef HAVE_VIDEOIO +#include +#define HAVE_CAMV4L2 +#endif + /* Defaults - If your board can do better, set it here. Set for the most common type inputs. */ #define DEFAULT_V4L_WIDTH 640 #define DEFAULT_V4L_HEIGHT 480 From 681ffd9a215c5be006999a57b890ee446b4bd801 Mon Sep 17 00:00:00 2001 From: Patrick Welche Date: Mon, 17 Sep 2012 12:03:35 +0200 Subject: [PATCH 2/5] NetBSD video(4) support, patch 2 of 3 * Decouple Video4Linux2 support from Video4Linux as existence of v4l2 on a system does not imply support for v4l. * Don't use V4L's struct video_window in V4L2 code. * Removed __USE_GNU as comment says: /* support for MJPEG is only available with libjpeg and gcc, because it's use libjepg and fmemopen() so replace with test for fmemopen() if found necessary. --- modules/highgui/src/cap.cpp | 5 +- modules/highgui/src/cap_v4l.cpp | 181 +++++++++++++++++++++----------- 2 files changed, 123 insertions(+), 63 deletions(-) diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index 821478f1b3..13475f2633 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -172,7 +172,8 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) defined(HAVE_TYZX) || \ defined(HAVE_VFW) || \ defined(HAVE_LIBV4L) || \ - (defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2)) || \ + defined(HAVE_CAMV4L) || \ + defined(HAVE_CAMV4L2) || \ defined(HAVE_VIDEOIO) || \ defined(HAVE_GSTREAMER) || \ defined(HAVE_DC1394_2) || \ @@ -217,7 +218,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) return capture; #endif -#if defined HAVE_LIBV4L || (defined (HAVE_CAMV4L) && defined (HAVE_CAMV4L2)) || defined HAVE_VIDEOIO +#if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO capture = cvCreateCameraCapture_V4L (index); if (capture) return capture; diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index 33e0f386aa..a0d51e8d89 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -202,7 +202,7 @@ make & enjoy! #include "precomp.hpp" -#if !defined WIN32 && ((defined HAVE_CAMV4L && defined HAVE_CAMV4L2) || defined HAVE_VIDEOIO) +#if !defined WIN32 && (defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO) #define CLEAR(x) memset (&(x), 0, sizeof (x)) @@ -214,16 +214,18 @@ make & enjoy! #include #include +#ifdef HAVE_CAMVAL #include +#endif #include #include -#include /* for videodev2.h */ #include #include #include #ifdef HAVE_CAMV4L2 +#include /* for videodev2.h */ #include #endif @@ -293,11 +295,13 @@ typedef struct CvCaptureCAM_V4L int deviceHandle; int bufferIndex; int FirstCapture; +#ifdef HAVE_CAMV4L struct video_capability capability; struct video_window captureWindow; struct video_picture imageProperties; struct video_mbuf memoryBuffer; struct video_mmap *mmaps; +#endif /* HAVE_CAMV4L */ char *memoryMap; IplImage frame; @@ -350,9 +354,6 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h); static int numCameras = 0; static int indexList = 0; -#ifdef HAVE_CAMV4L2 - -// IOCTL handling for V4L2 static int xioctl( int fd, int request, void *arg) { @@ -366,8 +367,6 @@ static int xioctl( int fd, int request, void *arg) } -#endif /* HAVE_CAMV4L2 */ - /* Simple test program: Find number of Video Sources available. Start from 0 and go to MAX_CAMERAS while checking for the device with that name. If it fails on the first attempt of /dev/video0, then check if /dev/video is valid. @@ -398,6 +397,8 @@ static void icvInitCapture_V4L() { }; /* End icvInitCapture_V4L */ +#ifdef HAVE_CAMV4L + static int try_palette(int fd, struct video_picture *cam_pic, @@ -415,6 +416,8 @@ try_palette(int fd, return 0; } +#endif /* HAVE_CAMV4L */ + #ifdef HAVE_CAMV4L2 static int try_palette_v4l2(CvCaptureCAM_V4L* capture, unsigned long colorspace) @@ -439,6 +442,8 @@ static int try_palette_v4l2(CvCaptureCAM_V4L* capture, unsigned long colorspace) #endif /* HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L + static int try_init_v4l(CvCaptureCAM_V4L* capture, char *deviceName) { @@ -454,7 +459,6 @@ static int try_init_v4l(CvCaptureCAM_V4L* capture, char *deviceName) /* No matter what the name - it still must be opened! */ capture->deviceHandle = open(deviceName, O_RDWR); - if (capture->deviceHandle == 0) { detect = -1; @@ -468,7 +472,6 @@ static int try_init_v4l(CvCaptureCAM_V4L* capture, char *deviceName) if (ioctl(capture->deviceHandle, VIDIOCGCAP, &capture->capability) < 0) { detect = 0; - icvCloseCAM_V4L(capture); } else @@ -481,54 +484,64 @@ static int try_init_v4l(CvCaptureCAM_V4L* capture, char *deviceName) } +#endif /* HAVE_CAMV4L */ + #ifdef HAVE_CAMV4L2 static int try_init_v4l2(CvCaptureCAM_V4L* capture, char *deviceName) { - - // if detect = -1 then unable to open device - // if detect = 0 then detected nothing - // if detect = 1 then V4L2 device - int detect = 0; - - // Test device for V4L2 compability + // Return value: + // -1 then unable to open device + // 0 then detected nothing + // 1 then V4L2 device + + int deviceIndex; /* Open and test V4L2 device */ capture->deviceHandle = open (deviceName, O_RDWR /* required */ | O_NONBLOCK, 0); - - - - if (capture->deviceHandle == 0) + if (-1 == capture->deviceHandle) { - detect = -1; - +#ifndef NDEBUG + fprintf(stderr, "(DEBUG) try_init_v4l2 open \"%s\": %s\n", deviceName, strerror(errno)); +#endif icvCloseCAM_V4L(capture); + return -1; } - if (detect == 0) + CLEAR (capture->cap); + if (-1 == xioctl (capture->deviceHandle, VIDIOC_QUERYCAP, &capture->cap)) { - CLEAR (capture->cap); - if (-1 == xioctl (capture->deviceHandle, VIDIOC_QUERYCAP, &capture->cap)) - { - detect = 0; +#ifndef NDEBUG + fprintf(stderr, "(DEBUG) try_init_v4l2 VIDIOC_QUERYCAP \"%s\": %s\n", deviceName, strerror(errno)); +#endif + icvCloseCAM_V4L(capture); + return 0; + } - icvCloseCAM_V4L(capture); - } - else - { - CLEAR (capture->capability); - capture->capability.type = capture->cap.capabilities; + /* Query channels number */ + if (-1 == xioctl (capture->deviceHandle, VIDIOC_G_INPUT, &deviceIndex)) + { +#ifndef NDEBUG + fprintf(stderr, "(DEBUG) try_init_v4l2 VIDIOC_G_INPUT \"%s\": %s\n", deviceName, strerror(errno)); +#endif + icvCloseCAM_V4L(capture); + return 0; + } - /* Query channels number */ - if (-1 != xioctl (capture->deviceHandle, VIDIOC_G_INPUT, &capture->capability.channels)) - { - detect = 1; - } - } + /* Query information about current input */ + CLEAR (capture->inp); + capture->inp.index = deviceIndex; + if (-1 == xioctl (capture->deviceHandle, VIDIOC_ENUMINPUT, &capture->inp)) + { +#ifndef NDEBUG + fprintf(stderr, "(DEBUG) try_init_v4l2 VIDIOC_ENUMINPUT \"%s\": %s\n", deviceName, strerror(errno)); +#endif + icvCloseCAM_V4L(capture); + return 0; } - return detect; + return 1; } @@ -551,17 +564,12 @@ static int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture) else #ifdef HAVE_JPEG -#ifdef __USE_GNU - /* support for MJPEG is only available with libjpeg and gcc, - because it's use libjepg and fmemopen() - */ if (try_palette_v4l2(capture, V4L2_PIX_FMT_MJPEG) == 0 || try_palette_v4l2(capture, V4L2_PIX_FMT_JPEG) == 0) { capture->palette = PALETTE_MJPEG; } else -#endif #endif if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUYV) == 0) @@ -598,6 +606,8 @@ static int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture) #endif /* HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L + static int autosetup_capture_mode_v4l(CvCaptureCAM_V4L* capture) { @@ -631,6 +641,8 @@ static int autosetup_capture_mode_v4l(CvCaptureCAM_V4L* capture) } +#endif /* HAVE_CAMV4L */ + #ifdef HAVE_CAMV4L2 static void v4l2_scan_controls_enumerate_menu(CvCaptureCAM_V4L* capture) @@ -981,8 +993,8 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName) /* Set up Image data */ cvInitImageHeader( &capture->frame, - cvSize( capture->captureWindow.width, - capture->captureWindow.height ), + cvSize( capture->form.fmt.pix.width, + capture->form.fmt.pix.height ), IPL_DEPTH_8U, 3, IPL_ORIGIN_TL, 4 ); /* Allocate space for RGBA data */ capture->frame.imageData = (char *)cvAlloc(capture->frame.imageSize); @@ -992,6 +1004,8 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName) #endif /* HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L + static int _capture_V4L (CvCaptureCAM_V4L *capture, char *deviceName) { int detect_v4l = 0; @@ -1110,6 +1124,8 @@ static int _capture_V4L (CvCaptureCAM_V4L *capture, char *deviceName) return 1; }; /* End _capture_V4L */ +#endif /* HAVE_CAMV4L */ + static CvCaptureCAM_V4L * icvCaptureFromCAM_V4L (int index) { static int autoindex; @@ -1159,10 +1175,12 @@ static CvCaptureCAM_V4L * icvCaptureFromCAM_V4L (int index) icvCloseCAM_V4L(capture); V4L2_SUPPORT = 0; #endif /* HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L if (_capture_V4L (capture, deviceName) == -1) { icvCloseCAM_V4L(capture); return NULL; } +#endif /* HAVE_CAMV4L */ #ifdef HAVE_CAMV4L2 } else { V4L2_SUPPORT = 1; @@ -1271,7 +1289,9 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { #ifdef HAVE_CAMV4L2 +#ifdef HAVE_CAMV4L if (V4L2_SUPPORT == 1) +#endif { for (capture->bufferIndex = 0; @@ -1301,8 +1321,12 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { perror ("VIDIOC_STREAMON"); return 0; } - } else + } #endif /* HAVE_CAMV4L2 */ +#if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) + else +#endif /* HAVE_CAMV4L && HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { for (capture->bufferIndex = 0; @@ -1321,6 +1345,7 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { } } +#endif /* HAVE_CAMV4L */ #if defined(V4L_ABORT_BADJPEG) && defined(HAVE_CAMV4L2) if (V4L2_SUPPORT == 1) @@ -1342,8 +1367,12 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { mainloop_v4l2(capture); - } else + } #endif /* HAVE_CAMV4L2 */ +#if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) + else +#endif /* HAVE_CAMV4L && HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { capture->mmaps[capture->bufferIndex].frame = capture->bufferIndex; @@ -1363,6 +1392,7 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { } } +#endif /* HAVE_CAMV4L */ return(1); } @@ -2080,6 +2110,7 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { #ifdef HAVE_CAMV4L2 if (V4L2_SUPPORT == 0) #endif /* HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { /* [FD] this really belongs here */ @@ -2088,6 +2119,7 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { } } +#endif /* HAVE_CAMV4L */ /* Now get what has already been captured as a IplImage return */ @@ -2108,8 +2140,12 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { capture->frame.imageData = (char *)cvAlloc(capture->frame.imageSize); } - } else + } #endif /* HAVE_CAMV4L2 */ +#if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) + else +#endif /* HAVE_CAMV4L && HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { if((capture->frame.width != capture->mmaps[capture->bufferIndex].width) @@ -2123,6 +2159,7 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { } } +#endif /* HAVE_CAMV4L */ #ifdef HAVE_CAMV4L2 @@ -2150,10 +2187,6 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { (unsigned char*)capture->frame.imageData); break; #ifdef HAVE_JPEG -#ifdef __USE_GNU - /* support for MJPEG is only available with libjpeg and gcc, - because it's use libjepg and fmemopen() - */ case PALETTE_MJPEG: if (!mjpeg_to_rgb24(capture->form.fmt.pix.width, capture->form.fmt.pix.height, @@ -2163,7 +2196,6 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { (unsigned char*)capture->frame.imageData)) return 0; break; -#endif #endif case PALETTE_YUYV: @@ -2206,8 +2238,12 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { (unsigned char*)capture->frame.imageData); break; } - } else + } #endif /* HAVE_CAMV4L2 */ +#if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) + else +#endif /* HAVE_CAMV4L && HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { switch(capture->imageProperties.palette) { @@ -2243,6 +2279,7 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { } } +#endif /* HAVE_CAMV4L */ return(&capture->frame); } @@ -2252,7 +2289,9 @@ static double icvGetPropertyCAM_V4L (CvCaptureCAM_V4L* capture, #ifdef HAVE_CAMV4L2 +#ifdef HAVE_CAMV4L if (V4L2_SUPPORT == 1) +#endif { /* default value for min and max */ @@ -2363,8 +2402,12 @@ static double icvGetPropertyCAM_V4L (CvCaptureCAM_V4L* capture, /* all was OK, so convert to 0.0 - 1.0 range, and return the value */ return ((float)capture->control.value - v4l2_min + 1) / (v4l2_max - v4l2_min); - } else + } #endif /* HAVE_CAMV4L2 */ +#if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) + else +#endif /* HAVE_CAMV4L && HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { int retval = -1; @@ -2422,6 +2465,7 @@ static double icvGetPropertyCAM_V4L (CvCaptureCAM_V4L* capture, return float (retval) / 0xFFFF; } +#endif /* HAVE_CAMV4L */ }; @@ -2494,8 +2538,12 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { return 0; - } else + } #endif /* HAVE_CAMV4L2 */ +#if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) + else +#endif /* HAVE_CAMV4L && HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { if (capture==0) return 0; @@ -2522,6 +2570,7 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { capture->FirstCapture = 1; } +#endif /* HAVE_CAMV4L */ return 0; @@ -2653,8 +2702,12 @@ static int icvSetControl (CvCaptureCAM_V4L* capture, perror ("VIDIOC_S_CTRL"); return -1; } - } else + } #endif /* HAVE_CAMV4L2 */ +#if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) + else +#endif /* HAVE_CAMV4L && HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { int v4l_value; @@ -2699,6 +2752,7 @@ static int icvSetControl (CvCaptureCAM_V4L* capture, return -1; } } +#endif /* HAVE_CAMV4L */ /* all was OK */ return 0; @@ -2759,6 +2813,7 @@ static void icvCloseCAM_V4L( CvCaptureCAM_V4L* capture ){ #ifdef HAVE_CAMV4L2 if (V4L2_SUPPORT == 0) #endif /* HAVE_CAMV4L2 */ +#ifdef HAVE_CAMV4L { if (capture->mmaps) @@ -2767,10 +2822,14 @@ static void icvCloseCAM_V4L( CvCaptureCAM_V4L* capture ){ munmap(capture->memoryMap, capture->memoryBuffer.size); } +#endif /* HAVE_CAMV4L */ +#if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) + else +#endif /* HAVE_CAMV4L && HAVE_CAMV4L2 */ #ifdef HAVE_CAMV4L2 - else { + { capture->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (ioctl(capture->deviceHandle, VIDIOC_STREAMOFF, &capture->type) < 0) { + if (-1 == ioctl(capture->deviceHandle, VIDIOC_STREAMOFF, &capture->type)) { perror ("Unable to stop the stream."); } From 1a84bcc56545d15b88bc6a159906f37879e778e9 Mon Sep 17 00:00:00 2001 From: Patrick Welche Date: Mon, 17 Sep 2012 14:46:54 +0200 Subject: [PATCH 3/5] NetBSD video(4) support, patch 3 of 3 xioctl() assumes that ioctl takes int request. Cope with int ioctl(int d, unsigned long request, ...) to avoid "invalid argument". --- cmake/OpenCVFindLibsVideo.cmake | 8 +++++++- cmake/templates/cvconfig.h.cmake | 3 +++ modules/highgui/src/cap_libv4l.cpp | 4 ++++ modules/highgui/src/cap_v4l.cpp | 7 ++++--- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index cfa4dcab97..323b1cbe96 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -85,12 +85,18 @@ if(WITH_XINE) endif(WITH_XINE) # --- V4L --- -ocv_clear_vars(HAVE_LIBV4L HAVE_CAMV4L HAVE_CAMV4L2) +ocv_clear_vars(HAVE_LIBV4L HAVE_CAMV4L HAVE_CAMV4L2 HAVE_IOCTL_ULONG) if(WITH_V4L) CHECK_MODULE(libv4l1 HAVE_LIBV4L) CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L) CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2) CHECK_INCLUDE_FILE(sys/videoio.h HAVE_VIDEOIO) + INCLUDE(CheckPrototypeDefinition) + CHECK_PROTOTYPE_DEFINITION(ioctl + "int ioctl(int d, unsigned long request, ...)" + "-1" + "sys/ioctl.h" + HAVE_IOCTL_ULONG) endif(WITH_V4L) # --- OpenNI --- diff --git a/cmake/templates/cvconfig.h.cmake b/cmake/templates/cvconfig.h.cmake index e44e1359a2..dab3ec8d51 100644 --- a/cmake/templates/cvconfig.h.cmake +++ b/cmake/templates/cvconfig.h.cmake @@ -25,6 +25,9 @@ /* V4L/V4L2 capturing support via libv4l */ #cmakedefine HAVE_LIBV4L +/* ioctl takes unsigned long request rather than int */ +#cmakedefine HAVE_IOCTL_ULONG + /* Carbon windowing environment */ #cmakedefine HAVE_CARBON diff --git a/modules/highgui/src/cap_libv4l.cpp b/modules/highgui/src/cap_libv4l.cpp index 01b611c66c..63a2ff96b0 100644 --- a/modules/highgui/src/cap_libv4l.cpp +++ b/modules/highgui/src/cap_libv4l.cpp @@ -346,7 +346,11 @@ static int numCameras = 0; static int indexList = 0; // IOCTL handling for V4L2 +#ifdef HAVE_IOCTL_ULONG +static int xioctl( int fd, unsigned long request, void *arg) +#else static int xioctl( int fd, int request, void *arg) +#endif { int r; diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index a0d51e8d89..3510ca3c4d 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -354,17 +354,18 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h); static int numCameras = 0; static int indexList = 0; +#ifdef HAVE_IOCTL_ULONG +static int xioctl( int fd, unsigned long request, void *arg) +#else static int xioctl( int fd, int request, void *arg) +#endif { - int r; - do r = ioctl (fd, request, arg); while (-1 == r && EINTR == errno); return r; - } /* Simple test program: Find number of Video Sources available. From cf407c2ec0354a45e49c4880412474ec2ef52aa6 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Mon, 28 Jan 2013 17:58:57 +0400 Subject: [PATCH 4/5] Don't check for EINTR and replace xioctl with ioctl This should be safe todo unless we are writing a signal handler. --- CMakeLists.txt | 8 ++-- cmake/OpenCVFindLibsVideo.cmake | 8 +--- cmake/templates/cvconfig.h.cmake | 3 -- modules/highgui/src/cap_v4l.cpp | 66 +++++++++++++------------------- 4 files changed, 32 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c977f97662..f2b088a6e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF OCV_OPTION(WITH_CSTRIPES "Include C= support" OFF IF WIN32 ) OCV_OPTION(WITH_TIFF "Include TIFF support" ON IF (NOT IOS) ) OCV_OPTION(WITH_UNICAP "Include Unicap support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) +OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON IF (UNIX AND NOT ANDROID) ) OCV_OPTION(WITH_VIDEOINPUT "Build HighGUI with DirectShow support" ON IF WIN32 ) OCV_OPTION(WITH_XIMEA "Include XIMEA cameras support" OFF IF (NOT ANDROID AND NOT APPLE) ) OCV_OPTION(WITH_XINE "Include Xine support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) @@ -722,13 +722,15 @@ if(DEFINED WITH_V4L) else() set(HAVE_CAMV4L_STR "NO") endif() - if(HAVE_CAMV4L2 OR HAVE_VIDEOIO) + if(HAVE_CAMV4L2) set(HAVE_CAMV4L2_STR "YES") + elseif(HAVE_VIDEOIO) + set(HAVE_CAMV4L2_STR "YES(videoio)") else() set(HAVE_CAMV4L2_STR "NO") endif() status(" V4L/V4L2:" HAVE_LIBV4L THEN "Using libv4l (ver ${ALIASOF_libv4l1_VERSION})" - ELSE "${HAVE_CAMV4L_STR}/${HAVE_CAMV4L2_STR}") + ELSE "${HAVE_CAMV4L_STR}/${HAVE_CAMV4L2_STR}") endif(DEFINED WITH_V4L) if(DEFINED WITH_VIDEOINPUT) diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index 323b1cbe96..414918527b 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -85,18 +85,12 @@ if(WITH_XINE) endif(WITH_XINE) # --- V4L --- -ocv_clear_vars(HAVE_LIBV4L HAVE_CAMV4L HAVE_CAMV4L2 HAVE_IOCTL_ULONG) +ocv_clear_vars(HAVE_LIBV4L HAVE_CAMV4L HAVE_CAMV4L2 HAVE_VIDEOIO) if(WITH_V4L) CHECK_MODULE(libv4l1 HAVE_LIBV4L) CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L) CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2) CHECK_INCLUDE_FILE(sys/videoio.h HAVE_VIDEOIO) - INCLUDE(CheckPrototypeDefinition) - CHECK_PROTOTYPE_DEFINITION(ioctl - "int ioctl(int d, unsigned long request, ...)" - "-1" - "sys/ioctl.h" - HAVE_IOCTL_ULONG) endif(WITH_V4L) # --- OpenNI --- diff --git a/cmake/templates/cvconfig.h.cmake b/cmake/templates/cvconfig.h.cmake index dab3ec8d51..e44e1359a2 100644 --- a/cmake/templates/cvconfig.h.cmake +++ b/cmake/templates/cvconfig.h.cmake @@ -25,9 +25,6 @@ /* V4L/V4L2 capturing support via libv4l */ #cmakedefine HAVE_LIBV4L -/* ioctl takes unsigned long request rather than int */ -#cmakedefine HAVE_IOCTL_ULONG - /* Carbon windowing environment */ #cmakedefine HAVE_CARBON diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index 3510ca3c4d..eacd744b12 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -354,20 +354,6 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h); static int numCameras = 0; static int indexList = 0; -#ifdef HAVE_IOCTL_ULONG -static int xioctl( int fd, unsigned long request, void *arg) -#else -static int xioctl( int fd, int request, void *arg) -#endif -{ - int r; - - do r = ioctl (fd, request, arg); - while (-1 == r && EINTR == errno); - - return r; -} - /* Simple test program: Find number of Video Sources available. Start from 0 and go to MAX_CAMERAS while checking for the device with that name. If it fails on the first attempt of /dev/video0, then check if /dev/video is valid. @@ -431,7 +417,7 @@ static int try_palette_v4l2(CvCaptureCAM_V4L* capture, unsigned long colorspace) capture->form.fmt.pix.width = DEFAULT_V4L_WIDTH; capture->form.fmt.pix.height = DEFAULT_V4L_HEIGHT; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form)) + if (-1 == ioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form)) return -1; @@ -511,7 +497,7 @@ static int try_init_v4l2(CvCaptureCAM_V4L* capture, char *deviceName) } CLEAR (capture->cap); - if (-1 == xioctl (capture->deviceHandle, VIDIOC_QUERYCAP, &capture->cap)) + if (-1 == ioctl (capture->deviceHandle, VIDIOC_QUERYCAP, &capture->cap)) { #ifndef NDEBUG fprintf(stderr, "(DEBUG) try_init_v4l2 VIDIOC_QUERYCAP \"%s\": %s\n", deviceName, strerror(errno)); @@ -521,7 +507,7 @@ static int try_init_v4l2(CvCaptureCAM_V4L* capture, char *deviceName) } /* Query channels number */ - if (-1 == xioctl (capture->deviceHandle, VIDIOC_G_INPUT, &deviceIndex)) + if (-1 == ioctl (capture->deviceHandle, VIDIOC_G_INPUT, &deviceIndex)) { #ifndef NDEBUG fprintf(stderr, "(DEBUG) try_init_v4l2 VIDIOC_G_INPUT \"%s\": %s\n", deviceName, strerror(errno)); @@ -533,7 +519,7 @@ static int try_init_v4l2(CvCaptureCAM_V4L* capture, char *deviceName) /* Query information about current input */ CLEAR (capture->inp); capture->inp.index = deviceIndex; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_ENUMINPUT, &capture->inp)) + if (-1 == ioctl (capture->deviceHandle, VIDIOC_ENUMINPUT, &capture->inp)) { #ifndef NDEBUG fprintf(stderr, "(DEBUG) try_init_v4l2 VIDIOC_ENUMINPUT \"%s\": %s\n", deviceName, strerror(errno)); @@ -655,7 +641,7 @@ static void v4l2_scan_controls_enumerate_menu(CvCaptureCAM_V4L* capture) (int)capture->querymenu.index <= capture->queryctrl.maximum; capture->querymenu.index++) { - if (0 == xioctl (capture->deviceHandle, VIDIOC_QUERYMENU, + if (0 == ioctl (capture->deviceHandle, VIDIOC_QUERYMENU, &capture->querymenu)) { // printf (" %s\n", capture->querymenu.name); @@ -679,7 +665,7 @@ static void v4l2_scan_controls(CvCaptureCAM_V4L* capture) CLEAR (capture->queryctrl); capture->queryctrl.id = ctrl_id; - if (0 == xioctl (capture->deviceHandle, VIDIOC_QUERYCTRL, + if (0 == ioctl (capture->deviceHandle, VIDIOC_QUERYCTRL, &capture->queryctrl)) { @@ -749,7 +735,7 @@ static void v4l2_scan_controls(CvCaptureCAM_V4L* capture) CLEAR (capture->queryctrl); capture->queryctrl.id = ctrl_id; - if (0 == xioctl (capture->deviceHandle, VIDIOC_QUERYCTRL, + if (0 == ioctl (capture->deviceHandle, VIDIOC_QUERYCTRL, &capture->queryctrl)) { @@ -872,7 +858,7 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName) capture->inp.index = CHANNEL_NUMBER; /* Set only channel number to CHANNEL_NUMBER */ /* V4L2 have a status field from selected video mode */ - if (-1 == xioctl (capture->deviceHandle, VIDIOC_ENUMINPUT, &capture->inp)) + if (-1 == ioctl (capture->deviceHandle, VIDIOC_ENUMINPUT, &capture->inp)) { fprintf (stderr, "HIGHGUI ERROR: V4L2: Aren't able to set channel number\n"); icvCloseCAM_V4L (capture); @@ -884,7 +870,7 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName) CLEAR (capture->form); capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form)) { + if (-1 == ioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form)) { fprintf( stderr, "HIGHGUI ERROR: V4L2: Could not obtain specifics of capture window.\n\n"); icvCloseCAM_V4L(capture); return -1; @@ -922,7 +908,7 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName) capture->req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; capture->req.memory = V4L2_MEMORY_MMAP; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_REQBUFS, &capture->req)) + if (-1 == ioctl (capture->deviceHandle, VIDIOC_REQBUFS, &capture->req)) { if (EINVAL == errno) { @@ -962,7 +948,7 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName) buf.memory = V4L2_MEMORY_MMAP; buf.index = n_buffers; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_QUERYBUF, &buf)) { + if (-1 == ioctl (capture->deviceHandle, VIDIOC_QUERYBUF, &buf)) { perror ("VIDIOC_QUERYBUF"); /* free capture, and returns an error code */ @@ -1201,7 +1187,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_DQBUF, &buf)) { + if (-1 == ioctl (capture->deviceHandle, VIDIOC_DQBUF, &buf)) { switch (errno) { case EAGAIN: return 0; @@ -1209,7 +1195,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { case EIO: if (!(buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))) { - if (xioctl(capture->deviceHandle, VIDIOC_QBUF, &buf) == -1) + if (ioctl(capture->deviceHandle, VIDIOC_QBUF, &buf) == -1) { return 0; } @@ -1232,7 +1218,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { //printf("got data in buff %d, len=%d, flags=0x%X, seq=%d, used=%d)\n", // buf.index, buf.length, buf.flags, buf.sequence, buf.bytesused); - if (-1 == xioctl (capture->deviceHandle, VIDIOC_QBUF, &buf)) + if (-1 == ioctl (capture->deviceHandle, VIDIOC_QBUF, &buf)) perror ("VIDIOC_QBUF"); return 1; @@ -1308,7 +1294,7 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { buf.memory = V4L2_MEMORY_MMAP; buf.index = (unsigned long)capture->bufferIndex; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_QBUF, &buf)) { + if (-1 == ioctl (capture->deviceHandle, VIDIOC_QBUF, &buf)) { perror ("VIDIOC_QBUF"); return 0; } @@ -1316,7 +1302,7 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { /* enable the streaming */ capture->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_STREAMON, + if (-1 == ioctl (capture->deviceHandle, VIDIOC_STREAMON, &capture->type)) { /* error enabling the stream */ perror ("VIDIOC_STREAMON"); @@ -2301,7 +2287,7 @@ static double icvGetPropertyCAM_V4L (CvCaptureCAM_V4L* capture, CLEAR (capture->form); capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form)) { + if (-1 == ioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form)) { /* display an error message, and return an error code */ perror ("VIDIOC_G_FMT"); return -1; @@ -2342,7 +2328,7 @@ static double icvGetPropertyCAM_V4L (CvCaptureCAM_V4L* capture, return -1; } - if (-1 == xioctl (capture->deviceHandle, VIDIOC_G_CTRL, + if (-1 == ioctl (capture->deviceHandle, VIDIOC_G_CTRL, &capture->control)) { fprintf( stderr, "HIGHGUI ERROR: V4L2: "); @@ -2480,7 +2466,7 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { CLEAR (capture->cropcap); capture->cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (xioctl (capture->deviceHandle, VIDIOC_CROPCAP, &capture->cropcap) < 0) { + if (ioctl (capture->deviceHandle, VIDIOC_CROPCAP, &capture->cropcap) < 0) { fprintf(stderr, "HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP\n"); } else { @@ -2489,7 +2475,7 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { capture->crop.c= capture->cropcap.defrect; /* set the crop area, but don't exit if the device don't support croping */ - if (xioctl (capture->deviceHandle, VIDIOC_S_CROP, &capture->crop) < 0) { + if (ioctl (capture->deviceHandle, VIDIOC_S_CROP, &capture->crop) < 0) { fprintf(stderr, "HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP\n"); } } @@ -2498,7 +2484,7 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; /* read the current setting, mainly to retreive the pixelformat information */ - xioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form); + ioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form); /* set the values we want to change */ capture->form.fmt.pix.width = w; @@ -2513,7 +2499,7 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { * don't test if the set of the size is ok, because some device * don't allow changing the size, and we will get the real size * later */ - xioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form); + ioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form); /* try to set framerate to 30 fps */ struct v4l2_streamparm setfps; @@ -2521,14 +2507,14 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; setfps.parm.capture.timeperframe.numerator = 1; setfps.parm.capture.timeperframe.denominator = 30; - xioctl (capture->deviceHandle, VIDIOC_S_PARM, &setfps); + ioctl (capture->deviceHandle, VIDIOC_S_PARM, &setfps); /* we need to re-initialize some things, like buffers, because the size has * changed */ capture->FirstCapture = 1; /* Get window info again, to get the real value */ - if (-1 == xioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form)) + if (-1 == ioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form)) { fprintf(stderr, "HIGHGUI ERROR: V4L/V4L2: Could not obtain specifics of capture window.\n\n"); @@ -2628,7 +2614,7 @@ static int icvSetControl (CvCaptureCAM_V4L* capture, } /* get the min and max values */ - if (-1 == xioctl (capture->deviceHandle, + if (-1 == ioctl (capture->deviceHandle, VIDIOC_G_CTRL, &capture->control)) { // perror ("VIDIOC_G_CTRL for getting min/max values"); return -1; @@ -2698,7 +2684,7 @@ static int icvSetControl (CvCaptureCAM_V4L* capture, capture->control.value = (int)(value * (v4l2_max - v4l2_min) + v4l2_min); /* The driver may clamp the value or return ERANGE, ignored here */ - if (-1 == xioctl (capture->deviceHandle, + if (-1 == ioctl (capture->deviceHandle, VIDIOC_S_CTRL, &capture->control) && errno != ERANGE) { perror ("VIDIOC_S_CTRL"); return -1; From 287fb2c611e302659296be921bb22a2d20a747b1 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 29 Jan 2013 14:46:13 +0400 Subject: [PATCH 5/5] Fix build warning --- modules/highgui/src/cap_v4l.cpp | 159 ++++++++++++++++---------------- 1 file changed, 82 insertions(+), 77 deletions(-) diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index eacd744b12..fdbd120faa 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -1415,7 +1415,7 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { static inline void move_420_block(int yTL, int yTR, int yBL, int yBR, int u, int v, - int rowPixels, unsigned char * rgb) + int rowPixels, unsigned char * rgb) { const int rvScale = 91881; const int guScale = -22553; @@ -1454,7 +1454,7 @@ move_420_block(int yTL, int yTR, int yBL, int yBR, int u, int v, static inline void move_411_block(int yTL, int yTR, int yBL, int yBR, int u, int v, - int /*rowPixels*/, unsigned char * rgb) + int /*rowPixels*/, unsigned char * rgb) { const int rvScale = 91881; const int guScale = -22553; @@ -1546,6 +1546,7 @@ yuv420p_to_rgb24(int width, int height, // /* Converts from interlaced YUV420 to RGB24. */ /* [FD] untested... */ +#ifdef HAVE_CAMV4L static void yuv420_to_rgb24(int width, int height, unsigned char *pIn0, unsigned char *pOut0) @@ -1590,6 +1591,7 @@ yuv420_to_rgb24(int width, int height, pOut += width * bytes; } } +#endif //HAVE_CAMV4L // Consider a YUV411P image of 8x2 pixels. // @@ -1641,6 +1643,8 @@ yuv411p_to_rgb24(int width, int height, /* based on ccvt_yuyv_bgr32() from camstream */ #define SAT(c) \ if (c & (~255)) { if (c < 0) c = 0; else c = 255; } + +#ifdef HAVE_CAMV4L2 static void yuyv_to_rgb24 (int width, int height, unsigned char *src, unsigned char *dst) { @@ -1732,6 +1736,7 @@ uyvy_to_rgb24 (int width, int height, unsigned char *src, unsigned char *dst) } } } +#endif //HAVE_CAMV4L2 #ifdef HAVE_JPEG @@ -1758,6 +1763,7 @@ mjpeg_to_rgb24 (int width, int height, * */ +#ifdef HAVE_CAMV4L2 static void bayer2rgb24(long int WIDTH, long int HEIGHT, unsigned char *src, unsigned char *dst) { long int i; @@ -1919,7 +1925,6 @@ static void sgbrg2rgb24(long int WIDTH, long int HEIGHT, unsigned char *src, uns } } - #define CLAMP(x) ((x)<0?0:((x)>255)?255:(x)) typedef struct { @@ -2090,7 +2095,7 @@ static int sonix_decompress(int width, int height, unsigned char *inp, unsigned return 0; } - +#endif //HAVE_CAMV4L2 static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { @@ -2153,78 +2158,77 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { if (V4L2_SUPPORT == 1) { switch (capture->palette) - { - case PALETTE_BGR24: - memcpy((char *)capture->frame.imageData, - (char *)capture->buffers[capture->bufferIndex].start, - capture->frame.imageSize); - break; + { + case PALETTE_BGR24: + memcpy((char *)capture->frame.imageData, + (char *)capture->buffers[capture->bufferIndex].start, + capture->frame.imageSize); + break; - case PALETTE_YVU420: - yuv420p_to_rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)(capture->buffers[capture->bufferIndex].start), - (unsigned char*)capture->frame.imageData); - break; + case PALETTE_YVU420: + yuv420p_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)(capture->buffers[capture->bufferIndex].start), + (unsigned char*)capture->frame.imageData); + break; - case PALETTE_YUV411P: - yuv411p_to_rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)(capture->buffers[capture->bufferIndex].start), - (unsigned char*)capture->frame.imageData); - break; + case PALETTE_YUV411P: + yuv411p_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)(capture->buffers[capture->bufferIndex].start), + (unsigned char*)capture->frame.imageData); + break; #ifdef HAVE_JPEG - case PALETTE_MJPEG: - if (!mjpeg_to_rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)(capture->buffers[capture->bufferIndex] - .start), - capture->buffers[capture->bufferIndex].length, - (unsigned char*)capture->frame.imageData)) - return 0; - break; + case PALETTE_MJPEG: + if (!mjpeg_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)(capture->buffers[capture->bufferIndex] + .start), + capture->buffers[capture->bufferIndex].length, + (unsigned char*)capture->frame.imageData)) + return 0; + break; #endif - case PALETTE_YUYV: - yuyv_to_rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)(capture->buffers[capture->bufferIndex].start), - (unsigned char*)capture->frame.imageData); - break; - - case PALETTE_UYVY: - uyvy_to_rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)(capture->buffers[capture->bufferIndex].start), - (unsigned char*)capture->frame.imageData); - break; - case PALETTE_SBGGR8: - bayer2rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)capture->buffers[capture->bufferIndex].start, - (unsigned char*)capture->frame.imageData); - break; - - case PALETTE_SN9C10X: - sonix_decompress_init(); - sonix_decompress(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)capture->buffers[capture->bufferIndex].start, - (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start); - - bayer2rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start, - (unsigned char*)capture->frame.imageData); - break; - - case PALETTE_SGBRG: - sgbrg2rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start, - (unsigned char*)capture->frame.imageData); - break; - } + case PALETTE_YUYV: + yuyv_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)(capture->buffers[capture->bufferIndex].start), + (unsigned char*)capture->frame.imageData); + break; + case PALETTE_UYVY: + uyvy_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)(capture->buffers[capture->bufferIndex].start), + (unsigned char*)capture->frame.imageData); + break; + case PALETTE_SBGGR8: + bayer2rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)capture->buffers[capture->bufferIndex].start, + (unsigned char*)capture->frame.imageData); + break; + + case PALETTE_SN9C10X: + sonix_decompress_init(); + sonix_decompress(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)capture->buffers[capture->bufferIndex].start, + (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start); + + bayer2rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start, + (unsigned char*)capture->frame.imageData); + break; + + case PALETTE_SGBRG: + sgbrg2rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start, + (unsigned char*)capture->frame.imageData); + break; + } } #endif /* HAVE_CAMV4L2 */ #if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2) @@ -2233,31 +2237,32 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { #ifdef HAVE_CAMV4L { - switch(capture->imageProperties.palette) { - case VIDEO_PALETTE_RGB24: + switch(capture->imageProperties.palette) + { + case VIDEO_PALETTE_RGB24: memcpy((char *)capture->frame.imageData, (char *)(capture->memoryMap + capture->memoryBuffer.offsets[capture->bufferIndex]), capture->frame.imageSize); break; - case VIDEO_PALETTE_YUV420P: + case VIDEO_PALETTE_YUV420P: yuv420p_to_rgb24(capture->captureWindow.width, capture->captureWindow.height, (unsigned char*)(capture->memoryMap + capture->memoryBuffer.offsets[capture->bufferIndex]), (unsigned char*)capture->frame.imageData); break; - case VIDEO_PALETTE_YUV420: + case VIDEO_PALETTE_YUV420: yuv420_to_rgb24(capture->captureWindow.width, capture->captureWindow.height, (unsigned char*)(capture->memoryMap + capture->memoryBuffer.offsets[capture->bufferIndex]), (unsigned char*)capture->frame.imageData); break; - case VIDEO_PALETTE_YUV411P: + case VIDEO_PALETTE_YUV411P: yuv411p_to_rgb24(capture->captureWindow.width, capture->captureWindow.height, (unsigned char*)(capture->memoryMap + capture->memoryBuffer.offsets[capture->bufferIndex]), (unsigned char*)capture->frame.imageData); break; - default: + default: fprintf( stderr, "HIGHGUI ERROR: V4L: Cannot convert from palette %d to RGB\n", capture->imageProperties.palette);