diff options
author | Thierry MERLE <thierry.merle@free.fr> | 2008-07-06 14:07:34 +0200 |
---|---|---|
committer | Thierry MERLE <thierry.merle@free.fr> | 2008-07-06 14:07:34 +0200 |
commit | ab715d2e8eb29998b60fa3bbc1ad95441cfb69b3 (patch) | |
tree | 78731a6290210dba267ee4f6f3655659334835d4 /v4l2-apps/lib/libv4l/libv4l2 | |
parent | c1a4267284bcd81240221187f5a16454f36ba02e (diff) | |
download | mediapointer-dvb-s2-ab715d2e8eb29998b60fa3bbc1ad95441cfb69b3.tar.gz mediapointer-dvb-s2-ab715d2e8eb29998b60fa3bbc1ad95441cfb69b3.tar.bz2 |
v4l2-library: libv4l-sync-with-0.3.3-release
From: Hans de Goede <j.w.r.degoede@hhs.nl>
* 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 <j.w.r.degoede@hhs.nl>
Signed-off-by: Thierry MERLE <thierry.merle@free.fr>
Diffstat (limited to 'v4l2-apps/lib/libv4l/libv4l2')
-rw-r--r-- | v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h | 9 | ||||
-rw-r--r-- | v4l2-apps/lib/libv4l/libv4l2/libv4l2.c | 58 | ||||
-rw-r--r-- | v4l2-apps/lib/libv4l/libv4l2/v4l2convert.c | 31 |
3 files changed, 81 insertions, 17 deletions
diff --git a/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h b/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h index e4edf91f2..203dcffaf 100644 --- a/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h +++ b/v4l2-apps/lib/libv4l/libv4l2/libv4l2-priv.h @@ -23,6 +23,15 @@ #include <pthread.h> #include <libv4lconvert.h> /* includes videodev2.h for us */ +/* On 32 bits archs we always use mmap2, on 64 bits archs there is no mmap2 */ +#ifdef __NR_mmap2 +#define SYS_mmap2 __NR_mmap2 +#define MMAP2_PAGE_SHIFT 12 +#else +#define SYS_mmap2 SYS_mmap +#define MMAP2_PAGE_SHIFT 0 +#endif + #define V4L2_MAX_DEVICES 16 /* Warning when making this larger the frame_queued and frame_mapped members of the v4l2_dev_info struct can no longer be a bitfield, so the code needs to diff --git a/v4l2-apps/lib/libv4l/libv4l2/libv4l2.c b/v4l2-apps/lib/libv4l/libv4l2/libv4l2.c index 0ed6ebdc6..5830576ae 100644 --- a/v4l2-apps/lib/libv4l/libv4l2/libv4l2.c +++ b/v4l2-apps/lib/libv4l/libv4l2/libv4l2.c @@ -55,9 +55,6 @@ When modifications are made, one should be carefull that this behavior is preserved. */ - -#define _LARGEFILE64_SOURCE 1 - #include <errno.h> #include <stdarg.h> #include <stdio.h> @@ -161,8 +158,9 @@ static int v4l2_map_buffers(int index) break; } - devices[index].frame_pointers[i] = mmap64(NULL, buf.length, - PROT_READ, MAP_SHARED, devices[index].fd, buf.m.offset); + devices[index].frame_pointers[i] = (void *)syscall(SYS_mmap2, NULL, + (size_t)buf.length, PROT_READ, MAP_SHARED, devices[index].fd, + (__off_t)(buf.m.offset >> MMAP2_PAGE_SHIFT)); if (devices[index].frame_pointers[i] == MAP_FAILED) { int saved_err = errno; V4L2_LOG_ERR("mmapping buffer %u: %s\n", i, strerror(errno)); @@ -583,8 +581,13 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) } } - if (!is_capture_request) - return syscall(SYS_ioctl, fd, request, arg); + if (!is_capture_request) { + result = syscall(SYS_ioctl, fd, request, arg); + saved_err = errno; + v4l2_log_ioctl(request, arg, result); + errno = saved_err; + return result; + } if (stream_needs_locking) @@ -755,16 +758,22 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) struct v4l2_buffer *buf = arg; result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_DQBUF, buf); - if (result || !converting) + if (result) { + V4L2_LOG_ERR("dequeing buffer: %s\n", strerror(errno)); + break; + } + + if (!converting) break; /* An application can do a DQBUF before mmap-ing in the buffer, but we need the buffer _now_ to write our converted data to it! */ if (devices[index].convert_mmap_buf == MAP_FAILED) { - devices[index].convert_mmap_buf = mmap64(NULL, - devices[index].no_frames * - V4L2_FRAME_BUF_SIZE, + devices[index].convert_mmap_buf = (void *)syscall(SYS_mmap2, + (size_t)( + devices[index].no_frames * + V4L2_FRAME_BUF_SIZE), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); @@ -789,8 +798,11 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) devices[index].convert_mmap_buf + buf->index * V4L2_FRAME_BUF_SIZE, V4L2_FRAME_BUF_SIZE); - if (result < 0) + if (result < 0) { + V4L2_LOG_ERR("converting / decoding frame data: %s\n", + v4lconvert_get_error_message(devices[index].convert)); break; + } buf->bytesused = result; buf->length = V4L2_FRAME_BUF_SIZE; @@ -861,6 +873,10 @@ ssize_t v4l2_read (int fd, void* buffer, size_t n) v4l2_queue_read_buffer(index, frame_index); + if (result < 0) + V4L2_LOG_ERR("converting / decoding frame data: %s\n", + v4lconvert_get_error_message(devices[index].convert)); + leave: pthread_mutex_unlock(&devices[index].stream_lock); @@ -868,7 +884,7 @@ leave: } void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd, - __off_t offset) + __off64_t offset) { int index; unsigned int buffer_index; @@ -882,7 +898,14 @@ void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd, if (index != -1) V4L2_LOG("Passing mmap(%p, %d, ..., %x, through to the driver\n", start, (int)length, (int)offset); - return mmap64(start, length, prot, flags, fd, offset); + + if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) { + errno = EINVAL; + return MAP_FAILED; + } + + return (void *)syscall(SYS_mmap2, start, length, prot, flags, fd, + (__off_t)(offset >> MMAP2_PAGE_SHIFT)); } pthread_mutex_lock(&devices[index].stream_lock); @@ -899,9 +922,10 @@ void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd, } if (devices[index].convert_mmap_buf == MAP_FAILED) { - devices[index].convert_mmap_buf = mmap64(NULL, - devices[index].no_frames * - V4L2_FRAME_BUF_SIZE, + devices[index].convert_mmap_buf = (void *)syscall(SYS_mmap2, NULL, + (size_t)( + devices[index].no_frames * + V4L2_FRAME_BUF_SIZE), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); 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 <stdarg.h> #include <stdlib.h> #include <syscall.h> @@ -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); |