[Sumover-dev] [svn commit] r4309 - in vic/branches/mpeg4: video

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Tue Nov 11 11:32:17 GMT 2008


Author: douglask
Date: Tue Nov 11 11:32:10 2008
New Revision: 4309

Modified:
   vic/branches/mpeg4/configure
   vic/branches/mpeg4/configure.in
   vic/branches/mpeg4/video/grabber-v4l2.cpp
   vic/branches/mpeg4/video/grabber-video4linux.cpp

Log:
Initial libv4l support

Tidied up grabber-video4linux.cpp a little


Modified: vic/branches/mpeg4/configure
==============================================================================
--- vic/branches/mpeg4/configure	(original)
+++ vic/branches/mpeg4/configure	Tue Nov 11 11:32:10 2008
@@ -6426,8 +6426,141 @@
                 V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2-old.o"
 		echo "Using old Linux grabber-v4l2"
 elif test -r /usr/include/linux/videodev.h ; then
+        if test "${ac_cv_header_libv4lconvert_h+set}" = set; then
+  { echo "$as_me:$LINENO: checking for libv4lconvert.h" >&5
+echo $ECHO_N "checking for libv4lconvert.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_libv4lconvert_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_libv4lconvert_h" >&5
+echo "${ECHO_T}$ac_cv_header_libv4lconvert_h" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking libv4lconvert.h usability" >&5
+echo $ECHO_N "checking libv4lconvert.h usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <libv4lconvert.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking libv4lconvert.h presence" >&5
+echo $ECHO_N "checking libv4lconvert.h presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <libv4lconvert.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: libv4lconvert.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: libv4lconvert.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: libv4lconvert.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: libv4lconvert.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: libv4lconvert.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: libv4lconvert.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: libv4lconvert.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: libv4lconvert.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: libv4lconvert.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: libv4lconvert.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: libv4lconvert.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: libv4lconvert.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: libv4lconvert.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: libv4lconvert.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: libv4lconvert.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: libv4lconvert.h: in the future, the compiler will take precedence" >&2;}
+
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for libv4lconvert.h" >&5
+echo $ECHO_N "checking for libv4lconvert.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_libv4lconvert_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header_libv4lconvert_h=$ac_header_preproc
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_libv4lconvert_h" >&5
+echo "${ECHO_T}$ac_cv_header_libv4lconvert_h" >&6; }
+
+fi
+if test $ac_cv_header_libv4lconvert_h = yes; then
+  V_DEFINE="$V_DEFINE -DHAVE_LIBV4L"
+         V_LIB_GRABBER="$V_LIB_GRABBER -lv4l1 -lv4l2"
+else
+  $V_OBJ_GRABBER="$V_OBJ_GRABBER  video/tinyjpeg.o video/jidctflt.o"
+fi
+
+
         if test -r /usr/include/linux/videodev2.h  ; then
-                V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2.o video/tinyjpeg.o video/jidctflt.o video/grabber-video4linux.o"
+                V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2.o video/grabber-video4linux.o"
 		echo "Using Linux Grabbers: Video4Linux2 and Video4Linux1"
         else
                 V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-video4linux.o"

Modified: vic/branches/mpeg4/configure.in
==============================================================================
--- vic/branches/mpeg4/configure.in	(original)
+++ vic/branches/mpeg4/configure.in	Tue Nov 11 11:32:10 2008
@@ -301,8 +301,12 @@
                 V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2-old.o"
 		echo "Using old Linux grabber-v4l2"
 elif test -r /usr/include/linux/videodev.h ; then
+        AC_CHECK_HEADER(libv4lconvert.h,
+        [V_DEFINE="$V_DEFINE -DHAVE_LIBV4L"
+         V_LIB_GRABBER="$V_LIB_GRABBER -lv4l1 -lv4l2"],
+        [$V_OBJ_GRABBER="$V_OBJ_GRABBER  video/tinyjpeg.o video/jidctflt.o"])
         if test -r /usr/include/linux/videodev2.h  ; then
-                V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2.o video/tinyjpeg.o video/jidctflt.o video/grabber-video4linux.o"
+                V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2.o video/grabber-video4linux.o"
 		echo "Using Linux Grabbers: Video4Linux2 and Video4Linux1"
         else
                 V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-video4linux.o"

Modified: vic/branches/mpeg4/video/grabber-v4l2.cpp
==============================================================================
--- vic/branches/mpeg4/video/grabber-v4l2.cpp	(original)
+++ vic/branches/mpeg4/video/grabber-v4l2.cpp	Tue Nov 11 11:32:10 2008
@@ -46,19 +46,28 @@
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
 
-
 extern "C"
 {
 #include <asm/types.h>
 #include <linux/videodev2.h>
 }
 
-//#include "videodev2.h"
+#ifdef HAVE_LIBV4L
+#include <libv4l2.h>
+#else
+#define v4l2_open open
+#define v4l2_close close
+#define v4l2_ioctl ioctl
+#define v4l2_read read
+#define v4l2_mmap mmap
+#define v4l2_munmap munmap
+#include "tinyjpeg.h"
+#endif
+
 #include "grabber.h"
 #include "vic_tcl.h"
 #include "device-input.h"
 #include "module.h"
-#include "tinyjpeg.h"
 
 /* here you can tune the device names */
 static const char *devlist[] = {
@@ -86,10 +95,18 @@
 #define BYTE_ORDER_VYUY 3
 
 /* V4L2 driver specific controls */
+#ifndef V4L2_CID_POWER_LINE_FREQUENCY
 #define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_PRIVATE_BASE + 1)
+#endif
+#ifndef V4L2_CID_FOCUS_AUTO
 #define V4L2_CID_FOCUS_AUTO           (V4L2_CID_PRIVATE_BASE + 4)
+#endif
+#ifndef V4L2_CID_FOCUS_ABSOLUTE
 #define V4L2_CID_FOCUS_ABSOLUTE       (V4L2_CID_PRIVATE_BASE + 5)
+#endif
+#ifndef V4L2_CID_FOCUS_RELATIVE
 #define V4L2_CID_FOCUS_RELATIVE       (V4L2_CID_PRIVATE_BASE + 6)
+#endif
 
 typedef struct tag_vimage
 {
@@ -118,7 +135,10 @@
 
         void packed422_to_planar422(char *, const char*);
         void packed422_to_planar420(char *, const char*);
+
+#ifndef HAVE_LIBV4L
         void jpeg_to_planar420(char *, const char*);
+#endif
 
         void setctrl(int, int, const char *, int);
 
@@ -143,6 +163,7 @@
         int have_YUV420P;
         int have_MJPEG;
         int have_JPEG;
+
         int byteorder_;
         int cformat_;
         int port_;
@@ -156,7 +177,9 @@
         int decimate_;
         int bytesused_;
 
+#ifndef HAVE_LIBV4L
         struct jdec_private *jpegdec_;
+#endif
 };
 
 /* ----------------------------------------------------------------- */
@@ -226,20 +249,27 @@
 
         for (i = 0; dev[i] != NULL; i++) {
                 debug_msg("V4L2: trying %s... ",dev[i]);
-                if (-1 == (fd = open(dev[i],O_RDWR))) {
+                if (-1 == (fd = v4l2_open(dev[i],O_RDWR))) {
                         debug_msg("Error opening: %s : %s\n", dev[i], strerror(errno));
                         continue;
                 }
+#ifdef HAVE_LIBV4L
+                if (-1 == v4l2_fd_open(fd,V4L2_ENABLE_ENUM_FMT_EMULATION)) {
+                        perror("V4L2: v4l2_fd_open V4L2_ENABLE_ENUM_FMT_EMULATION");
+                        v4l2_close(fd);
+                        continue;
+                }
+#endif
                 memset(&capability,0,sizeof(capability));
-                if (-1 == ioctl(fd,VIDIOC_QUERYCAP,&capability)) {
+                if (-1 == v4l2_ioctl(fd,VIDIOC_QUERYCAP,&capability)) {
                         perror("V4L2: ioctl VIDIOC_QUERYCAP");
-                        close(fd);
+                        v4l2_close(fd);
                         continue;
                 }
 
                 if (capability.capabilities & V4L2_CAP_VIDEO_CAPTURE == 0) {
                         debug_msg("%s, %s can't capture\n",capability.card,capability.bus_info);
-                        close(fd);
+                        v4l2_close(fd);
                         continue;
                 }
 
@@ -251,8 +281,8 @@
                 strcat(attr,"port { ");
                 //input.index = 0;
                 memset(&input, 0, sizeof(input));
-                while (-1 != ioctl (fd, VIDIOC_ENUMINPUT, &input)) {
-                        if (-1 == ioctl(fd,VIDIOC_S_INPUT,&input.index)) {
+                while (-1 != v4l2_ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
+                        if (-1 == v4l2_ioctl(fd,VIDIOC_S_INPUT,&input.index)) {
                                 debug_msg("ioctl VIDIOC_S_INPUT: %s", strerror(errno));
                         } else {
 
@@ -275,7 +305,7 @@
                         struct v4l2_standard     estd;
                         memset(&estd,0,sizeof(estd));
                         estd.index = k;
-                        err = ioctl(fd, VIDIOC_ENUMSTD, &estd);
+                        err = v4l2_ioctl(fd, VIDIOC_ENUMSTD, &estd);
                         if (!err) {
                                 strcat(attr, (const char*)estd.name);
                                 strcat(attr," ");
@@ -290,7 +320,7 @@
                 sprintf(nick,"V4L2-%s %s",capability.card, dev[i]);
                 new V4l2Device(dev[i],nick,attr);
                 fprintf(stderr, "Attached to V4L2 device: %s\n", nick);
-                close(fd);
+                v4l2_close(fd);
         }
 }
 
@@ -311,11 +341,13 @@
         have_MJPEG = 0;
         have_JPEG = 0;
 
+#ifndef HAVE_LIBV4L
         jpegdec_ = NULL;
+#endif
 
         struct v4l2_capability cap;
         memset(&cap,0,sizeof(cap));
-        if (-1 == ioctl(fd_,VIDIOC_QUERYCAP,&cap)) {
+        if (-1 == v4l2_ioctl(fd_,VIDIOC_QUERYCAP,&cap)) {
                 perror("ioctl VIDIOC_QUERYCAP");
         } else {
                 if ( !(cap.capabilities & V4L2_CAP_READWRITE) && !(cap.capabilities & V4L2_CAP_STREAMING)) {
@@ -327,12 +359,12 @@
 
         memset(&fmt,0,sizeof(fmt));
         fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-        ioctl(fd_, VIDIOC_G_FMT, &fmt);
+        v4l2_ioctl(fd_, VIDIOC_G_FMT, &fmt);
 
         fmt.fmt.pix.width = CIF_WIDTH;
         fmt.fmt.pix.height = CIF_HEIGHT;
         fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
-        if (-1 != ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
+        if (-1 != v4l2_ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
                 if (fmt.fmt.pix.height == CIF_HEIGHT) {
                         have_YUV420P = 1;
                         debug_msg("\nDevice supports V4L2_PIX_FMT_YUV420\n");
@@ -342,7 +374,7 @@
         fmt.fmt.pix.width = CIF_WIDTH;
         fmt.fmt.pix.height = CIF_HEIGHT;
         fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
-        if (-1 != ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
+        if (-1 != v4l2_ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
                 if (fmt.fmt.pix.height == CIF_HEIGHT) {
                         have_YUV422P = 1;
                         debug_msg("\nDevice supports V4L2_PIX_FMT_YUV422\n");
@@ -352,17 +384,18 @@
         fmt.fmt.pix.width = CIF_WIDTH;
         fmt.fmt.pix.height = CIF_HEIGHT;
         fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
-        if (-1 != ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
+        if (-1 != v4l2_ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
                 if (fmt.fmt.pix.height == CIF_HEIGHT) {
                         have_YUV422 = 1;
                         debug_msg("\nDevice supports V4L2_PIX_FMT_YUYV (YUV 4:2:2)\n");
                 }
         }
 
+#ifdef HAVE_LIBV4L
         fmt.fmt.pix.width = CIF_WIDTH;
         fmt.fmt.pix.height = CIF_HEIGHT;
         fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
-        if (-1 != ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
+        if (-1 != v4l2_ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
                 have_MJPEG = 1;
                 debug_msg("\nDevice supports V4L2_PIX_FMT_MJPEG\n");
         }
@@ -370,14 +403,15 @@
         fmt.fmt.pix.width = CIF_WIDTH;
         fmt.fmt.pix.height = CIF_HEIGHT;
         fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG;
-        if (-1 != ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
+        if (-1 != v4l2_ioctl(fd_, VIDIOC_S_FMT, &fmt) ) {
                 have_MJPEG = 1;
                 debug_msg("\nDevice supports V4L2_PIX_FMT_JPEG\n");
         }
+#endif
 
         if( !( have_YUV422P || have_YUV422 || have_YUV420P || have_MJPEG || have_JPEG)){
                 debug_msg("No suitable pixelformat found\n");
-                close(fd_);
+                v4l2_close(fd_);
                 status_=-1;
                 return;
         }
@@ -388,7 +422,7 @@
         reqbuf.memory = V4L2_MEMORY_MMAP;
         reqbuf.count = 20;
         have_mmap = 1;
-        if (-1 == ioctl (fd_, VIDIOC_REQBUFS, &reqbuf)) {
+        if (-1 == v4l2_ioctl(fd_, VIDIOC_REQBUFS, &reqbuf)) {
                 if (errno == EINVAL) {
                         printf("Video capturing or mmap-streaming is not supported\n");
                         have_mmap = 0;
@@ -423,8 +457,8 @@
         if (have_mmap) {
                 for (i = 0; i < STREAMBUFS; ++i) {
                         if (vimage[i].data)
-                                munmap(vimage[i].data,
-                                       vimage[i].vidbuf.length);
+                                v4l2_munmap(vimage[i].data,
+                                            vimage[i].vidbuf.length);
                         vimage[i].data = NULL;
                 }
         } else {
@@ -432,11 +466,13 @@
                         free(vimage[0].data);
                 vimage[0].data = NULL;
         }
-        close(fd_);
+        v4l2_close(fd_);
 
+#ifndef HAVE_LIBV4L
         if (jpegdec_) {
                 tinyjpeg_free(jpegdec_);
         }
+#endif
 
 }
 
@@ -469,7 +505,7 @@
                                 struct v4l2_input inp;
                                 memset(&inp,0,sizeof(inp));
                                 inp.index = i;
-                                err = ioctl(fd_, VIDIOC_ENUMINPUT, &inp);
+                                err = v4l2_ioctl(fd_, VIDIOC_ENUMINPUT, &inp);
                                 if (!err) {
 
                                         char input[32];
@@ -527,11 +563,11 @@
 
                         memset (&qctrl, 0, sizeof(qctrl));
                         qctrl.id = V4L2_CID_POWER_LINE_FREQUENCY;
-                        if (-1 != ioctl(fd_, VIDIOC_QUERYCTRL, &qctrl)) {
+                        if (-1 != v4l2_ioctl(fd_, VIDIOC_QUERYCTRL, &qctrl)) {
                                 if (strcmp((char *)qctrl.name, "Power Line Frequency") == 0) {
                                         ctrl.id = qctrl.id;
                                         ctrl.value = atoi(argv[2]);
-                                        if (-1 == ioctl(fd_, VIDIOC_S_CTRL, &ctrl))
+                                        if (-1 == v4l2_ioctl(fd_, VIDIOC_S_CTRL, &ctrl))
                                                 perror("ioctl  VIDIOC_S_CTRL");
                                         else
                                                 debug_msg( "V4L2: V4L2_CID_POWER_LINE_FREQUENCY = %d\n", ctrl.value);
@@ -571,7 +607,7 @@
                                 struct v4l2_standard     estd;
                                 memset(&estd,0,sizeof(estd));
                                 estd.index = k;
-                                if ( !(err = ioctl(fd_, VIDIOC_ENUMSTD, &estd)) )
+                                if ( !(err = v4l2_ioctl(fd_, VIDIOC_ENUMSTD, &estd)) )
                                         if ( strcasecmp(argv[2], (const char *)estd.name) == 0)
                                                 norm_ = k;
                         }
@@ -610,7 +646,7 @@
                         req.count = STREAMBUFS;
                         req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                         req.memory = V4L2_MEMORY_MMAP;
-                        err = ioctl(fd_, VIDIOC_REQBUFS, &req);
+                        err = v4l2_ioctl(fd_, VIDIOC_REQBUFS, &req);
                         if (err < 0 || req.count < 1) {
                                 debug_msg("REQBUFS returned error %d, count %d\n", errno,req.count);
                                 return;
@@ -620,12 +656,12 @@
                                 vimage[i].vidbuf.index = i;
                                 vimage[i].vidbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                                 vimage[i].vidbuf.memory = V4L2_MEMORY_MMAP;
-                                err = ioctl(fd_, VIDIOC_QUERYBUF, &vimage[i].vidbuf);
+                                err = v4l2_ioctl(fd_, VIDIOC_QUERYBUF, &vimage[i].vidbuf);
                                 if (err < 0) {
                                         debug_msg("QUERYBUF returned error %d\n",errno);
                                         return;
                                 }
-                                vimage[i].data = (typeof(vimage[0].data)) mmap(0,  vimage[i].vidbuf.length, PROT_READ|PROT_WRITE, MAP_SHARED, fd_, vimage[i].vidbuf.m.offset);
+                                vimage[i].data = (typeof(vimage[0].data)) v4l2_mmap(0,  vimage[i].vidbuf.length, PROT_READ|PROT_WRITE, MAP_SHARED, fd_, vimage[i].vidbuf.m.offset);
 
                                 if ((long)vimage[i].data == -1) {
                                         debug_msg("V4L2: mmap() returned error %l\n", errno);
@@ -634,12 +670,12 @@
                         }
 
                         for (i = 0; i < (int)req.count; ++i)
-                                if ((err = ioctl(fd_, VIDIOC_QBUF, &vimage[i].vidbuf))) {
+                                if ((err = v4l2_ioctl(fd_, VIDIOC_QBUF, &vimage[i].vidbuf))) {
                                         debug_msg("QBUF returned error %d\n",errno);
                                         return;
                                 }
 
-                        err = ioctl(fd_, VIDIOC_STREAMON, &vimage[0].vidbuf.type);
+                        err = v4l2_ioctl(fd_, VIDIOC_STREAMON, &vimage[0].vidbuf.type);
                         if (err)
                                 debug_msg("STREAMON returned error %d\n",errno);
 
@@ -665,12 +701,12 @@
         if (have_mmap) {
                 if ( fd_ > 0 ) {
                         i = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-                        if ( (err = ioctl(fd_, VIDIOC_STREAMOFF, &i) ) )
+                        if ( (err = v4l2_ioctl(fd_, VIDIOC_STREAMOFF, &i) ) )
                                 debug_msg("V4L2: VIDIOC_STREAMOFF failed\n");
                 }
 
                 tempbuf.type = vimage[0].vidbuf.type;
-                while ((err = ioctl(fd_, VIDIOC_DQBUF, &tempbuf)) < 0 &&
+                while ((err = v4l2_ioctl(fd_, VIDIOC_DQBUF, &tempbuf)) < 0 &&
                        (errno == EINTR));
 
                 if (err < 0) {
@@ -679,7 +715,7 @@
 
                 for (i = 0; i < STREAMBUFS; ++i) {
                         if (vimage[i].data)
-                                err = munmap(vimage[i].data, vimage[i].vidbuf.length);
+                                err = v4l2_munmap(vimage[i].data, vimage[i].vidbuf.length);
                         vimage[i].data = NULL;
                 }
 
@@ -715,7 +751,7 @@
                         memset(&tempbuf, 0, sizeof(struct v4l2_buffer));
                         tempbuf.type = vimage[0].vidbuf.type;
                         tempbuf.memory = vimage[0].vidbuf.memory;
-                        if (-1 == ioctl(fd_, VIDIOC_DQBUF, &tempbuf))
+                        if (-1 == v4l2_ioctl(fd_, VIDIOC_DQBUF, &tempbuf))
                                 perror("ioctl  VIDIOC_DQBUF");
 
                         if (  (req.count > 1) ) buf_sync++;
@@ -726,7 +762,7 @@
 
         } else {
                 fr = vimage[0].data;
-                read(fd_, vimage[0].data, fmt.fmt.pix.sizeimage);
+                v4l2_read(fd_, vimage[0].data, fmt.fmt.pix.sizeimage);
                 bytesused_ = fmt.fmt.pix.sizeimage;
         }
 
@@ -738,9 +774,11 @@
 ;
                 else if( have_YUV422 )
                        packed422_to_planar420((char*)frame_,fr);
+#ifndef HAVE_LIBV4L
                 else if( have_MJPEG || have_JPEG) {
                        jpeg_to_planar420((char*)frame_,fr);
                 }
+#endif
                 break;
 
         case CF_422:
@@ -748,13 +786,15 @@
                        memcpy((void *)frame_, (const void *)fr, (size_t)height_*width_*2);
                 else if( have_YUV422 )
                        packed422_to_planar422((char*)frame_,fr);
+#ifndef HAVE_LIBV4L
                 else if( have_MJPEG  || have_JPEG)
                        // jpeg_to_planar422((char*)frame_,fr);
+#endif
                 break;
         }
 
         if (have_mmap)
-                ioctl(fd_, VIDIOC_QBUF, &vimage[buf_sync%2].vidbuf);
+                v4l2_ioctl(fd_, VIDIOC_QBUF, &vimage[buf_sync%2].vidbuf);
 
         suppress(frame_);
         saveblks(frame_);
@@ -1009,6 +1049,7 @@
     }
 }
 
+#ifndef HAVE_LIBV4L
 void V4l2Grabber::jpeg_to_planar420(char *dest, const char *src)
 {
         char *y,*u,*v;
@@ -1039,7 +1080,7 @@
                return;
         }
 }
-
+#endif
 
 
 void V4l2Grabber::format()
@@ -1058,10 +1099,12 @@
                        pixelformat = V4L2_PIX_FMT_YUV420;
                 else if( have_YUV422 )
                        pixelformat = V4L2_PIX_FMT_YUYV;
+#ifndef HAVE_LIBV4L
                 else if( have_MJPEG )
                        pixelformat = V4L2_PIX_FMT_MJPEG;
                 else if( have_JPEG )
                        pixelformat = V4L2_PIX_FMT_JPEG;
+#endif
                 break;
 
         case CF_422:
@@ -1069,10 +1112,12 @@
                        pixelformat = V4L2_PIX_FMT_YUV422P;
                 else if( have_YUV422 )
                        pixelformat = V4L2_PIX_FMT_YUYV;
+#ifndef HAVE_LIBV4L
                 else if( have_MJPEG )
                        pixelformat = V4L2_PIX_FMT_MJPEG;
                 else if( have_JPEG )
                        pixelformat = V4L2_PIX_FMT_JPEG;
+#endif
                 break;
         }
 
@@ -1101,15 +1146,15 @@
 
                 memset(&standard,0,sizeof(standard));
                 standard.index = norm_;
-                err = ioctl(fd_, VIDIOC_ENUMSTD, &standard);
+                err = v4l2_ioctl(fd_, VIDIOC_ENUMSTD, &standard);
                 if (!err) {
-                        if (-1 == ioctl(fd_, VIDIOC_S_STD, &standard.id))
+                        if (-1 == v4l2_ioctl(fd_, VIDIOC_S_STD, &standard.id))
                                 perror("ioctl VIDIOC_S_STD");
                         else debug_msg("V4L2: setting norm to %s\n",standard.name);
                 }
 
                 input = port_;
-                if ((err = ioctl(fd_, VIDIOC_S_INPUT, &input)) )
+                if ((err = v4l2_ioctl(fd_, VIDIOC_S_INPUT, &input)) )
                         debug_msg("S_INPUT returned error %d\n",errno);
                 else debug_msg("V4L2: setting input port to %d\n", port_);
 
@@ -1118,19 +1163,19 @@
                         memset(&fmtd,0,sizeof(fmtd));
                         fmtd.index = i;
                         fmtd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-                        err = ioctl(fd_, VIDIOC_ENUM_FMT, &fmtd);
+                        err = v4l2_ioctl(fd_, VIDIOC_ENUM_FMT, &fmtd);
                         if (!err) {
 
                                 if (fmtd.pixelformat == pixelformat) {
                                         memset(&fmt,0,sizeof(fmt));
                                         fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-                                        ioctl(fd_, VIDIOC_G_FMT, &fmt);
+                                        v4l2_ioctl(fd_, VIDIOC_G_FMT, &fmt);
                                         fmt.fmt.pix.width = width_;
                                         fmt.fmt.pix.height = height_;
                                         fmt.fmt.pix.field = V4L2_FIELD_ANY;
                                         fmt.fmt.pix.pixelformat = pixelformat;
 
-                                        if ( (err = ioctl(fd_, VIDIOC_S_FMT, &fmt) ) )
+                                        if ( (err = v4l2_ioctl(fd_, VIDIOC_S_FMT, &fmt) ) )
                                                 debug_msg("\nV4L2: Failed to set format\n");
 
                                         if ( ( fmt.fmt.pix.width != (unsigned int)width_ ) ||
@@ -1180,7 +1225,7 @@
         struct v4l2_control ctrl;
 
         qctrl.id = cid;
-        if (-1 != ioctl(fd_, VIDIOC_QUERYCTRL, &qctrl)) {
+        if (-1 != v4l2_ioctl(fd_, VIDIOC_QUERYCTRL, &qctrl)) {
                 if ( !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED) ) {
 
                         ctrl.id = cid;
@@ -1188,7 +1233,7 @@
                                 ctrl.value = qctrl.default_value;
                         else
                                 ctrl.value = qctrl.minimum + (qctrl.maximum - qctrl.minimum) * val/256;
-                        if (-1 == ioctl(fd_, VIDIOC_S_CTRL,&ctrl))
+                        if (-1 == v4l2_ioctl(fd_, VIDIOC_S_CTRL,&ctrl))
                                 perror("ioctl  VIDIOC_S_CTRL");
                         else debug_msg( "V4L2: %s = %d\n", controlname, val);
                 }

Modified: vic/branches/mpeg4/video/grabber-video4linux.cpp
==============================================================================
--- vic/branches/mpeg4/video/grabber-video4linux.cpp	(original)
+++ vic/branches/mpeg4/video/grabber-video4linux.cpp	Tue Nov 11 11:32:10 2008
@@ -35,6 +35,16 @@
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
 
+#ifdef HAVE_LIBV4L
+#include <libv4l1.h>
+#else
+#define v4l1_open open
+#define v4l1_close close
+#define v4l1_ioctl ioctl
+#define v4l1_read read
+#define v4l1_mmap mmap
+#define v4l1_munmap munmap
+#endif
 
 extern "C"
 {
@@ -100,12 +110,9 @@
     void format();
     void setsize();
 
-    void packed422_to_planar422(char *, char *);
-    void packed422_to_planar411(char *, char *);
-    void vcvt_420p_422p(int width, int height, void *src, void *dst);
-    void vcvt_420p_411p(int width, int height, void *src, void *dst);
-    void vcvt_420i_yuyv(int width, int height, int plus, void *src,
-			void *dst);
+    void packed422_to_planar422(char *, const char *);
+    void packed422_to_planar420(char *, const char *);
+    void planar420_to_planar422(char *, const char *);
 
     struct video_capability capability;
     struct video_channel *channels;
@@ -217,19 +224,19 @@
 
     for (i = 0; dev[i] != NULL; i++) {
 	debug_msg("V4L: trying %s... ", dev[i]);
-	if (-1 == (fd = open(dev[i], O_RDONLY))) {
-	    debug_msg("Error opening: %s : %s\n", dev[i], strerror(errno));	//SV-XXX: sys_errlist deprecated, use strerror()
+	if (-1 == (fd = v4l1_open(dev[i], O_RDONLY))) {
+	    debug_msg("Error opening: %s : %s\n", dev[i], strerror(errno));
 	    continue;
 	}
-	if (-1 == ioctl(fd, VIDIOCGCAP, &capability)) {
+	if (-1 == v4l1_ioctl(fd, VIDIOCGCAP, &capability)) {
 	    perror("ioctl VIDIOCGCAP");
-	    close(fd);
+	    v4l1_close(fd);
 	    continue;
 	}
 
 	if (!(capability.type & VID_TYPE_CAPTURE)) {
 	    debug_msg("device can't capture\n");
-	    close(fd);
+	    v4l1_close(fd);
 	    continue;
 	}
 
@@ -254,15 +261,17 @@
 	debug_msg("V4L:   ports:");
 	strcat(attr, "port { ");
 
-	char attr_tmp[100]="";
+	char attr_tmp[256]="";
 	
 	for (j = 0; j < capability.channels; j++) {
 	    channel.channel = j;
-	    if (-1 == ioctl(fd, VIDIOCGCHAN, &channel)) {
+	    if (-1 == v4l1_ioctl(fd, VIDIOCGCHAN, &channel)) {
 		perror("ioctl VIDIOCGCHAN");
 	    }
 	    else {
 		debug_msg(" %s", channel.name);
+		for (unsigned int s=0 ; s<strlen(channel.name) ; s++)
+		  if (channel.name[s]==' ') channel.name[s]='-';
 		// Using S-Video as default
 		if(strcasecmp(channel.name, "S-Video")==0){
 		  strcat(attr, channel.name);
@@ -274,11 +283,11 @@
 	    }
 	}
 	strcat(attr, attr_tmp);
-			
+
 	debug_msg("\n");
 	strcat(attr, "} ");
 
-	if (-1 == ioctl(fd, VIDIOCGPICT, &pict)) {
+	if (-1 == v4l1_ioctl(fd, VIDIOCGPICT, &pict)) {
 	    perror("ioctl VIDIOCGPICT");
 	}
 	debug_msg("V4L:   depth=%d, palette=%s\n",  pict.depth,
@@ -292,7 +301,7 @@
 	new V4lDevice(dev[i], nick, attr);
 	fprintf(stderr, "Attached to V4L device: %s\n", nick);
 
-	close(fd);
+	v4l1_close(fd);
     }
 }
 
@@ -303,22 +312,6 @@
     unsigned int i = 0;
     struct video_mmap vid_mmap;
 
-    // COMMENTED by barz 2006/9/19: should not overwrite protected member variable capability
-    // struct video_capability  capability;
-
-    /* Taken from MASH - need to update code using this approach
-     * which checks for palettes with multiple resolutions
-     * Helps various Webcams... */
-    /*
-    int palettes[] = {
-	VIDEO_PALETTE_YUV422,	// BT878 (OS driver broken, so listed first)
-	VIDEO_PALETTE_YUV422P,	// BT878 (untested)
-	VIDEO_PALETTE_YUV420P,	// (untested)
-	VIDEO_PALETTE_UYVY,	// LML33
-	VIDEO_PALETTE_YUYV	// others listed in order of preference
-    };
-    */
-    
     have_mmap = 0;
     have_422P = 0;
     have_422 = 0;
@@ -339,15 +332,15 @@
 	return;
     }
 
-    if (-1 == ioctl(fd_, VIDIOCGCAP, &capability)) {
+    if (-1 == v4l1_ioctl(fd_, VIDIOCGCAP, &capability)) {
 	perror("ioctl VIDIOCGCAP");
-	close(fd_);
+	v4l1_close(fd_);
 	status_ = -1;
 	return;
     }
        
     /* ask for capabilities */
-    if (-1 == ioctl(fd_, VIDIOCGCAP, &capability)) {
+    if (-1 == v4l1_ioctl(fd_, VIDIOCGCAP, &capability)) {
 	perror("ioctl VIDIOCGCAP");
 	status_ = -1;
 	return;
@@ -360,11 +353,11 @@
 	calloc(capability.channels, sizeof(struct video_channel));
     for (i = 0; i < capability.channels; i++) {
 	channels[i].channel = i;
-	if (-1 == ioctl(fd_, VIDIOCGCHAN, &channels[i])) {
+	if (-1 == v4l1_ioctl(fd_, VIDIOCGCHAN, &channels[i])) {
 	    perror("ioctl VIDIOCGCHAN");
 	}
     }
-    if (-1 == ioctl(fd_, VIDIOCGPICT, &pict)) {
+    if (-1 == v4l1_ioctl(fd_, VIDIOCGPICT, &pict)) {
 	perror("ioctl VIDIOCGPICT");
     }
 
@@ -372,12 +365,12 @@
     gb_buffers.size = 2 * 0x151000;
     gb_buffers.offsets[0] = 0;
     gb_buffers.offsets[1] = 0x151000;
-    if (-1 == ioctl(fd_, VIDIOCGMBUF, &gb_buffers)) {
+    if (-1 == v4l1_ioctl(fd_, VIDIOCGMBUF, &gb_buffers)) {
 	perror("ioctl VIDIOCGMBUF");
     }
     mem =
-	(char *) mmap(0, gb_buffers.size, PROT_READ | PROT_WRITE, MAP_SHARED,
-		      fd_, 0);
+	(char *) v4l1_mmap(0, gb_buffers.size,
+			   PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0);
 
     if ((char *) -1 == mem) {
 	perror("mmap");
@@ -393,27 +386,26 @@
     vid_mmap.height = CIF_HEIGHT;
     
     vid_mmap.format = VIDEO_PALETTE_YUV422P;    
-    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
+    if (-1 != v4l1_ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
 	have_422P = 1;
 	debug_msg("Device capture VIDEO_PALETTE_YUV422P\n");
     }
 
     vid_mmap.format = VIDEO_PALETTE_YUV420P;
-    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
+    if (-1 != v4l1_ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
 	have_420P = 1;
 	debug_msg("Device capture VIDEO_PALETTE_YUV420P\n");
     }
 
-
     vid_mmap.format = VIDEO_PALETTE_YUV422;
-    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
+    if (-1 != v4l1_ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
 	have_422 = 1;
 	debug_msg("Device capture VIDEO_PALETTE_YUV422\n");
     }
 
     if( !( have_422P || have_422 || have_420P)){
       debug_msg("No suitable palette found\n");
-      close(fd_);
+      v4l1_close(fd_);
       status_=-1;
       return;
     }
@@ -432,8 +424,8 @@
     debug_msg("V4L: destructor\n");
 
     if (have_mmap)
-	munmap(mem, gb_buffers.size);
-    close(fd_);
+	v4l1_munmap(mem, gb_buffers.size);
+    v4l1_close(fd_);
 }
 
 int V4lGrabber::command(int argc, const char *const *argv)
@@ -475,7 +467,7 @@
 
 	    pict.brightness = val * 256;
 
-	    if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+	    if (-1 == v4l1_ioctl(fd_, VIDIOCSPICT, &pict))
 		perror("ioctl VIDIOCSPICT");
 
 	    debug_msg("V4L: Brightness = %d\n", val);
@@ -487,7 +479,7 @@
 
 	    pict.contrast = val * 256;
 
-	    if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+	    if (-1 == v4l1_ioctl(fd_, VIDIOCSPICT, &pict))
 		perror("ioctl VIDIOCSPICT");
 
 	    debug_msg("V4L: Contrast = %d\n", val);
@@ -499,7 +491,7 @@
 
 	    pict.hue = val * 256;
 
-	    if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+	    if (-1 == v4l1_ioctl(fd_, VIDIOCSPICT, &pict))
 		perror("ioctl VIDIOCSPICT");
 
 	    debug_msg("V4L: Hue = %d\n", val);
@@ -511,7 +503,7 @@
 
 	    pict.colour = val * 256;
 
-	    if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+	    if (-1 == v4l1_ioctl(fd_, VIDIOCSPICT, &pict))
 		perror("ioctl VIDIOCSPICT");
 
 	    debug_msg("V4L: Saturation = %d\n", val);
@@ -526,7 +518,7 @@
 		pict.colour = 32768;
 		pict.hue = 32768;
 
-		if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+		if (-1 == v4l1_ioctl(fd_, VIDIOCSPICT, &pict))
 		    perror("ioctl VIDIOCSPICT");
 
 		debug_msg("V4L: Resetting controls\n");
@@ -575,7 +567,7 @@
 	grab_count = 0;
 	sync_count = 0;
 
-	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_odd))
+	if (-1 == v4l1_ioctl(fd_, VIDIOCMCAPTURE, &gb_odd))
 	    perror("ioctl VIDIOCMCAPTURE odd");
 	else
 	    grab_count++;
@@ -583,7 +575,7 @@
 
 	// COMMENTED by barz 2006/9/19: not grab immediately after grabing         
 /*
-	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_even))
+	if (-1 == v4l1_ioctl(fd_, VIDIOCMCAPTURE, &gb_even))
 	    perror("ioctl VIDIOCMCAPTURE even");
 	else
 	    grab_count++;
@@ -598,7 +590,7 @@
 
     if (have_mmap) {
 	while (grab_count > sync_count) {
-	    if (-1 == ioctl(fd_, VIDIOCSYNC, (sync_count % 2) ? &one : &zero)) {
+	    if (-1 == v4l1_ioctl(fd_, VIDIOCSYNC, (sync_count % 2) ? &one : &zero)) {
 		perror("ioctl VIDIOCSYNC");
 		break;
 	    }
@@ -619,7 +611,7 @@
     if (have_mmap) {
 	fr = mem + (gb_buffers.offsets[(sync_count % 2) ? 1 : 0]);
 
-	if (-1 == ioctl(fd_, VIDIOCSYNC, (sync_count % 2) ? &one : &zero) < 0) {
+	if (-1 == v4l1_ioctl(fd_, VIDIOCSYNC, (sync_count % 2) ? &one : &zero)) {
 	    perror("ioctl VIDIOCSYNC");
 	    printf("Syncerror SyncCount %d\n", sync_count);
 	}
@@ -634,24 +626,11 @@
     switch (cformat_) {
     case CF_411:
     case CF_CIF:
-/*		    
-	if (have_422)         
-	    packed422_to_planar411((char*)frame_,fr);
-	else {
-	   //  have_420P 
-	   // vcvt_420p_411p(width_, height_, (char *)fr, frame_);  
-	   // erwartet wird scheinbar 420P und nicht 411P  *wunder* 
-	   memcpy((void *)frame_, (const void *)fr, (size_t)height_*width_*3/2);
-	}
-	break;						
-	*/
-
-	//  barz: bttv using packed422_to_planar411
 	if (have_420P)
 	    memcpy((void *) frame_, (const void *) fr,
 		   (size_t) height_ * width_ * 3 / 2);
 	else
-	    packed422_to_planar411((char *) frame_, fr);
+	    packed422_to_planar420((char *) frame_, fr);
 	break;
 
     case CF_422:
@@ -663,7 +642,7 @@
 	}
 	else {
 	    //  have_420P 
-	    vcvt_420p_422p(width_, height_, (char *) fr, frame_);
+	    planar420_to_planar422((char *) frame_, fr);
 	}
 	break;
     }
@@ -673,7 +652,7 @@
 
 	if (have_mmap) {
 	    if (-1 ==
-		ioctl(fd_, VIDIOCMCAPTURE,
+		v4l1_ioctl(fd_, VIDIOCMCAPTURE,
 		      (grab_count % 2) ? &gb_odd : &gb_even))
 		perror("ioctl VIDIOMCAPTURE");
 	    else
@@ -687,16 +666,15 @@
     return (target_->consume(&f));
 }
 
-void V4lGrabber::packed422_to_planar422(char *dest, char *src)
+void V4lGrabber::packed422_to_planar422(char *dest, const char *src)
 {
     int i;
-    char *s, *y, *u, *v;
+    char *y, *u, *v;
     unsigned int a, *srca;
 
     srca = (unsigned int *) src;
 
     i = (width_ * height_) / 2;
-    s = src;
     y = dest;
     u = y + width_ * height_;
     v = u + width_ * height_ / 2;
@@ -799,15 +777,14 @@
 
 }
 
-void V4lGrabber::packed422_to_planar411(char *dest, char *src)
+void V4lGrabber::packed422_to_planar420(char *dest, const char *src)
 {
     int a1, b;
-    char *s, *y, *u, *v;
+    char *y, *u, *v;
     unsigned int a, *srca;
 
     srca = (unsigned int *) src;
 
-    s = src;
     y = dest;
     u = y + width_ * height_;
     v = u + width_ * height_ / 4;
@@ -938,116 +915,39 @@
     }
 }
 
-/* Konvertierung YUV420P YUV422P
- * 
- */
-void V4lGrabber::vcvt_420p_422p(int width, int height, void *src, void *dst)
-{
-  /**
-  \brief convert YUV 4:2:0 (planar) data into YUV 4:2:2 (planar)
-  \param width Width of yuv data, in pixels
-  \param height Height of yuv data, in pixels
-  \param src beginning of YUV420 data
-  \param dst beginning of YUV422P data
-  */
 
-    int line, clinewidth;
+void V4lGrabber::planar420_to_planar422(char *dest, const char *src)
+{
+    int line, stride;
     unsigned char *sy, *su, *sv, *ty, *tu, *tv;
 
-    clinewidth = 2 * width;
+    stride = 2 * width_;
     sy = (unsigned char *) src;
-    su = sy + width * height;
-    sv = su + width * height / 4;
+    su = sy + width_ * height_;
+    sv = su + width_ * height_ / 4;
 
-    ty = (unsigned char *) dst;
-    tu = ty + width * height;
-    tv = tu + width * height / 2;
+    ty = (unsigned char *) dest;
+    tu = ty + width_ * height_;
+    tv = tu + width_ * height_ / 2;
 
     /* Copy planar lumina block */
-    memcpy(ty, sy, width * height);
+    memcpy(ty, sy, width_ * height_);
 
     /* Copy the chroma under consideration of chroma for two lines in YUV420 */
-    for (line = 0; line < height; line += 2) {
-	memcpy(tu, su, clinewidth);
-	memcpy(tv, sv, clinewidth);
+    for (line = 0; line < height_; line += 2) {
+	memcpy(tu, su, stride);
+	memcpy(tv, sv, stride);
 	// Don't increment sourceline if line = 2,6,10,14,... 
 	if ((line & 3) != 2) {
-	    su += width;
-	    sv += width;
-	}
-	tu += width;
-	tv += width;
-    }
-}
-
-
-/* Konvertierung YUV420P YUV411P
- * 
- */
-void V4lGrabber::vcvt_420p_411p(int width, int height, void *src, void *dst)
-{
-  /**
-  \brief convert YUV 4:2:0 (planar) data into YUV 4:1:1 (planar)
-  \param width Width of yuv data, in pixels
-  \param height Height of yuv data, in pixels
-  \param src beginning of YUV420 data
-  \param dst beginning of YUV422P data
-  */
-
-    int line, col, clinewidth, tr, tb;
-    unsigned char *sy, *su, *sv, *ty, *tu, *tv;
-
-    clinewidth = width * 2;
-    sy = (unsigned char *) src;
-    su = sy + width * height;
-    sv = su + width * height / 4;
-
-    ty = (unsigned char *) dst;
-    tu = ty + width * height;
-    tv = tu + width * height / 4;
-
-    /* Copy planar lumina block */
-    memcpy(ty, sy, width * height);
-
-    /* Copy the chroma under consideration of chroma for two lines in YUV420
-     * Conversation 2lines2columns1chroma => 1line4columns1chroma */
-    for (line = 0; line < height; line += 2) {
-	for (col = 0; col < clinewidth; col += 4) {
-	    tb = (*su++ + *su++) / 2;	//SV-XXX: clarify desired operation using brackets
-	    tr = (*sv++ + *sv++) / 2;	//SV-XXX: clarify desired operation using brackets
-	    *tu++ = tb;
-	    *tv++ = tr;
-	}
-
-	// Decrement sourceline if line = 2,6,10,14,... 
-	if ((line & 3) == 2) {
-	    su -= width;
-	    sv -= width;
+	    su += width_;
+	    sv += width_;
 	}
+	tu += width_;
+	tv += width_;
     }
-
-    /*  for (line = 0; line < height; line += 2) {
-       for (col = 0; col < width; col += 4){
-       tb = (*su++ + *su++) / 2;
-       tr = (*sv++ + *sv++) / 2;
-       *tu++ = tb;
-       *tv++ = tr;
-       }
-       su -= width/2;
-       sv -= width/2;
-       for (col = 0; col < width; col += 4){
-       tb = (*su++ + *su++) / 2;
-       tr = (*sv++ + *sv++) / 2;
-       *tu++ = tb;
-       *tv++ = tr;
-       }
-       } */
 }
 
 
-
-
-
 void V4lGrabber::format()
 {
     struct video_channel channel;
@@ -1114,36 +1014,36 @@
 	win.width = width_;
 	win.height = height_;
 	debug_msg("Setting palette to %d", pict.palette);
-	if (-1 == ioctl(fd_, VIDIOCSWIN, &win))
+	if (-1 == v4l1_ioctl(fd_, VIDIOCSWIN, &win))
 	    perror("ioctl VIDIOCSWIN");
-	if (-1 == ioctl(fd_, VIDIOCGWIN, &win))
+	if (-1 == v4l1_ioctl(fd_, VIDIOCGWIN, &win))
 	    perror("ioctl VIDIOCGWIN");
 	width_ = win.width;
 	height_ = win.height;
 	pict.palette = v4lformat_;
-	if (-1 == ioctl(fd_, VIDIOCSPICT, &pict)) {
+	if (-1 == v4l1_ioctl(fd_, VIDIOCSPICT, &pict)) {
 	    perror("ioctl VIDIOCSPICT");
 	}
     }
     // barz: get pict to setup the white blance
-    if (-1 == ioctl(fd_, VIDIOCGPICT, &pict)) {
+    if (-1 == v4l1_ioctl(fd_, VIDIOCGPICT, &pict)) {
 	perror("ioctl VIDIOCGPICT");
     }
 
     debug_msg(" size=%dx%d\n", width_, height_);
 
     bzero(&channel, sizeof(struct video_channel));
-    if (-1 == ioctl(fd_, VIDIOCGCHAN, &channel))
+    if (-1 == v4l1_ioctl(fd_, VIDIOCGCHAN, &channel))
 	perror("ioctl VIDIOCGCHAN");
 
     channel.channel = port_;
     channel.norm = norm_;
 
-    if (-1 == ioctl(fd_, VIDIOCSCHAN, &channel))
+    if (-1 == v4l1_ioctl(fd_, VIDIOCSCHAN, &channel))
 	perror("ioctl VIDIOCSCHAN");
 
     debug_msg(" port=%d\n", port_);
     debug_msg(" norm=%d\n", norm_);
-    
+
     allocref();
 }



More information about the Sumover-dev mailing list