PKGBUILDs/extra/xawtv/xawtv-3.95-libv4l2.patch

177 lines
5.5 KiB
Diff
Raw Normal View History

2009-10-10 02:23:22 +00:00
--- xawtv-3.95/libng/plugins/Subdir.mk~ 2008-07-30 09:51:01.000000000 +0200
+++ xawtv-3.95/libng/plugins/Subdir.mk 2008-07-30 09:51:01.000000000 +0200
@@ -41,6 +41,7 @@ libng/plugins/read-qt.so : LDLIBS := $(
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 -up xawtv-3.95/libng/plugins/drv0-v4l2.c.orig xawtv-3.95/libng/plugins/drv0-v4l2.c
--- xawtv-3.95/libng/plugins/drv0-v4l2.c.orig 2008-08-03 21:26:13.000000000 +0200
+++ xawtv-3.95/libng/plugins/drv0-v4l2.c 2008-08-03 21:27:50.000000000 +0200
@@ -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 v4l2_handle {
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 @@ xioctl(int fd, int cmd, void *arg, int m
{
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 @@ get_device_capabilities(struct v4l2_hand
}
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_write_attr(struct ng_at
/* ---------------------------------------------------------------------- */
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 @@ v4l2_open(char *device)
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 @@ v4l2_open(char *device)
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 @@ v4l2_start_streaming(struct v4l2_handle
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 @@ v4l2_stop_streaming(struct v4l2_handle *
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 @@ v4l2_stop_streaming(struct v4l2_handle *
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 @@ v4l2_nextframe(void *handle)
} 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 @@ v4l2_getimage(void *handle)
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);
}