27a148a
diff --git a/configure.ac b/configure.ac
27a148a
--- a/configure.ac
27a148a
+++ b/configure.ac
27a148a
@@ -179,20 +179,13 @@ AC_ARG_ENABLE([video],
27a148a
 with_video="no"
27a148a
 AS_IF([test "x$enable_video" != "xno"],
27a148a
   [AS_IF([test "x$win32" = "xno"],
27a148a
-    [AC_CHECK_HEADERS([linux/videodev.h], [with_video="v4l1"],
27a148a
-      [AC_MSG_FAILURE([test for video support failed!
27a148a
-rebuild your kernel to include video4linux support or
27a148a
-configure --disable-video to skip building video support.])])
27a148a
-       AC_CHECK_HEADERS([linux/videodev2.h], [with_video="v4l2"],
27a148a
+    [AC_CHECK_LIB([v4l2], [v4l2_open], [],
27a148a
          [AC_MSG_WARN([v4l2 API not detected, upgrade your kernel!])])],
27a148a
     [AC_CHECK_HEADERS([vfw.h], [with_video="vfw"],
27a148a
       [AC_MSG_FAILURE([test for VfW video support failed!
27a148a
 configure --disable-video to skip building vidoe support.])])])
27a148a
 ])
27a148a
 AM_CONDITIONAL([HAVE_VIDEO], [test "x$enable_video" != "xno"])
27a148a
-AM_CONDITIONAL([HAVE_V4L1],
27a148a
-  [test "x$with_video" = "xv4l1" || test "x$with_video" = "xv4l2"])
27a148a
-AM_CONDITIONAL([HAVE_V4L2], [test "x$with_video" = "xv4l2"])
27a148a
 
27a148a
 dnl X
27a148a
 AC_ARG_VAR([XSHM_LIBS], [linker flags for X shared memory extension])
27a148a
@@ -500,7 +493,7 @@ echo "please verify that the detected co
27a148a
 echo "------------------------------------------------------------------------"
27a148a
 echo "X                 --with-x=$have_x"
27a148a
 echo "pthreads          --enable-pthread=$enable_pthread"
27a148a
-echo "v4l               --enable-video=$enable_video"
27a148a
+echo "v4l2              --enable-video=$enable_video"
27a148a
 AS_IF([test "x$enable_video" != "xyes"],
27a148a
   [echo "        => zbarcam video scanner will *NOT* be built"])
27a148a
 echo "jpeg              --with-jpeg=$with_jpeg"
27a148a
diff --git a/zbar/Makefile.am.inc b/zbar/Makefile.am.inc
27a148a
--- a/zbar/Makefile.am.inc
27a148a
+++ b/zbar/Makefile.am.inc
27a148a
@@ -59,21 +59,17 @@ else
27a148a
 zbar_libzbar_la_SOURCES += zbar/processor/posix.h zbar/processor/posix.c
27a148a
 endif
27a148a
 
27a148a
-if HAVE_V4L1
27a148a
-zbar_libzbar_la_SOURCES += zbar/video/v4l1.c
27a148a
-if HAVE_V4L2
27a148a
-zbar_libzbar_la_SOURCES += zbar/video/v4l2.c
27a148a
-endif
27a148a
-endif
27a148a
+if HAVE_VIDEO
27a148a
 if WIN32
27a148a
-if HAVE_VIDEO
27a148a
 zbar_libzbar_la_SOURCES += zbar/video/vfw.c
27a148a
 zbar_libzbar_la_LIBADD += -lvfw32
27a148a
-endif
27a148a
-endif
27a148a
-if !HAVE_VIDEO
27a148a
+else
27a148a
+zbar_libzbar_la_SOURCES += zbar/video/v4l2.c
27a148a
+zbar_libzbar_la_LDFLAGS += -lv4l2
27a148a
+endif #WIN32
27a148a
+else
27a148a
 zbar_libzbar_la_SOURCES += zbar/video/null.c
27a148a
-endif
27a148a
+endif #HAVE_VIDEO
27a148a
 
27a148a
 if HAVE_JPEG
27a148a
 zbar_libzbar_la_SOURCES += zbar/jpeg.c
27a148a
diff --git a/zbar/video/v4l1.c b/zbar/video/v4l1.c
27a148a
deleted file mode 100644
27a148a
--- a/zbar/video/v4l1.c
27a148a
+++ /dev/null
27a148a
@@ -1,435 +0,0 @@
27a148a
-/*------------------------------------------------------------------------
27a148a
- *  Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net>
27a148a
- *
27a148a
- *  This file is part of the ZBar Bar Code Reader.
27a148a
- *
27a148a
- *  The ZBar Bar Code Reader is free software; you can redistribute it
27a148a
- *  and/or modify it under the terms of the GNU Lesser Public License as
27a148a
- *  published by the Free Software Foundation; either version 2.1 of
27a148a
- *  the License, or (at your option) any later version.
27a148a
- *
27a148a
- *  The ZBar Bar Code Reader is distributed in the hope that it will be
27a148a
- *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
27a148a
- *  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27a148a
- *  GNU Lesser Public License for more details.
27a148a
- *
27a148a
- *  You should have received a copy of the GNU Lesser Public License
27a148a
- *  along with the ZBar Bar Code Reader; if not, write to the Free
27a148a
- *  Software Foundation, Inc., 51 Franklin St, Fifth Floor,
27a148a
- *  Boston, MA  02110-1301  USA
27a148a
- *
27a148a
- *  http://sourceforge.net/projects/zbar
27a148a
- *------------------------------------------------------------------------*/
27a148a
-
27a148a
-#include <config.h>
27a148a
-#ifdef HAVE_INTTYPES_H
27a148a
-# include <inttypes.h>
27a148a
-#endif
27a148a
-#ifdef HAVE_STDLIB_H
27a148a
-# include <stdlib.h>
27a148a
-#endif
27a148a
-#include <string.h>
27a148a
-#include <sys/types.h>
27a148a
-#include <sys/stat.h>
27a148a
-#include <unistd.h>
27a148a
-#include <fcntl.h>
27a148a
-#include <errno.h>
27a148a
-#include <assert.h>
27a148a
-#ifdef HAVE_SYS_IOCTL_H
27a148a
-# include <sys/ioctl.h>
27a148a
-#endif
27a148a
-#ifdef HAVE_SYS_MMAN_H
27a148a
-# include <sys/mman.h>
27a148a
-#endif
27a148a
-#include <linux/videodev.h>
27a148a
-
27a148a
-#include "video.h"
27a148a
-#include "image.h"
27a148a
-
27a148a
-extern int _zbar_v4l2_probe(zbar_video_t*);
27a148a
-
27a148a
-typedef struct v4l1_format_s {
27a148a
-    uint32_t format;
27a148a
-    uint8_t bpp;
27a148a
-} v4l1_format_t;
27a148a
-
27a148a
-/* static v4l1 "palette" mappings
27a148a
- * documentation for v4l1 formats is terrible...
27a148a
- */
27a148a
-static const v4l1_format_t v4l1_formats[17] = {
27a148a
-    /* format                   bpp */
27a148a
-    { 0,                         0 },
27a148a
-    { fourcc('G','R','E','Y'),   8 }, /* GREY */
27a148a
-    { fourcc('H','I','2','4'),   8 }, /* HI240 (BT848) */
27a148a
-
27a148a
-    /* component ordering for RGB palettes is unspecified,
27a148a
-     * convention appears to place red in the most significant bits
27a148a
-     * FIXME is this true for other drivers? big endian machines?
27a148a
-     */
27a148a
-    { fourcc('R','G','B','P'),  16 }, /* RGB565 */
27a148a
-    { fourcc('B','G','R','3'),  24 }, /* RGB24 */
27a148a
-    { fourcc('B','G','R','4'),  32 }, /* RGB32 */
27a148a
-    { fourcc('R','G','B','O'),  16 }, /* RGB555 */
27a148a
-    { fourcc('Y','U','Y','2'),  16 }, /* YUV422 (8 bpp?!) */
27a148a
-    { fourcc('Y','U','Y','V'),  16 }, /* YUYV */
27a148a
-    { fourcc('U','Y','V','Y'),  16 }, /* UYVY */
27a148a
-    { 0,                        12 }, /* YUV420 (24 bpp?) FIXME?! */
27a148a
-    { fourcc('Y','4','1','P'),  12 }, /* YUV411 */
27a148a
-    { 0,                         0 }, /* Bt848 raw */
27a148a
-    { fourcc('4','2','2','P'),  16 }, /* YUV422P (24 bpp?) */
27a148a
-    { fourcc('4','1','1','P'),  12 }, /* YUV411P */
27a148a
-    { fourcc('Y','U','1','2'),  12 }, /* YUV420P */
27a148a
-    { fourcc('Y','U','V','9'),   9 }, /* YUV410P */
27a148a
-};
27a148a
-
27a148a
-static int v4l1_nq (zbar_video_t *vdo,
27a148a
-                    zbar_image_t *img)
27a148a
-{
27a148a
-    if(video_nq_image(vdo, img))
27a148a
-        return(-1);
27a148a
-
27a148a
-    if(vdo->iomode != VIDEO_MMAP)
27a148a
-        return(0);
27a148a
-
27a148a
-    struct video_mmap vmap;
27a148a
-    vmap.frame = img->srcidx;
27a148a
-    vmap.width = vdo->width;
27a148a
-    vmap.height = vdo->height;
27a148a
-    vmap.format = vdo->palette;
27a148a
-    if(ioctl(vdo->fd, VIDIOCMCAPTURE, &vmap) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "initiating video capture (VIDIOCMCAPTURE)"));
27a148a
-
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-static zbar_image_t *v4l1_dq (zbar_video_t *vdo)
27a148a
-{
27a148a
-    video_iomode_t iomode = vdo->iomode;
27a148a
-    int fd = vdo->fd;
27a148a
-    zbar_image_t *img = video_dq_image(vdo);
27a148a
-    if(!img)
27a148a
-        return(NULL);
27a148a
-
27a148a
-    if(iomode == VIDEO_MMAP) {
27a148a
-        int frame = img->srcidx;
27a148a
-        if(ioctl(fd, VIDIOCSYNC, &frame) < 0)
27a148a
-            return(NULL);
27a148a
-    }
27a148a
-    else if(read(fd, (void*)img->data, img->datalen) != img->datalen)
27a148a
-        return(NULL);
27a148a
-
27a148a
-    return(img);
27a148a
-}
27a148a
-
27a148a
-static int v4l1_mmap_buffers (zbar_video_t *vdo)
27a148a
-{
27a148a
-#ifdef HAVE_SYS_MMAN_H
27a148a
-    /* map camera image to memory */
27a148a
-    struct video_mbuf vbuf;
27a148a
-    memset(&vbuf, 0, sizeof(vbuf));
27a148a
-    if(ioctl(vdo->fd, VIDIOCGMBUF, &vbuf) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "querying video frame buffers (VIDIOCGMBUF)"));
27a148a
-    assert(vbuf.frames && vbuf.size);
27a148a
-
27a148a
-    zprintf(1, "mapping %d buffers size=0x%x\n", vbuf.frames, vbuf.size);
27a148a
-    vdo->buflen = vbuf.size;
27a148a
-    vdo->buf = mmap(0, vbuf.size, PROT_READ | PROT_WRITE, MAP_SHARED,
27a148a
-                    vdo->fd, 0);
27a148a
-    if(vdo->buf == MAP_FAILED)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "mapping video frame buffers"));
27a148a
-
27a148a
-    int i;
27a148a
-    for(i = 0; i < vbuf.frames; i++) {
27a148a
-        zbar_image_t *img = vdo->images[i];
27a148a
-        zprintf(2, "    [%02d] @%08x\n", img->srcidx, vbuf.offsets[i]);
27a148a
-        img->data = vdo->buf + vbuf.offsets[i];
27a148a
-        img->datalen = vdo->datalen;
27a148a
-        int next_offset = ((i + 1 < vdo->num_images)
27a148a
-                           ? vbuf.offsets[i + 1]
27a148a
-                           : vbuf.size);
27a148a
-        if(next_offset < vbuf.offsets[i] + vdo->datalen)
27a148a
-            fprintf(stderr, "WARNING: insufficient v4l1 video buffer size:\n"
27a148a
-                    "\tvbuf[%d]=%x vbuf[%d]=%x datalen=%lx\n"
27a148a
-                    "\timage=%d x %d %.4s(%08x) palette=%d\n",
27a148a
-                    i, vbuf.offsets[i], i + 1, next_offset,
27a148a
-                    vdo->datalen, vdo->width, vdo->height,
27a148a
-                    (char*)&vdo->format, vdo->format, vdo->palette);
27a148a
-    }
27a148a
-    return(0);
27a148a
-#else
27a148a
-    return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_UNSUPPORTED, __func__,
27a148a
-                       "memory mapping not supported"));
27a148a
-#endif
27a148a
-}
27a148a
-
27a148a
-static int v4l1_start (zbar_video_t *vdo)
27a148a
-{
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-static int v4l1_stop (zbar_video_t *vdo)
27a148a
-{
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-static inline int v4l1_set_format (zbar_video_t *vdo,
27a148a
-                                   uint32_t fmt)
27a148a
-{
27a148a
-    struct video_picture vpic;
27a148a
-    memset(&vpic, 0, sizeof(vpic));
27a148a
-    if(ioctl(vdo->fd, VIDIOCGPICT, &vpic) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "querying video format (VIDIOCGPICT)"));
27a148a
-
27a148a
-    vdo->palette = 0;
27a148a
-    int ifmt;
27a148a
-    for(ifmt = 1; ifmt <= VIDEO_PALETTE_YUV410P; ifmt++)
27a148a
-        if(v4l1_formats[ifmt].format == fmt)
27a148a
-            break;
27a148a
-    if(!fmt || ifmt >= VIDEO_PALETTE_YUV410P)
27a148a
-        return(err_capture_int(vdo, SEV_ERROR, ZBAR_ERR_INVALID, __func__,
27a148a
-                               "invalid v4l1 format: %x", fmt));
27a148a
-
27a148a
-    vpic.palette = ifmt;
27a148a
-    vpic.depth = v4l1_formats[ifmt].bpp;
27a148a
-    if(ioctl(vdo->fd, VIDIOCSPICT, &vpic) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "setting format (VIDIOCSPICT)"));
27a148a
-
27a148a
-    memset(&vpic, 0, sizeof(vpic));
27a148a
-    if(ioctl(vdo->fd, VIDIOCGPICT, &vpic) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "querying video format (VIDIOCGPICT)"));
27a148a
-
27a148a
-    if(vpic.palette != ifmt || vpic.depth != v4l1_formats[ifmt].bpp) {
27a148a
-        fprintf(stderr,
27a148a
-                "WARNING: set v4l1 palette %d which should have depth %d bpp\n"
27a148a
-                "    but probed palette %d with depth %d bpp?"
27a148a
-                "  ...continuing anyway\n",
27a148a
-                ifmt, v4l1_formats[ifmt].bpp, vpic.palette, vpic.depth);
27a148a
-        err_capture_int(vdo, SEV_WARNING, ZBAR_ERR_INVALID, __func__,
27a148a
-                        "driver format (%x) inconsistency", fmt);
27a148a
-    }
27a148a
-    vdo->format = fmt;
27a148a
-    vdo->palette = ifmt;
27a148a
-    vdo->datalen = (vdo->width * vdo->height * v4l1_formats[ifmt].bpp + 7) >> 3;
27a148a
-
27a148a
-    zprintf(1, "set new format: %.4s(%08x) depth=%d palette=%d size=0x%lx\n",
27a148a
-            (char*)&vdo->format, vdo->format, vpic.depth, vdo->palette,
27a148a
-            vdo->datalen);
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-static int v4l1_init (zbar_video_t *vdo,
27a148a
-                      uint32_t fmt)
27a148a
-{
27a148a
-    if(v4l1_set_format(vdo, fmt))
27a148a
-        return(-1);
27a148a
-    if(vdo->iomode == VIDEO_MMAP && v4l1_mmap_buffers(vdo))
27a148a
-        return(-1);
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-static int v4l1_cleanup (zbar_video_t *vdo)
27a148a
-{
27a148a
-#ifdef HAVE_SYS_MMAN_H
27a148a
-    /* FIXME should avoid holding onto mmap'd buffers so long? */
27a148a
-    if(vdo->iomode == VIDEO_MMAP && vdo->buf) {
27a148a
-        if(munmap(vdo->buf, vdo->buflen))
27a148a
-            return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                               "unmapping video frame buffers"));
27a148a
-        vdo->buf = NULL;
27a148a
-        /* FIXME reset image */
27a148a
-    }
27a148a
-#endif
27a148a
-
27a148a
-    /* close open device */
27a148a
-    if(vdo->fd >= 0) {
27a148a
-        close(vdo->fd);
27a148a
-        vdo->fd = -1;
27a148a
-    }
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-static int v4l1_probe_iomode (zbar_video_t *vdo)
27a148a
-{
27a148a
-    vdo->iomode = VIDEO_READWRITE;
27a148a
-#ifdef HAVE_SYS_MMAN_H
27a148a
-    struct video_mbuf vbuf;
27a148a
-    memset(&vbuf, 0, sizeof(vbuf));
27a148a
-    if(ioctl(vdo->fd, VIDIOCGMBUF, &vbuf) < 0) {
27a148a
-        if(errno != EINVAL)
27a148a
-            return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                               "querying video frame buffers (VIDIOCGMBUF)"));
27a148a
-        /* not supported */
27a148a
-        return(0);
27a148a
-    }
27a148a
-    if(!vbuf.frames || !vbuf.size)
27a148a
-        return(0);
27a148a
-    vdo->iomode = VIDEO_MMAP;
27a148a
-    if(vdo->num_images > vbuf.frames)
27a148a
-        vdo->num_images = vbuf.frames;
27a148a
-#endif
27a148a
-    zprintf(1, "using %d images in %s mode\n", vdo->num_images,
27a148a
-            (vdo->iomode == VIDEO_READWRITE) ? "READ" : "MMAP");
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-static inline int v4l1_probe_formats (zbar_video_t *vdo)
27a148a
-{
27a148a
-    struct video_picture vpic;
27a148a
-    memset(&vpic, 0, sizeof(vpic));
27a148a
-    if(ioctl(vdo->fd, VIDIOCGPICT, &vpic) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "querying format (VIDIOCGPICT)"));
27a148a
-
27a148a
-    vdo->format = 0;
27a148a
-    if(vpic.palette <= VIDEO_PALETTE_YUV410P)
27a148a
-        vdo->format = v4l1_formats[vpic.palette].format;
27a148a
-
27a148a
-    zprintf(1, "current format: %.4s(%08x) depth=%d palette=%d\n",
27a148a
-            (char*)&vdo->format, vdo->format, vpic.depth, vpic.palette);
27a148a
-
27a148a
-    vdo->formats = calloc(16, sizeof(uint32_t));
27a148a
-    if(!vdo->formats)
27a148a
-        return(err_capture(vdo, SEV_FATAL, ZBAR_ERR_NOMEM, __func__,
27a148a
-                           "allocating format list"));
27a148a
-
27a148a
-    int num_formats = 0;
27a148a
-    zprintf(2, "probing supported formats:\n");
27a148a
-    int i;
27a148a
-    for(i = 1; i <= VIDEO_PALETTE_YUV410P; i++) {
27a148a
-        if(!v4l1_formats[i].format)
27a148a
-            continue;
27a148a
-        vpic.depth = v4l1_formats[i].bpp;
27a148a
-        vpic.palette = i;
27a148a
-        if(ioctl(vdo->fd, VIDIOCSPICT, &vpic) < 0) {
27a148a
-            zprintf(2, "    [%02d] %.4s...no (set fails)\n",
27a148a
-                    i, (char*)&v4l1_formats[i].format);
27a148a
-            continue;
27a148a
-        }
27a148a
-        if(ioctl(vdo->fd, VIDIOCGPICT, &vpic) < 0 ||
27a148a
-           vpic.palette != i) {
27a148a
-            zprintf(2, "    [%02d] %.4s...no (set ignored)\n",
27a148a
-                    i, (char*)&v4l1_formats[i].format);
27a148a
-            continue;
27a148a
-        }
27a148a
-        zprintf(2, "    [%02d] %.4s...yes\n",
27a148a
-                i, (char*)&v4l1_formats[i].format);
27a148a
-        vdo->formats[num_formats++] = v4l1_formats[i].format;
27a148a
-    }
27a148a
-    vdo->formats = realloc(vdo->formats, (num_formats + 1) * sizeof(uint32_t));
27a148a
-    assert(vdo->formats);
27a148a
-
27a148a
-    return(v4l1_set_format(vdo, vdo->format));
27a148a
-}
27a148a
-
27a148a
-static inline int v4l1_init_window (zbar_video_t *vdo)
27a148a
-{
27a148a
-    struct video_window vwin;
27a148a
-    memset(&vwin, 0, sizeof(vwin));
27a148a
-    if(ioctl(vdo->fd, VIDIOCGWIN, &vwin) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "querying video window settings (VIDIOCGWIN)"));
27a148a
-
27a148a
-    zprintf(1, "current window: %d x %d @(%d, %d)%s\n",
27a148a
-            vwin.width, vwin.height, vwin.x, vwin.y,
27a148a
-            (vwin.flags & 1) ? " INTERLACE" : "");
27a148a
-
27a148a
-    if(vwin.width == vdo->width && vwin.height == vdo->height)
27a148a
-        /* max window already set */
27a148a
-        return(0);
27a148a
-
27a148a
-    struct video_window maxwin;
27a148a
-    memcpy(&maxwin, &vwin, sizeof(maxwin));
27a148a
-    maxwin.width = vdo->width;
27a148a
-    maxwin.height = vdo->height;
27a148a
-
27a148a
-    zprintf(1, "setting max win: %d x %d @(%d, %d)%s\n",
27a148a
-            maxwin.width, maxwin.height, maxwin.x, maxwin.y,
27a148a
-            (maxwin.flags & 1) ? " INTERLACE" : "");
27a148a
-    if(ioctl(vdo->fd, VIDIOCSWIN, &maxwin) < 0) {
27a148a
-        zprintf(1, "set FAILED...trying to recover original window\n");
27a148a
-        /* ignore errors (driver broken anyway) */
27a148a
-        ioctl(vdo->fd, VIDIOCSWIN, &vwin);
27a148a
-    }
27a148a
-
27a148a
-    /* re-query resulting parameters */
27a148a
-    memset(&vwin, 0, sizeof(vwin));
27a148a
-    if(ioctl(vdo->fd, VIDIOCGWIN, &vwin) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                           "querying video window settings (VIDIOCGWIN)"));
27a148a
-
27a148a
-    zprintf(1, "    final window: %d x %d @(%d, %d)%s\n",
27a148a
-            vwin.width, vwin.height, vwin.x, vwin.y,
27a148a
-            (vwin.flags & 1) ? " INTERLACE" : "");
27a148a
-    vdo->width = vwin.width;
27a148a
-    vdo->height = vwin.height;
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-static int _zbar_v4l1_probe (zbar_video_t *vdo)
27a148a
-{
27a148a
-    /* check capabilities */
27a148a
-    struct video_capability vcap;
27a148a
-    memset(&vcap, 0, sizeof(vcap));
27a148a
-    if(ioctl(vdo->fd, VIDIOCGCAP, &vcap) < 0)
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_UNSUPPORTED, __func__,
27a148a
-                           "video4linux version 1 not supported (VIDIOCGCAP)"));
27a148a
-
27a148a
-    zprintf(1, "%s (%sCAPTURE) (%d x %d) - (%d x %d)\n",
27a148a
-            vcap.name, (vcap.type & VID_TYPE_CAPTURE) ? "" : "*NO* ",
27a148a
-            vcap.minwidth, vcap.minheight, vcap.maxwidth, vcap.maxheight);
27a148a
-
27a148a
-    if(!(vcap.type & VID_TYPE_CAPTURE))
27a148a
-        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_UNSUPPORTED, __func__,
27a148a
-                           "v4l1 device does not support CAPTURE"));
27a148a
-
27a148a
-    if(!vdo->width || !vdo->height) {
27a148a
-        vdo->width = vcap.maxwidth;
27a148a
-        vdo->height = vcap.maxheight;
27a148a
-    }
27a148a
-
27a148a
-    if(v4l1_init_window(vdo) ||
27a148a
-       v4l1_probe_formats(vdo) ||
27a148a
-       v4l1_probe_iomode(vdo))
27a148a
-        return(-1);
27a148a
-
27a148a
-    vdo->intf = VIDEO_V4L1;
27a148a
-    vdo->init = v4l1_init;
27a148a
-    vdo->cleanup = v4l1_cleanup;
27a148a
-    vdo->start = v4l1_start;
27a148a
-    vdo->stop = v4l1_stop;
27a148a
-    vdo->nq = v4l1_nq;
27a148a
-    vdo->dq = v4l1_dq;
27a148a
-    return(0);
27a148a
-}
27a148a
-
27a148a
-int _zbar_video_open (zbar_video_t *vdo,
27a148a
-                      const char *dev)
27a148a
-{
27a148a
-    vdo->fd = open(dev, O_RDWR);
27a148a
-    if(vdo->fd < 0)
27a148a
-        return(err_capture_str(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
-                               "opening video device '%s'", dev));
27a148a
-    zprintf(1, "opened camera device %s (fd=%d)\n", dev, vdo->fd);
27a148a
-
27a148a
-    int rc = -1;
27a148a
-#ifdef HAVE_LINUX_VIDEODEV2_H
27a148a
-    if(vdo->intf != VIDEO_V4L1)
27a148a
-        rc = _zbar_v4l2_probe(vdo);
27a148a
-    if(rc)
27a148a
-#else
27a148a
-    zprintf(1, "WARNING: not compiled with v4l2 support, trying v4l1\n");
27a148a
-#endif
27a148a
-        rc = _zbar_v4l1_probe(vdo);
27a148a
-
27a148a
-    if(rc && vdo->fd >= 0) {
27a148a
-        close(vdo->fd);
27a148a
-        vdo->fd = -1;
27a148a
-    }
27a148a
-    return(rc);
27a148a
-}
27a148a
diff --git a/zbar/video/v4l2.c b/zbar/video/v4l2.c
27a148a
--- a/zbar/video/v4l2.c
27a148a
+++ b/zbar/video/v4l2.c
27a148a
@@ -38,6 +38,8 @@
27a148a
 #ifdef HAVE_SYS_MMAN_H
27a148a
 # include <sys/mman.h>
27a148a
 #endif
27a148a
+#include <fcntl.h>
27a148a
+#include <libv4l2.h>
27a148a
 #include <linux/videodev2.h>
27a148a
 
27a148a
 #include "video.h"
27a148a
@@ -67,7 +69,7 @@ static int v4l2_nq (zbar_video_t *vdo,
27a148a
         vbuf.length = img->datalen;
27a148a
         vbuf.index = img->srcidx; /* FIXME workaround broken drivers */
27a148a
     }
27a148a
-    if(ioctl(vdo->fd, VIDIOC_QBUF, &vbuf) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_QBUF, &vbuf) < 0)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "queuing video buffer (VIDIOC_QBUF)"));
27a148a
     return(0);
27a148a
@@ -91,7 +93,7 @@ static zbar_image_t *v4l2_dq (zbar_video
27a148a
         else
27a148a
             vbuf.memory = V4L2_MEMORY_USERPTR;
27a148a
 
27a148a
-        if(ioctl(fd, VIDIOC_DQBUF, &vbuf) < 0)
27a148a
+        if(v4l2_ioctl(fd, VIDIOC_DQBUF, &vbuf) < 0)
27a148a
             return(NULL);
27a148a
 
27a148a
         if(iomode == VIDEO_MMAP) {
27a148a
@@ -132,7 +134,7 @@ static int v4l2_start (zbar_video_t *vdo
27a148a
         return(0);
27a148a
 
27a148a
     enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
-    if(ioctl(vdo->fd, VIDIOC_STREAMON, &type) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_STREAMON, &type) < 0)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "starting video stream (VIDIOC_STREAMON)"));
27a148a
     return(0);
27a148a
@@ -144,7 +146,7 @@ static int v4l2_stop (zbar_video_t *vdo)
27a148a
         return(0);
27a148a
 
27a148a
     enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
-    if(ioctl(vdo->fd, VIDIOC_STREAMOFF, &type) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_STREAMOFF, &type) < 0)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "stopping video stream (VIDIOC_STREAMOFF)"));
27a148a
     return(0);
27a148a
@@ -164,7 +166,7 @@ static int v4l2_cleanup (zbar_video_t *v
27a148a
         for(i = 0; i < vdo->num_images; i++) {
27a148a
             zbar_image_t *img = vdo->images[i];
27a148a
             if(img->data &&
27a148a
-               munmap((void*)img->data, img->datalen))
27a148a
+               v4l2_munmap((void*)img->data, img->datalen))
27a148a
                 err_capture(vdo, SEV_WARNING, ZBAR_ERR_SYSTEM, __func__,
27a148a
                             "unmapping video frame buffers");
27a148a
             img->data = NULL;
27a148a
@@ -177,27 +179,27 @@ static int v4l2_cleanup (zbar_video_t *v
27a148a
     /* requesting 0 buffers
27a148a
      * should implicitly disable streaming
27a148a
      */
27a148a
-    if(ioctl(vdo->fd, VIDIOC_REQBUFS, &rb) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_REQBUFS, &rb) < 0)
27a148a
         err_capture(vdo, SEV_WARNING, ZBAR_ERR_SYSTEM, __func__,
27a148a
                     "releasing video frame buffers (VIDIOC_REQBUFS)");
27a148a
 
27a148a
 
27a148a
-    /* close open device */
27a148a
+    /* v4l2_close v4l2_open device */
27a148a
     if(vdo->fd >= 0) {
27a148a
-        close(vdo->fd);
27a148a
+        v4l2_close(vdo->fd);
27a148a
         vdo->fd = -1;
27a148a
     }
27a148a
     return(0);
27a148a
 }
27a148a
 
27a148a
-static int v4l2_mmap_buffers (zbar_video_t *vdo)
27a148a
+static int v4l2_v4l2_mmap_buffers (zbar_video_t *vdo)
27a148a
 {
27a148a
     struct v4l2_requestbuffers rb;
27a148a
     memset(&rb, 0, sizeof(rb));
27a148a
     rb.count = vdo->num_images;
27a148a
     rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
     rb.memory = V4L2_MEMORY_MMAP;
27a148a
-    if(ioctl(vdo->fd, VIDIOC_REQBUFS, &rb) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_REQBUFS, &rb) < 0)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "requesting video frame buffers (VIDIOC_REQBUFS)"));
27a148a
     zprintf(1, "mapping %u buffers (of %d requested)\n",
27a148a
@@ -216,7 +218,7 @@ static int v4l2_mmap_buffers (zbar_video
27a148a
     int i;
27a148a
     for(i = 0; i < vdo->num_images; i++) {
27a148a
         vbuf.index = i;
27a148a
-        if(ioctl(vdo->fd, VIDIOC_QUERYBUF, &vbuf) < 0)
27a148a
+        if(v4l2_ioctl(vdo->fd, VIDIOC_QUERYBUF, &vbuf) < 0)
27a148a
             /* FIXME cleanup */
27a148a
             return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                                "querying video buffer (VIDIOC_QUERYBUF)"));
27a148a
@@ -229,7 +231,7 @@ static int v4l2_mmap_buffers (zbar_video
27a148a
 
27a148a
         zbar_image_t *img = vdo->images[i];
27a148a
         img->datalen = vbuf.length;
27a148a
-        img->data = mmap(NULL, vbuf.length, PROT_READ | PROT_WRITE, MAP_SHARED,
27a148a
+        img->data = v4l2_mmap(NULL, vbuf.length, PROT_READ | PROT_WRITE, MAP_SHARED,
27a148a
                          vdo->fd, vbuf.m.offset);
27a148a
         if(img->data == MAP_FAILED)
27a148a
             /* FIXME cleanup */
27a148a
@@ -253,7 +255,7 @@ static int v4l2_set_format (zbar_video_t
27a148a
     vpix->pixelformat = fmt;
27a148a
     vpix->field = V4L2_FIELD_NONE;
27a148a
     int rc = 0;
27a148a
-    if((rc = ioctl(vdo->fd, VIDIOC_S_FMT, &vfmt)) < 0) {
27a148a
+    if((rc = v4l2_ioctl(vdo->fd, VIDIOC_S_FMT, &vfmt)) < 0) {
27a148a
         /* several broken drivers return an error if we request
27a148a
          * no interlacing (NB v4l2 spec violation)
27a148a
          * ...try again with an interlaced request
27a148a
@@ -264,7 +266,7 @@ static int v4l2_set_format (zbar_video_t
27a148a
         /* FIXME this might be _ANY once we can de-interlace */
27a148a
         vpix->field = V4L2_FIELD_INTERLACED;
27a148a
 
27a148a
-        if(ioctl(vdo->fd, VIDIOC_S_FMT, &vfmt) < 0)
27a148a
+        if(v4l2_ioctl(vdo->fd, VIDIOC_S_FMT, &vfmt) < 0)
27a148a
             return(err_capture_int(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                                    "setting format %x (VIDIOC_S_FMT)", fmt));
27a148a
 
27a148a
@@ -276,7 +278,7 @@ static int v4l2_set_format (zbar_video_t
27a148a
     struct v4l2_pix_format *newpix = &newfmt.fmt.pix;
27a148a
     memset(&newfmt, 0, sizeof(newfmt));
27a148a
     newfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
-    if(ioctl(vdo->fd, VIDIOC_G_FMT, &newfmt) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_G_FMT, &newfmt) < 0)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "querying format (VIDIOC_G_FMT)"));
27a148a
 
27a148a
@@ -307,7 +309,7 @@ static int v4l2_init (zbar_video_t *vdo,
27a148a
     if(v4l2_set_format(vdo, fmt))
27a148a
         return(-1);
27a148a
     if(vdo->iomode == VIDEO_MMAP)
27a148a
-        return(v4l2_mmap_buffers(vdo));
27a148a
+        return(v4l2_v4l2_mmap_buffers(vdo));
27a148a
     return(0);
27a148a
 }
27a148a
 
27a148a
@@ -322,7 +324,7 @@ static int v4l2_probe_iomode (zbar_video
27a148a
     else
27a148a
         rb.memory = V4L2_MEMORY_USERPTR;
27a148a
 
27a148a
-    if(ioctl(vdo->fd, VIDIOC_REQBUFS, &rb) < 0) {
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_REQBUFS, &rb) < 0) {
27a148a
         if(vdo->iomode)
27a148a
             return(err_capture_int(vdo, SEV_ERROR, ZBAR_ERR_INVALID, __func__,
27a148a
                                    "unsupported iomode requested (%d)",
27a148a
@@ -350,7 +352,7 @@ static inline int v4l2_probe_formats (zb
27a148a
     memset(&desc, 0, sizeof(desc));
27a148a
     desc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
     for(desc.index = 0; desc.index < V4L2_FORMATS_MAX; desc.index++) {
27a148a
-        if(ioctl(vdo->fd, VIDIOC_ENUM_FMT, &desc) < 0)
27a148a
+        if(v4l2_ioctl(vdo->fd, VIDIOC_ENUM_FMT, &desc) < 0)
27a148a
             break;
27a148a
         zprintf(2, "    [%d] %.4s : %s%s\n",
27a148a
                 desc.index, (char*)&desc.pixelformat, desc.description,
27a148a
@@ -368,7 +370,7 @@ static inline int v4l2_probe_formats (zb
27a148a
     struct v4l2_pix_format *pix = &fmt.fmt.pix;
27a148a
     memset(&fmt, 0, sizeof(fmt));
27a148a
     fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
-    if(ioctl(vdo->fd, VIDIOC_G_FMT, &fmt) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_G_FMT, &fmt) < 0)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "querying current video format (VIDIO_G_FMT)"));
27a148a
 
27a148a
@@ -390,15 +392,15 @@ static inline int v4l2_probe_formats (zb
27a148a
     maxpix->height = vdo->height;
27a148a
 
27a148a
     zprintf(1, "setting requested size: %d x %d\n", vdo->width, vdo->height);
27a148a
-    if(ioctl(vdo->fd, VIDIOC_S_FMT, &maxfmt) < 0) {
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_S_FMT, &maxfmt) < 0) {
27a148a
         zprintf(1, "set FAILED...trying to recover original format\n");
27a148a
         /* ignore errors (driver broken anyway) */
27a148a
-        ioctl(vdo->fd, VIDIOC_S_FMT, &fmt);
27a148a
+        v4l2_ioctl(vdo->fd, VIDIOC_S_FMT, &fmt);
27a148a
     }
27a148a
 
27a148a
     memset(&fmt, 0, sizeof(fmt));
27a148a
     fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
-    if(ioctl(vdo->fd, VIDIOC_G_FMT, &fmt) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_G_FMT, &fmt) < 0)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "querying current video format (VIDIOC_G_FMT)"));
27a148a
 
27a148a
@@ -420,7 +422,7 @@ static inline int v4l2_reset_crop (zbar_
27a148a
     struct v4l2_cropcap ccap;
27a148a
     memset(&ccap, 0, sizeof(ccap));
27a148a
     ccap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
-    if(ioctl(vdo->fd, VIDIOC_CROPCAP, &ccap) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_CROPCAP, &ccap) < 0)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "querying crop support (VIDIOC_CROPCAP)"));
27a148a
 
27a148a
@@ -442,7 +444,7 @@ static inline int v4l2_reset_crop (zbar_
27a148a
     memset(&crop, 0, sizeof(crop));
27a148a
     crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
27a148a
     crop.c = ccap.defrect;
27a148a
-    if(ioctl(vdo->fd, VIDIOC_S_CROP, &crop) < 0 && errno != EINVAL)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_S_CROP, &crop) < 0 && errno != EINVAL)
27a148a
         return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
                            "setting default crop window (VIDIOC_S_CROP)"));
27a148a
     return(0);
27a148a
@@ -453,7 +455,7 @@ int _zbar_v4l2_probe (zbar_video_t *vdo)
27a148a
     /* check capabilities */
27a148a
     struct v4l2_capability vcap;
27a148a
     memset(&vcap, 0, sizeof(vcap));
27a148a
-    if(ioctl(vdo->fd, VIDIOC_QUERYCAP, &vcap) < 0)
27a148a
+    if(v4l2_ioctl(vdo->fd, VIDIOC_QUERYCAP, &vcap) < 0)
27a148a
         return(err_capture(vdo, SEV_WARNING, ZBAR_ERR_UNSUPPORTED, __func__,
27a148a
                            "video4linux version 2 not supported (VIDIOC_QUERYCAP)"));
27a148a
 
27a148a
@@ -507,3 +509,21 @@ int _zbar_v4l2_probe (zbar_video_t *vdo)
27a148a
     vdo->dq = v4l2_dq;
27a148a
     return(0);
27a148a
 }
27a148a
+
27a148a
+int _zbar_video_open (zbar_video_t *vdo,
27a148a
+                      const char *dev)
27a148a
+{
27a148a
+    vdo->fd = v4l2_open(dev, O_RDWR);
27a148a
+    if(vdo->fd < 0)
27a148a
+        return(err_capture_str(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
27a148a
+                               "opening video device '%s'", dev));
27a148a
+    zprintf(1, "opened camera device %s (fd=%d)\n", dev, vdo->fd);
27a148a
+
27a148a
+    int rc = _zbar_v4l2_probe(vdo);
27a148a
+
27a148a
+    if(rc && vdo->fd >= 0) {
27a148a
+        v4l2_close(vdo->fd);
27a148a
+        vdo->fd = -1;
27a148a
+    }
27a148a
+    return(rc);
27a148a
+}
27a148a
diff --git a/zbarcam/Makefile.am.inc b/zbarcam/Makefile.am.inc
27a148a
--- a/zbarcam/Makefile.am.inc
27a148a
+++ b/zbarcam/Makefile.am.inc
27a148a
@@ -7,4 +7,6 @@ CLEANFILES += zbarcam/.libs/zbarcam
27a148a
 if WIN32
27a148a
 zbarcam_zbarcam_SOURCES += zbarcam/zbarcam.rc
27a148a
 zbarcam_zbarcam_LDADD += zbarcam/zbarcam-rc.o
27a148a
+else
27a148a
+zbarcam_zbarcam_LDADD += -lv4l2
27a148a
 endif