From 0d3f75db47da8e0a51eab041eb401bfb6f309174 Mon Sep 17 00:00:00 2001 From: Thierry MERLE Date: Tue, 1 Jul 2008 21:11:29 +0200 Subject: v4l2-library: libv4l2 and v4l2convert From: Hans de Goede libv4l2 offers v4l2_ prefixed versions of open/close/etc. The API is 100% the same as directly opening /dev/videoX using regular open/close/etc, the big difference is that format conversion is done if necessary when capturing. That is if you (try to) set a capture format which is not supported by the cam, but is supported by libv4lconvert, then the try_fmt / set_fmt will succeed as if the cam supports the format and on dqbuf / read the data will be converted for you and returned in the request format. v4l2convert: open/close/ioctl/mmap/munmap library call wrapper doing format conversion for v4l2 applications which want to be able to simply capture bgr24 / yuv420 from v4l2 devices with more exotic frame formats. Signed-off-by: Hans de Goede Signed-off-by: Thierry MERLE --- v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c | 121 +++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c (limited to 'v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c') diff --git a/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c b/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c new file mode 100644 index 000000000..bcd11c2cc --- /dev/null +++ b/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c @@ -0,0 +1,121 @@ +/* +# open/close/ioctl/mmap/munmap library call wrapper doing format conversion +# for v4l2 applications which want to be able to simply capture bgr24 / yuv420 +# from v4l2 devices with more exotic frame formats. + +# (C) 2008 Hans de Goede + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include +#include +#include +#include +/* These headers are not needed by us, but by linux/videodev2.h, + which is broken on some systems and doesn't include them itself :( */ +#include +#include +#include +/* end broken header workaround includes */ +#include +#include + +/* Check that open/read/mmap is not a define */ +#if defined open || defined read || defined mmap +#error open/read/mmap is a prepocessor macro !! +#endif + +int open (const char *file, int oflag, ...) +{ + int fd; + struct v4l2_capability cap; + + /* original open code */ + if (oflag & O_CREAT) + { + va_list ap; + mode_t mode; + + va_start (ap, oflag); + mode = va_arg (ap, mode_t); + + fd = syscall(SYS_open, file, oflag, mode); + + va_end(ap); + } else + fd = syscall(SYS_open, file, oflag); + /* end of original open code */ + + if (fd == -1) + return fd; + + /* check if we're opening a video4linux2 device */ + if (strncmp(file, "/dev/video", 10)) + return fd; + + /* check that this is an v4l2 device, libv4l2 only supports v4l2 devices */ + if (syscall(SYS_ioctl, fd, VIDIOC_QUERYCAP, &cap)) + return fd; + + /* libv4l2 only adds functionality to capture capable devices */ + if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) + return fd; + + /* Try to Register with libv4l2 (in case of failure pass the fd to the + application as is) */ + v4l2_fd_open(fd, V4L2_ENABLE_ENUM_FMT_EMULATION); + + return fd; +} + +int close(int fd) +{ + return v4l2_close(fd); +} + +int dup(int fd) +{ + return v4l2_dup(fd); +} + +int ioctl (int fd, unsigned long int request, ...) +{ + void *arg; + va_list ap; + + va_start (ap, request); + arg = va_arg (ap, void *); + va_end (ap); + + return v4l2_ioctl (fd, request, arg); +} + +ssize_t read (int fd, void* buffer, size_t n) +{ + return v4l2_read (fd, buffer, n); +} + +void mmap(void *start, size_t length, int prot, int flags, int fd, + off_t offset) +{ + return v4l2_mmap(start, length, prot, flags, fd, offset); +} + +int munmap(void *start, size_t length) +{ + return v4l2_munmap(start, length); +} -- cgit v1.2.3 From 63c4e4bef7b1537de4e313ee9d20907a372d8f56 Mon Sep 17 00:00:00 2001 From: Thierry MERLE Date: Fri, 4 Jul 2008 19:30:13 +0200 Subject: v4l2-library: libv4l-warnings.patch From: Hans de Goede Fix all compiler warnings in libv4l Signed-off-by: Hans de Goede Signed-off-by: Thierry MERLE --- v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c') diff --git a/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c b/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c index bcd11c2cc..67f563602 100644 --- a/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c +++ b/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c @@ -110,7 +110,7 @@ ssize_t read (int fd, void* buffer, size_t n) } void mmap(void *start, size_t length, int prot, int flags, int fd, - off_t offset) + __off_t offset) { return v4l2_mmap(start, length, prot, flags, fd, offset); } -- cgit v1.2.3 From ab715d2e8eb29998b60fa3bbc1ad95441cfb69b3 Mon Sep 17 00:00:00 2001 From: Thierry MERLE Date: Sun, 6 Jul 2008 14:07:34 +0200 Subject: v4l2-library: libv4l-sync-with-0.3.3-release From: Hans de Goede * Add open64 and mmap64 wrappers to the LD_PRELOAD wrapper libs, so that they also work for applications compiled with FILE_OFFSET_BITS=64, this fixes using them with v4l-info * While looking at xawtv in general, found a few bugs in xawtv itself, added a patch to fix those to the appl-patches dir * Talking about the appl-patches dir, restore that as it accidentally got dropped from 0.3.2 * Be more verbose in various places when it comes to logging (esp errors) * Change v4lconvert_enum_fmt code a bit, so that it is easier to add more supported destination formats to libv4lconvert * Don't return -EINVAL from try_fmt when we cannot convert because the cam doesn't have any formats we know. Instead just return as format whatever the cam returns from try_fmt, this new behavior is compliant with the v4l2 api as documented Signed-off-by: Hans de Goede Signed-off-by: Thierry MERLE --- v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c') diff --git a/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c b/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c index 67f563602..7db1ca6d6 100644 --- a/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c +++ b/v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c @@ -20,6 +20,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#define _LARGEFILE64_SOURCE 1 + #include #include #include @@ -82,6 +84,29 @@ int open (const char *file, int oflag, ...) return fd; } +int open64(const char *file, int oflag, ...) +{ + int fd; + + /* original open code */ + if (oflag & O_CREAT) + { + va_list ap; + mode_t mode; + + va_start (ap, oflag); + mode = va_arg (ap, mode_t); + + fd = open(file, oflag | O_LARGEFILE, mode); + + va_end(ap); + } else + fd = open(file, oflag | O_LARGEFILE); + /* end of original open code */ + + return fd; +} + int close(int fd) { return v4l2_close(fd); @@ -115,6 +140,12 @@ void mmap(void *start, size_t length, int prot, int flags, int fd, return v4l2_mmap(start, length, prot, flags, fd, offset); } +void mmap64(void *start, size_t length, int prot, int flags, int fd, + __off64_t offset) +{ + return v4l2_mmap(start, length, prot, flags, fd, offset); +} + int munmap(void *start, size_t length) { return v4l2_munmap(start, length); -- cgit v1.2.3