Blob Blame History Raw
diff -Nrbu xawtv-3.95/libng/plugins/Subdir.mk xawtv-3.95-OK/libng/plugins/Subdir.mk
--- xawtv-3.95/libng/plugins/Subdir.mk	2008-08-26 19:46:59.000000000 +0400
+++ xawtv-3.95-OK/libng/plugins/Subdir.mk	2008-08-26 19:48:40.000000000 +0400
@@ -41,6 +41,7 @@
 libng/plugins/write-qt.so : LDLIBS := $(QT_LIBS)
 libng/plugins/read-dv.so  : LDLIBS := $(DV_LIBS)
 libng/plugins/write-dv.so : LDLIBS := $(DV_LIBS)
+libng/plugins/drv0-v4l2.so: LDLIBS := -lv4l2
 
 # global targets
 all:: $(TARGETS-plugins)
diff -Nrbu xawtv-3.95/libng/plugins/drv0-v4l2.c xawtv-3.95-OK/libng/plugins/drv0-v4l2.c
--- xawtv-3.95/libng/plugins/drv0-v4l2.c	2008-08-26 19:46:59.000000000 +0400
+++ xawtv-3.95-OK/libng/plugins/drv0-v4l2.c	2008-08-26 19:48:40.000000000 +0400
@@ -29,11 +29,26 @@
 #include "struct-dump.h"
 #include "struct-v4l2.h"
 
+/* FIXME replace with autoconf detection */
+#define HAVE_LIBV4L
+
+#ifdef HAVE_LIBV4L
+#include <libv4l2.h>
+#else
+#define v4l2_fd_open(fd, flags) (fd)
+#define v4l2_close close
+#define v4l2_dup dup
+#define v4l2_ioctl ioctl
+#define v4l2_read read
+#define v4l2_mmap mmap
+#define v4l2_munmap munmap
+#endif  
+
 /* ---------------------------------------------------------------------- */
 
 /* open+close */
-static void*   v4l2_open(char *device);
-static int     v4l2_close(void *handle);
+static void*   v4l2_open_handle(char *device);
+static int     v4l2_close_handle(void *handle);
 
 /* attributes */
 static char*   v4l2_devname(void *handle);
@@ -111,8 +126,8 @@
 
 struct ng_vid_driver v4l2_driver = {
     name:          "v4l2",
-    open:          v4l2_open,
-    close:         v4l2_close,
+    open:          v4l2_open_handle,
+    close:         v4l2_close_handle,
 
     get_devname:   v4l2_devname,
     capabilities:  v4l2_flags,
@@ -166,7 +181,7 @@
 {
     int rc;
 
-    rc = ioctl(fd,cmd,arg);
+    rc = v4l2_ioctl(fd,cmd,arg);
     if (rc >= 0 && ng_debug < 2)
 	return rc;
     if (mayfail && errno == mayfail && ng_debug < 2)
@@ -220,7 +235,7 @@
     }
 
     h->streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-    ioctl(h->fd,VIDIOC_G_PARM,&h->streamparm);
+    v4l2_ioctl(h->fd,VIDIOC_G_PARM,&h->streamparm);
 
     /* controls */
     for (i = 0; i < MAX_CTRL; i++) {
@@ -444,10 +459,10 @@
 /* ---------------------------------------------------------------------- */
 
 static void*
-v4l2_open(char *device)
+v4l2_open_handle(char *device)
 {
     struct v4l2_handle *h;
-    int i;
+    int i, libv4l2_fd;
 
     h = malloc(sizeof(*h));
     if (NULL == h)
@@ -459,6 +474,16 @@
 	goto err;
     }
 
+    /* Note the v4l2_xxx functions are designed so that if they get passed an
+       unknown fd, the will behave exactly as their regular xxx counterparts, so
+       if v4l2_fd_open fails, we continue as normal (missing the libv4l2 custom
+       cam format to normal formats conversion). Chances are big we will still
+       fail then though, as normally v4l2_fd_open only fails if the device is not
+       a v4l2 device. */
+    libv4l2_fd = v4l2_fd_open(h->fd, 0);
+    if (libv4l2_fd != -1)
+        h->fd = libv4l2_fd;
+
     if (-1 == xioctl(h->fd,VIDIOC_QUERYCAP,&h->cap,EINVAL))
 	goto err;
     if (ng_debug)
@@ -495,21 +520,21 @@
 
  err:
     if (h->fd != -1)
-	close(h->fd);
+	v4l2_close(h->fd);
     if (h)
 	free(h);
     return NULL;
 }
 
 static int
-v4l2_close(void *handle)
+v4l2_close_handle(void *handle)
 {
     struct v4l2_handle *h = handle;
 
     if (ng_debug)
 	fprintf(stderr, "v4l2: close\n");
 
-    close(h->fd);
+    v4l2_close(h->fd);
     free(h);
     return 0;
 }
@@ -818,7 +843,7 @@
 	h->buf_me[i].fmt  = h->fmt_me;
 	h->buf_me[i].size = h->buf_me[i].fmt.bytesperline *
 	    h->buf_me[i].fmt.height;
-	h->buf_me[i].data = mmap(NULL, h->buf_v4l2[i].length,
+	h->buf_me[i].data = v4l2_mmap(NULL, h->buf_v4l2[i].length,
 				 PROT_READ | PROT_WRITE, MAP_SHARED,
 				 h->fd, h->buf_v4l2[i].m.offset);
 	if (MAP_FAILED == h->buf_me[i].data) {
@@ -859,7 +884,7 @@
     unsigned int i;
     
     /* stop capture */
-    if (-1 == ioctl(h->fd,VIDIOC_STREAMOFF,&h->fmt_v4l2.type))
+    if (-1 == v4l2_ioctl(h->fd,VIDIOC_STREAMOFF,&h->fmt_v4l2.type))
 	perror("ioctl VIDIOC_STREAMOFF");
     
     /* free buffers */
@@ -868,7 +893,7 @@
 	    ng_waiton_video_buf(&h->buf_me[i]);
 	if (ng_debug)
 	    print_bufinfo(&h->buf_v4l2[i]);
-	if (-1 == munmap(h->buf_me[i].data, h->buf_v4l2_size[i]))
+	if (-1 == v4l2_munmap(h->buf_me[i].data, h->buf_v4l2_size[i]))
 	    perror("munmap");
     }
     h->queue = 0;
@@ -989,7 +1014,7 @@
     } else {
 	size = h->fmt_me.bytesperline * h->fmt_me.height;
 	buf = ng_malloc_video_buf(&h->fmt_me,size);
-	rc = read(h->fd,buf->data,size);
+	rc = v4l2_read(h->fd,buf->data,size);
 	if (rc != size) {
 	    if (-1 == rc) {
 		perror("v4l2: read");
@@ -1023,11 +1048,11 @@
     size = h->fmt_me.bytesperline * h->fmt_me.height;
     buf = ng_malloc_video_buf(&h->fmt_me,size);
     if (h->cap.capabilities & V4L2_CAP_READWRITE) {
-	rc = read(h->fd,buf->data,size);
+	rc = v4l2_read(h->fd,buf->data,size);
 	if (-1 == rc  &&  EBUSY == errno  &&  h->ov_on) {
 	    h->ov_on = 0;
 	    xioctl(h->fd, VIDIOC_OVERLAY, &h->ov_on, 0);
-	    rc = read(h->fd,buf->data,size);
+	    rc = v4l2_read(h->fd,buf->data,size);
 	    h->ov_on = 1;
 	    xioctl(h->fd, VIDIOC_OVERLAY, &h->ov_on, 0);
 	}