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
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);
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
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)
{
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,
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;
}
#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) \
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);