libv4l: Add v4l2_write function and plugin op
authorHans de Goede <hdegoede@redhat.com>
Sun, 24 Jul 2011 17:35:11 +0000 (19:35 +0200)
committerHans de Goede <hdegoede@redhat.com>
Sun, 24 Jul 2011 17:35:49 +0000 (19:35 +0200)
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
lib/include/libv4l2-plugin.h
lib/include/libv4l2.h
lib/libv4l2/libv4l2.c
lib/libv4l2/v4l2-plugin.c
lib/libv4lconvert/libv4lsyscall-priv.h

index 158c0c2..150eb17 100644 (file)
@@ -31,6 +31,16 @@ struct libv4l2_dev_ops {
     void (*close)(void *dev_ops_priv);
     int (*ioctl)(void *dev_ops_priv, int fd, unsigned long int request, void *arg);
     ssize_t (*read)(void *dev_ops_priv, int fd, void *buffer, size_t n);
+    ssize_t (*write)(void *dev_ops_priv, int fd, const void *buffer, size_t n);
+    /* For future plugin API extension, plugins implementing the current API
+       must set these all to NULL, as future versions may check for these */
+    void (*reserved1)(void);
+    void (*reserved2)(void);
+    void (*reserved3)(void);
+    void (*reserved4)(void);
+    void (*reserved5)(void);
+    void (*reserved6)(void);
+    void (*reserved7)(void);
 };
 
 #endif
index 1985e08..20960d2 100644 (file)
@@ -70,6 +70,7 @@ LIBV4L_PUBLIC int v4l2_close(int fd);
 LIBV4L_PUBLIC int v4l2_dup(int fd);
 LIBV4L_PUBLIC int v4l2_ioctl(int fd, unsigned long int request, ...);
 LIBV4L_PUBLIC ssize_t v4l2_read(int fd, void *buffer, size_t n);
+LIBV4L_PUBLIC ssize_t v4l2_write(int fd, const void *buffer, size_t n);
 LIBV4L_PUBLIC void *v4l2_mmap(void *start, size_t length, int prot, int flags,
                int fd, int64_t offset);
 LIBV4L_PUBLIC int v4l2_munmap(void *_start, size_t length);
index 04689b8..c8e75f7 100644 (file)
@@ -1414,6 +1414,11 @@ ssize_t v4l2_read(int fd, void *dest, size_t n)
        if (index == -1)
                return SYS_READ(fd, dest, n);
 
+       if (!devices[index].dev_ops->read) {
+               errno = EINVAL;
+               return -1;
+       }
+
        pthread_mutex_lock(&devices[index].stream_lock);
 
        /* When not converting and the device supports read let the kernel handle
@@ -1466,6 +1471,22 @@ leave:
        return result;
 }
 
+ssize_t v4l2_write(int fd, const void *buffer, size_t n)
+{
+       int index = v4l2_get_index(fd);
+
+       if (index == -1)
+               return SYS_WRITE(fd, buffer, n);
+
+       if (!devices[index].dev_ops->write) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       return devices[index].dev_ops->write(
+                       devices[index].dev_ops_priv, fd, buffer, n);
+}
+
 void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd,
                int64_t offset)
 {
index 3c513a7..0b74d2e 100644 (file)
@@ -66,11 +66,18 @@ static ssize_t dev_read(void *dev_ops_priv, int fd, void *buf, size_t len)
        return SYS_READ(fd, buf, len);
 }
 
+static ssize_t dev_write(void *dev_ops_priv, int fd, const void *buf,
+                         size_t len)
+{
+       return SYS_WRITE(fd, buf, len);
+}
+
 const struct libv4l2_dev_ops libv4l2_default_dev_ops = {
        .init = dev_init,
        .close = dev_close,
        .ioctl = dev_ioctl,
-       .read = dev_read
+       .read = dev_read,
+       .write = dev_write,
 };
 
 void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret,
@@ -113,9 +120,8 @@ void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret,
 
                if (!libv4l2_plugin->init ||
                    !libv4l2_plugin->close ||
-                   !libv4l2_plugin->ioctl ||
-                   !libv4l2_plugin->read) {
-                       V4L2_LOG("PLUGIN: does not have all functions\n");
+                   !libv4l2_plugin->ioctl) {
+                       V4L2_LOG("PLUGIN: does not have all mandatory ops\n");
                        dlclose(plugin_library);
                        continue;
                }
index 87028ef..8d8a1d1 100644 (file)
@@ -81,7 +81,7 @@ typedef off_t __off_t;
 #define SYS_READ(fd, buf, len) \
        syscall(SYS_read, (int)(fd), (void *)(buf), (size_t)(len));
 #define SYS_WRITE(fd, buf, len) \
-       syscall(SYS_write, (int)(fd), (void *)(buf), (size_t)(len));
+       syscall(SYS_write, (int)(fd), (const void *)(buf), (size_t)(len));
 
 #ifdef __FreeBSD__
 #define SYS_MMAP(addr, len, prot, flags, fd, off) \
@@ -102,7 +102,7 @@ int v4lx_open_wrapper(const char *, int, int);
 int v4lx_close_wrapper(int);
 int v4lx_ioctl_wrapper(int, unsigned long, void *);
 int v4lx_read_wrapper(int, void *, size_t);
-int v4lx_write_wrapper(int, void *, size_t);
+int v4lx_write_wrapper(int, const void *, size_t);
 void *v4lx_mmap_wrapper(void *, size_t, int, int, int, off_t);
 int v4lx_munmap_wrapper(void *, size_t);