libv4l: Add plugin support
v3 cover libv4l: Add plugin support
Hi Hans,
here is third version of plugin support for libv4l2.
Changes in v3:
* Pass opened fd to the plugin instead of filename
* Plugin private data is returned by init call and is passed as argument in ioctl/read/close (remove libv4l2_set/get_plugindata functions)
* Plugin do not handle mmap/munmap
--------------------------------------------------------------------------
Changes in v2:
* Remove calls of v4l2_plugin_foo functions in the beginning of coresponding v4l2_foo functions and instead replace SYS_FOO calls.
* Add to v4l2_dev_info device operation structure which can hold plugin callbacks or dyrect syscall(SYS_foo, ...) calls.
* Under libv4lconvert also replace SYS_FOO cals with device operations. This required also to add dev_ops field to v4lconvert_data and v4lcontrol_data.
---------------------------------------------------------------------------
v1:
Here is initial version of plugin support for libv4l, based on your RFC.
It is provided by functions v4l2_plugin_[open,close,etc]. When open() is called libv4l dlopens files in /usr/lib/libv4l/plugins 1 at a time and call open() callback passing through the applications parameters unmodified. If a plugin is relevant for the specified device node, it can indicate so by returning a value other then -1 (the actual file descriptor).
As soon as a plugin returns another value then -1 plugin loading stops and information about it (fd and corresponding library handle) is stored. For each function v4l2_[ioctl,read,close,etc] is called corresponding v4l2_plugin_* function which looks if there is loaded plugin for that file and call it's callbacks. v4l2_plugin_* functions indicate by their first argument if plugin was used, and if it was not then v4l2_* functions proceed with their usual behavior.
Yordan Kamenov (1):
libv4l: Add plugin support to libv4l
lib/include/libv4l2-plugin.h | 36 ++++++ lib/include/libv4lconvert.h | 5 +- lib/libv4l2/Makefile | 4 +- lib/libv4l2/libv4l2-priv.h | 10 ++ lib/libv4l2/libv4l2.c | 90 ++++++++++---- lib/libv4l2/v4l2-plugin.c | 160 ++++++++++++++++++++++++ lib/libv4l2/v4l2convert.c | 9 -- lib/libv4lconvert/control/libv4lcontrol-priv.h | 4 + lib/libv4lconvert/control/libv4lcontrol.c | 35 ++++-- lib/libv4lconvert/control/libv4lcontrol.h | 5 +- lib/libv4lconvert/libv4lconvert-priv.h | 2 + lib/libv4lconvert/libv4lconvert.c | 34 ++++-- 12 files changed, 333 insertions(+), 61 deletions(-) create mode 100644 lib/include/libv4l2-plugin.h create mode 100644 lib/libv4l2/v4l2-plugin.c
Signature · 1 line
1.7.3.1
PATCH v3 1/1 libv4l: Add plugin support to libv4l
A libv4l2 plugin will sit in between libv4l2 itself and the actual /dev/video device node a fd refers to. It will be called each time libv4l2 wants to do an operation (read/write/ioctl) on the actual /dev/video node in question.
--- lib/include/libv4l2-plugin.h | 36 ++++++ lib/include/libv4lconvert.h | 5 +- lib/libv4l2/Makefile | 4 +- lib/libv4l2/libv4l2-priv.h | 10 ++ lib/libv4l2/libv4l2.c | 90 ++++++++++---- lib/libv4l2/v4l2-plugin.c | 160 ++++++++++++++++++++++++ lib/libv4l2/v4l2convert.c | 9 -- lib/libv4lconvert/control/libv4lcontrol-priv.h | 4 + lib/libv4lconvert/control/libv4lcontrol.c | 35 ++++-- lib/libv4lconvert/control/libv4lcontrol.h | 5 +- lib/libv4lconvert/libv4lconvert-priv.h | 2 + lib/libv4lconvert/libv4lconvert.c | 34 ++++-- 12 files changed, 333 insertions(+), 61 deletions(-) create mode 100644 lib/include/libv4l2-plugin.h create mode 100644 lib/libv4l2/v4l2-plugin.c
lib/include/libv4l2-plugin.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2010 Nokia Corporation <[email protected]> + +* 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 +* Lesser 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 +*/ + +#ifndef __LIBV4L2_PLUGIN_H +#define __LIBV4L2_PLUGIN_H + +#include <sys/types.h> + +/* Structure libv4l2_dev_ops holds the calls from libv4ls to video nodes. +They can be normal open/close/ioctl etc. or any of them may be replaced +with a callback by a loaded plugin. +*/ + +struct libv4l2_dev_ops { +void * (*init)(int fd); +int (*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); +}; + +#endif
lib/include/libv4lconvert.h +4 -1
@@ -38,6 +38,8 @@#include <linux/videodev2.h> +#include "libv4l2-plugin.h" +#ifdef __cplusplusextern "C" {#endif /* __cplusplus */
@@ -50,7 +52,8 @@ extern "C" {struct v4lconvert_data ; -LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create(int fd); +LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create(int fd, +void *dev_ops_priv,struct libv4l2_dev_ops *dev_ops); LIBV4L_PUBLIC void v4lconvert_destroy(struct v4lconvert_data *data);/* When doing flipping / rotating / video-processing, only supported
lib/libv4l2/Makefile +2 -2
@@ -1,8 +1,8 @@ override CPPFLAGS += -I../include -fvisibility=hidden -LIBS_libv4l2 = -lpthread +LIBS_libv4l2 = -lpthread -ldl -V4L2_OBJS = libv4l2.o log.o +V4L2_OBJS = libv4l2.o v4l2-plugin.o log.o V4L2CONVERT = v4l2convert.so V4L2CONVERT_O = v4l2convert.o libv4l2.so TARGETS = $(V4L2_LIB) libv4l2.pc
lib/libv4l2/libv4l2-priv.h +10 -0
@@ -85,8 +85,18 @@ struct v4l2_dev_info {/* buffer when doing conversion and using read() for read() */ int readbuf_size;unsigned char *readbuf; +struct libv4l2_dev_ops *dev_ops; +/* plugin info */ +void *plugin_library; +void *dev_ops_priv; }; +void v4l2_plugin_init (int fd,void **plugin_lib_ret,void **plugin_priv_ret, +struct libv4l2_dev_ops **dev_ops_ret); +void v4l2_plugin_cleanup (void *plugin_priv,void *plugin_lib, +struct libv4l2_dev_ops *dev_ops); + +/* From log.c */ void v4l2_log_ioctl (unsigned long int request,void *arg,int result);
lib/libv4l2/libv4l2.c +65 -25
284 lines not on this page · raw message
lib/libv4l2/v4l2-plugin.c new file +160 -0
160 lines not on this page · raw message
lib/libv4l2/v4l2convert.c +0 -9
@@ -46,7 +46,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...) {int fd; -struct v4l2_capability cap;int v4l_device =0 ;/* check if we're opening a video4linux2 device */
@@ -76,14 +75,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...)if (fd ==-1 || !v4l_device)return fd; -/* check that this is an v4l2 device, libv4l2 only supports v4l2 devices */ -if (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,0 );
lib/libv4lconvert/control/libv4lcontrol-priv.h +4 -0
@@ -22,6 +22,8 @@#ifndef __LIBV4LCONTROL_PRIV_H#define __LIBV4LCONTROL_PRIV_H +#include "libv4l2-plugin.h" +#define V4LCONTROL_SHM_SIZE 4096#define V4LCONTROL_SUPPORTS_NEXT_CTRL 0x01
@@ -37,6 +39,8 @@ struct v4lcontrol_data {unsigned int *shm_values;/* shared memory control value store */ unsigned int old_values[V4LCONTROL_COUNT ];/* for controls_changed() */ const struct v4lcontrol_flags_info *flags_info; +struct libv4l2_dev_ops *dev_ops; +void *dev_ops_priv; };struct v4lcontrol_flags_info {
lib/libv4lconvert/control/libv4lcontrol.c +23 -12
@@ -701,7 +701,8 @@ static void v4lcontrol_get_flags_from_db(struct v4lcontrol_data *data, } } -struct v4lcontrol_data *v4lcontrol_create (int fd,int always_needs_conversion) +struct v4lcontrol_data *v4lcontrol_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops,int always_needs_conversion) {int shm_fd;int i, rc, got_usb_ids, init =0 ;
@@ -721,10 +722,12 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion) } data->fd = fd; + data->dev_ops = dev_ops; + data->dev_ops_priv = dev_ops_priv;/* Check if the driver has indicated some form of flipping is needed */ -if ((SYS_IOCTL (data->fd,VIDIOC_G_INPUT , &input.index) ==0 ) && - (SYS_IOCTL (data->fd,VIDIOC_ENUMINPUT , &input) ==0 )) { +if ((data->dev_ops->ioctl (data->dev_ops_priv, data->fd,VIDIOC_G_INPUT , &input.index) ==0 ) && + (data->dev_ops->ioctl (data->dev_ops_priv, data->fd,VIDIOC_ENUMINPUT , &input) ==0 )) {if (input.status &V4L2_IN_ST_HFLIP ) data->flags |=V4LCONTROL_HFLIPPED ;if (input.status &V4L2_IN_ST_VFLIP )
@@ -741,7 +744,8 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion) data->flags =strtol (s,NULL ,0 ); ctrl.id =V4L2_CTRL_FLAG_NEXT_CTRL ; -if (SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL , &ctrl) ==0 ) +if (data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL , &ctrl) ==0 ) data->priv_flags |=V4LCONTROL_SUPPORTS_NEXT_CTRL ;/* If the device always needs conversion, we can add fake controls at no cost
@@ -749,7 +753,8 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)if (always_needs_conversion ||v4lcontrol_needs_conversion (data)) {for (i =0 ; i <V4LCONTROL_AUTO_ENABLE_COUNT ; i++) { ctrl.id = fake_controls[i].id; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL , &ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL , &ctrl);if (rc ==-1 || (rc ==0 && (ctrl.flags &V4L2_CTRL_FLAG_DISABLED ))) data->controls |=1 << i; }
@@ -761,17 +766,20 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)different sensors with / without autogain or the necessary controls. */ while (data->flags &V4LCONTROL_WANTS_AUTOGAIN ) { ctrl.id =V4L2_CID_AUTOGAIN ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL , &ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL , &ctrl);if (rc ==0 && !(ctrl.flags &V4L2_CTRL_FLAG_DISABLED ))break ; ctrl.id =V4L2_CID_EXPOSURE ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL , &ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL , &ctrl);if (rc !=0 || (ctrl.flags &V4L2_CTRL_FLAG_DISABLED ))break ; ctrl.id =V4L2_CID_GAIN ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL , &ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL , &ctrl);if (rc !=0 || (ctrl.flags &V4L2_CTRL_FLAG_DISABLED ))break ;
@@ -788,7 +796,7 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)if (data->controls ==0 )return data;/* No need to create a shared memory segment */ -if (SYS_IOCTL (fd,VIDIOC_QUERYCAP , &cap)) { +if (data->dev_ops->ioctl (data->dev_ops_priv, fd,VIDIOC_QUERYCAP , &cap)) {perror ("libv4lcontrol: error querying device capabilities" ); goto error; }
@@ -974,7 +982,8 @@ int v4lcontrol_vidioc_queryctrl(struct v4lcontrol_data *data, void *arg) }/* find out what the kernel driver would respond. */ - retval =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL , arg); + retval = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL , arg);if ((data->priv_flags &V4LCONTROL_SUPPORTS_NEXT_CTRL ) && (orig_id &V4L2_CTRL_FLAG_NEXT_CTRL )) {
@@ -1011,7 +1020,8 @@ int v4lcontrol_vidioc_g_ctrl(struct v4lcontrol_data *data, void *arg)return 0 ; } -return SYS_IOCTL (data->fd,VIDIOC_G_CTRL , arg); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_G_CTRL , arg); }int v4lcontrol_vidioc_s_ctrl (struct v4lcontrol_data *data,void *arg)
@@ -1032,7 +1042,8 @@ int v4lcontrol_vidioc_s_ctrl(struct v4lcontrol_data *data, void *arg)return 0 ; } -return SYS_IOCTL (data->fd,VIDIOC_S_CTRL , arg); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_S_CTRL , arg); }int v4lcontrol_get_flags (struct v4lcontrol_data *data)
lib/libv4lconvert/control/libv4lcontrol.h +4 -1
@@ -22,6 +22,8 @@#ifndef __LIBV4LCONTROL_H#define __LIBV4LCONTROL_H +#include "libv4l2-plugin.h" +/* Flags */ #define V4LCONTROL_HFLIPPED 0x01#define V4LCONTROL_VFLIPPED 0x02
@@ -47,7 +49,8 @@ enum {struct v4lcontrol_data ; -struct v4lcontrol_data *v4lcontrol_create (int fd,int always_needs_conversion); +struct v4lcontrol_data *v4lcontrol_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops,int always_needs_conversion);void v4lcontrol_destroy (struct v4lcontrol_data *data);/* Functions used by v4lprocessing to get the control state */
lib/libv4lconvert/libv4lconvert-priv.h +2 -0
@@ -65,6 +65,8 @@ struct v4lconvert_data {unsigned char *convert_pixfmt_buf;struct v4lcontrol_data *control;struct v4lprocessing_data *processing; +struct libv4l2_dev_ops *dev_ops; +void *dev_ops_priv;/* Data for external decompression helpers code */ pid_t decompress_pid;
lib/libv4lconvert/libv4lconvert.c +23 -11
@@ -91,7 +91,8 @@ static const int v4lconvert_crop_res[][2] = { { 176, 144 }, }; -struct v4lconvert_data *v4lconvert_create (int fd) +struct v4lconvert_data *v4lconvert_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops) {int i, j;struct v4lconvert_data *data =calloc (1 ,sizeof (struct v4lconvert_data ));
@@ -107,6 +108,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) } data->fd = fd; + data->dev_ops = dev_ops; + data->dev_ops_priv = dev_ops_priv; data->decompress_pid =-1 ;/* Check supported formats */
@@ -115,7 +118,7 @@ struct v4lconvert_data *v4lconvert_create(int fd) fmt.index = i; -if (SYS_IOCTL (data->fd,VIDIOC_ENUM_FMT , &fmt)) +if (data->dev_ops->ioctl (data->dev_ops_priv, data->fd,VIDIOC_ENUM_FMT , &fmt))break ;for (j =0 ; j <ARRAY_SIZE (supported_src_pixfmts); j++)
@@ -134,7 +137,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) data->no_formats = i;/* Check if this cam has any special flags */ -if (SYS_IOCTL (data->fd,VIDIOC_QUERYCAP , &cap) ==0 ) { +if (data->dev_ops->ioctl (data->dev_ops_priv, + data->fd,VIDIOC_QUERYCAP , &cap) ==0 ) {if (!strcmp ((char *)cap.driver,"uvcvideo" )) data->flags |=V4LCONVERT_IS_UVC ;
@@ -142,7 +146,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) always_needs_conversion =0 ; } - data->control =v4lcontrol_create (fd, always_needs_conversion); + data->control =v4lcontrol_create (fd, dev_ops_priv, dev_ops, + always_needs_conversion);if (!data->control) {free (data);return NULL ;
@@ -205,7 +210,8 @@ int v4lconvert_enum_fmt(struct v4lconvert_data *data, struct v4l2_fmtdesc *fmt)if (fmt->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE || (!v4lconvert_supported_dst_fmt_only (data) && fmt->index < data->no_formats)) -return SYS_IOCTL (data->fd,VIDIOC_ENUM_FMT , fmt); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FMT , fmt);for (i =0 ; i <ARRAY_SIZE (supported_dst_pixfmts); i++) if (v4lconvert_supported_dst_fmt_only(data) ||
@@ -313,7 +319,8 @@ static int v4lconvert_do_try_format(struct v4lconvert_data *data, try_fmt = *dest_fmt; try_fmt.fmt.pix.pixelformat = supported_src_pixfmts[i].fmt; -if (!SYS_IOCTL (data->fd,VIDIOC_TRY_FMT , &try_fmt)) { +if (!data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_TRY_FMT , &try_fmt)) {if (try_fmt.fmt.pix.pixelformat == supported_src_pixfmts[i].fmt) {int size_x_diff =abs ((int )try_fmt.fmt.pix.width - (int )dest_fmt->fmt.pix.width);
@@ -381,7 +388,8 @@ int v4lconvert_try_format(struct v4lconvert_data *data,if (!v4lconvert_supported_dst_format (dest_fmt->fmt.pix.pixelformat) || dest_fmt->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE ||v4lconvert_do_try_format (data, &try_dest, &try_src)) { - result =SYS_IOCTL (data->fd,VIDIOC_TRY_FMT , dest_fmt); + result = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_TRY_FMT , dest_fmt);if (src_fmt) *src_fmt = *dest_fmt;return result;
@@ -1236,7 +1244,8 @@ static void v4lconvert_get_framesizes(struct v4lconvert_data *data,for (i =0 ; ; i++) { frmsize.index = i; -if (SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMESIZES , &frmsize)) +if (data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMESIZES , &frmsize))break ;/* We got a framesize, check we don't have the same one already */
@@ -1296,7 +1305,8 @@ int v4lconvert_enum_framesizes(struct v4lconvert_data *data, errno =EINVAL ;return -1 ; } -return SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMESIZES , frmsize); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMESIZES , frmsize); }if (frmsize->index >= data->no_framesizes) {
@@ -1332,7 +1342,8 @@ int v4lconvert_enum_frameintervals(struct v4lconvert_data *data, errno =EINVAL ;return -1 ; } - res =SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMEINTERVALS , frmival); + res = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMEINTERVALS , frmival);if (res)V4LCONVERT_ERR ("%s\n" ,strerror (errno));return res;
@@ -1377,7 +1388,8 @@ int v4lconvert_enum_frameintervals(struct v4lconvert_data *data, frmival->pixel_format = src_fmt.fmt.pix.pixelformat; frmival->width = src_fmt.fmt.pix.width; frmival->height = src_fmt.fmt.pix.height; - res =SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMEINTERVALS , frmival); + res = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMEINTERVALS , frmival);if (res) {int dest_pixfmt = dest_fmt.fmt.pix.pixelformat;int src_pixfmt = src_fmt.fmt.pix.pixelformat;
Signature · 1 line
1.7.3.1
Hi Hans,
any comments on that?
Regards
Yordan
Quoted 63 lines · Yordan Kamenov
Hi Hans,
here is third version of plugin support for libv4l2.
Changes in v3:
* Pass opened fd to the plugin instead of filename
* Plugin private data is returned by init call and is passed as argument in ioctl/read/close (remove libv4l2_set/get_plugindata functions)
* Plugin do not handle mmap/munmap--------------------------------------------------------------------------
Changes in v2:* Remove calls of
v4l2_plugin_foofunctions in the beginning of corespondingv4l2_foofunctions and instead replaceSYS_FOOcalls.
* Add tov4l2_dev_infodevice operation structure which can hold plugin callbacks or dyrectsyscall(SYS_foo, ...)calls.
* Under libv4lconvert also replaceSYS_FOOcals with device operations. This required also to adddev_opsfield tov4lconvert_dataandv4lcontrol_data.---------------------------------------------------------------------------
v1:Here is initial version of plugin support for libv4l, based on your RFC.
It is provided by functions v4l2_plugin_[open,close,etc]. When
open()is called libv4l dlopens files in/usr/lib/libv4l/plugins1 at a time and callopen()callback passing through the applications parameters unmodified. If a plugin is relevant for the specified device node, it can indicate so by returning a value other then -1 (the actual file descriptor).As soon as a plugin returns another value then -1 plugin loading stops and information about it (fd and corresponding library handle) is stored. For each function v4l2_[ioctl,read,close,etc] is called corresponding v4l2_plugin_* function which looks if there is loaded plugin for that file and call it's callbacks. v4l2_plugin_* functions indicate by their first argument if plugin was used, and if it was not then v4l2_* functions proceed with their usual behavior.
Yordan Kamenov (1):
libv4l: Add plugin support to libv4llib/include/libv4l2-plugin.h | 36 ++++++ lib/include/libv4lconvert.h | 5 +- lib/libv4l2/Makefile | 4 +- lib/libv4l2/libv4l2-priv.h | 10 ++ lib/libv4l2/libv4l2.c | 90 ++++++++++---- lib/libv4l2/v4l2-plugin.c | 160 ++++++++++++++++++++++++ lib/libv4l2/v4l2convert.c | 9 -- lib/libv4lconvert/control/libv4lcontrol-priv.h | 4 + lib/libv4lconvert/control/libv4lcontrol.c | 35 ++++-- lib/libv4lconvert/control/libv4lcontrol.h | 5 +- lib/libv4lconvert/libv4lconvert-priv.h | 2 + lib/libv4lconvert/libv4lconvert.c | 34 ++++-- 12 files changed, 333 insertions(+), 61 deletions(-) create mode 100644 lib/include/libv4l2-plugin.h create mode 100644 lib/libv4l2/v4l2-plugin.c
Hi,
Quoted 4 lines · Yordan Kamenov
Hi Hans,
any comments on that?
I looked at globally immediately after you send it, summary of that look: looks good, but I still spotted some minor issues.
I'm still trying to make some time for a more detailed look. I hope to do that real soon now, esp. as I would like to have this reviewed before the Warschau meeting.
Thanks & Regards,
Hans
Quoted 69 lines
Regards
YordanQuoted 62 lines · Yordan Kamenov
Hi Hans,
here is third version of plugin support for libv4l2.
Changes in v3:
* Pass opened fd to the plugin instead of filename
* Plugin private data is returned by init call and is passed as argument in ioctl/read/close (remove libv4l2_set/get_plugindata functions)
* Plugin do not handle mmap/munmap--------------------------------------------------------------------------
Changes in v2:* Remove calls of
v4l2_plugin_foofunctions in the beginning of corespondingv4l2_foofunctions and instead replaceSYS_FOOcalls.
* Add tov4l2_dev_infodevice operation structure which can hold plugin callbacks or dyrectsyscall(SYS_foo, ...)calls.
* Under libv4lconvert also replaceSYS_FOOcals with device operations. This required also to adddev_opsfield tov4lconvert_dataandv4lcontrol_data.---------------------------------------------------------------------------
v1:Here is initial version of plugin support for libv4l, based on your RFC.
It is provided by functions v4l2_plugin_[open,close,etc]. When
open()is called libv4l dlopens files in/usr/lib/libv4l/plugins1 at a time and callopen()callback passing through the applications parameters unmodified. If a plugin is relevant for the specified device node, it can indicate so by returning a value other then -1 (the actual file descriptor).As soon as a plugin returns another value then -1 plugin loading stops and information about it (fd and corresponding library handle) is stored. For each function v4l2_[ioctl,read,close,etc] is called corresponding v4l2_plugin_* function which looks if there is loaded plugin for that file and call it's callbacks. v4l2_plugin_* functions indicate by their first argument if plugin was used, and if it was not then v4l2_* functions proceed with their usual behavior.
Yordan Kamenov (1):
libv4l: Add plugin support to libv4l
lib/include/libv4l2-plugin.h| 36 ++++++lib/include/libv4lconvert.h| 5 +-lib/libv4l2/Makefile| 4 +-lib/libv4l2/libv4l2-priv.h| 10 ++lib/libv4l2/libv4l2.c| 90 ++++++++++----lib/libv4l2/v4l2-plugin.c| 160 ++++++++++++++++++++++++lib/libv4l2/v4l2convert.c| 9 --lib/libv4lconvert/control/libv4lcontrol-priv.h| 4 +lib/libv4lconvert/control/libv4lcontrol.c| 35 ++++--lib/libv4lconvert/control/libv4lcontrol.h| 5 +-lib/libv4lconvert/libv4lconvert-priv.h| 2 +lib/libv4lconvert/libv4lconvert.c| 34 ++++--12 files changed, 333 insertions(+), 61 deletions(-)create mode 100644
lib/include/libv4l2-plugin.h
create mode 100644lib/libv4l2/v4l2-plugin.c
Re: [PATCH 1/1 v3] libv4l: Add plugin support to libv4l
In reply to Yordan KamenovHi,
First of all my apologies for taking so long to get around to reviewing this.
Over all it looks good, I've put some small remarks inline, if you fix these I can merge this. I wonder though, given the recent limbo around Nokia's change of focus, if there are any plans to actually move forward with a plugin using this... ?
The reason I'm asking is that adding the plugin framework if nothing is going to use it seems a bit senseless.
Regards,
Hans
Quoted 50 lines · Yordan Kamenov
A libv4l2 plugin will sit in between libv4l2 itself and the actual
/dev/videodevice node a fd refers to. It will be called each time libv4l2 wants to do an operation (read/write/ioctl) on the actual/dev/videonode in question.Signed-off-by Yordan Kamenov<[email protected]>--- lib/include/libv4l2-plugin.h | 36 ++++++ lib/include/libv4lconvert.h | 5 +- lib/libv4l2/Makefile | 4 +- lib/libv4l2/libv4l2-priv.h | 10 ++ lib/libv4l2/libv4l2.c | 90 ++++++++++---- lib/libv4l2/v4l2-plugin.c | 160 ++++++++++++++++++++++++ lib/libv4l2/v4l2convert.c | 9 -- lib/libv4lconvert/control/libv4lcontrol-priv.h | 4 + lib/libv4lconvert/control/libv4lcontrol.c | 35 ++++-- lib/libv4lconvert/control/libv4lcontrol.h | 5 +- lib/libv4lconvert/libv4lconvert-priv.h | 2 + lib/libv4lconvert/libv4lconvert.c | 34 ++++-- 12 files changed, 333 insertions(+), 61 deletions(-)create mode 100644
lib/include/libv4l2-plugin.h
create mode 100644lib/libv4l2/v4l2-plugin.clib/include/libv4l2-plugin.h new file +21
-0@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2010 Nokia Corporation<[email protected]> + +* 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 +* Lesser 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 +*/ + +#ifndef __LIBV4L2_PLUGIN_H +#define __LIBV4L2_PLUGIN_H +
lib/include/libv4l2-plugin.h line 31
Quoted 10 lines
lib/include/libv4l2-plugin.h new file +10
-0+#include <sys/types.h> + +/* Structure libv4l2_dev_ops holds the calls from libv4ls to video nodes. +They can be normal open/close/ioctl etc. or any of them may be replaced +with a callback by a loaded plugin. +*/ + +struct libv4l2_dev_ops { +void * (*init)(int fd); +int (*close)(void *dev_ops_priv);
Since you don't error check the close callback's return value in the single place you call it, you might just as well make it void
Quoted 244 lines
lib/include/libv4l2-plugin.h new file +5
-0+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); +}; + +#endif lib/include/libv4lconvert.h +4
-1@@ -38,6 +38,8 @@#include <linux/videodev2.h> +#include "libv4l2-plugin.h" +#ifdef __cplusplusextern "C" {#endif /* __cplusplus */ @@ -50,7 +52,8 @@ extern "C" {struct v4lconvert_data ; -LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create(int fd); +LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create(int fd, +void *dev_ops_priv,struct libv4l2_dev_ops *dev_ops); LIBV4L_PUBLIC void v4lconvert_destroy(struct v4lconvert_data *data);/* When doing flipping / rotating / video-processing, only supported lib/libv4l2/Makefile +2
-2@@ -1,8 +1,8 @@ override CPPFLAGS += -I../include -fvisibility=hidden -LIBS_libv4l2 = -lpthread +LIBS_libv4l2 = -lpthread -ldl -V4L2_OBJS = libv4l2.o log.o +V4L2_OBJS = libv4l2.o v4l2-plugin.o log.o V4L2CONVERT = v4l2convert.so V4L2CONVERT_O = v4l2convert.o libv4l2.so TARGETS = $(V4L2_LIB) libv4l2.pclib/libv4l2/libv4l2-priv.h +10
-0@@ -85,8 +85,18 @@ struct v4l2_dev_info {/* buffer when doing conversion and using read() for read() */ int readbuf_size;unsigned char *readbuf; +struct libv4l2_dev_ops *dev_ops; +/* plugin info */ +void *plugin_library; +void *dev_ops_priv; }; +void v4l2_plugin_init (int fd,void **plugin_lib_ret,void **plugin_priv_ret, +struct libv4l2_dev_ops **dev_ops_ret); +void v4l2_plugin_cleanup (void *plugin_priv,void *plugin_lib, +struct libv4l2_dev_ops *dev_ops); + +/* From log.c */ void v4l2_log_ioctl (unsigned long int request,void *arg,int result);lib/libv4l2/libv4l2.c +40
-14@@ -67,6 +67,7 @@#include <sys/stat.h> #include "libv4l2.h" #include "libv4l2-priv.h" +#include "libv4l2-plugin.h" /* Note these flags are stored together with the flags passed to v4l2_fd_open() in v4l2_dev_info's flags member, so care should be taken that the do not @@ -102,7 +103,8 @@ static int v4l2_request_read_buffers(int index) devices[index].nreadbuffers; req.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; req.memory =V4L2_MEMORY_MMAP ; - result =SYS_IOCTL (devices[index].fd,VIDIOC_REQBUFS ,&req); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_REQBUFS ,&req);if (result<0 ) {int saved_err = errno;@@ -131,7 +133,8 @@ static void v4l2_unrequest_read_buffers(int index) req.count =0 ; req.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; req.memory =V4L2_MEMORY_MMAP ; -if (SYS_IOCTL (devices[index].fd,VIDIOC_REQBUFS ,&req)<0 ) +if (devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_REQBUFS ,&req)<0 )return ; devices[index].no_frames =MIN (req.count,V4L2_MAX_NO_FRAMES );@@ -152,7 +155,8 @@ static int v4l2_map_buffers(int index) buf.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; buf.memory =V4L2_MEMORY_MMAP ; buf.index = i; - result =SYS_IOCTL (devices[index].fd,VIDIOC_QUERYBUF ,&buf); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_QUERYBUF ,&buf);if (result) {int saved_err = errno;@@ -202,7 +206,8 @@ static int v4l2_streamon(int index)enum v4l2_buf_type type =V4L2_BUF_TYPE_VIDEO_CAPTURE ;if (!(devices[index].flags&V4L2_STREAMON )) { - result =SYS_IOCTL (devices[index].fd,VIDIOC_STREAMON ,&type); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_STREAMON ,&type);if (result) {int saved_err = errno;@@ -223,7 +228,8 @@ static int v4l2_streamoff(int index)enum v4l2_buf_type type =V4L2_BUF_TYPE_VIDEO_CAPTURE ;if (devices[index].flags&V4L2_STREAMON ) { - result =SYS_IOCTL (devices[index].fd,VIDIOC_STREAMOFF ,&type); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_STREAMOFF ,&type);if (result) {int saved_err = errno;@@ -252,7 +258,8 @@ static int v4l2_queue_read_buffer(int index, int buffer_index) buf.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; buf.memory =V4L2_MEMORY_MMAP ; buf.index = buffer_index; - result =SYS_IOCTL (devices[index].fd,VIDIOC_QBUF ,&buf); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_QBUF ,&buf);if (result) {int saved_err = errno;@@ -277,7 +284,8 @@ static int v4l2_dequeue_and_convert(int index, struct v4l2_buffer *buf,return result; do { - result = SYS_IOCTL(devices[index].fd, VIDIOC_DQBUF, buf); + result = devices[index].dev_ops->ioctl(devices[index].dev_ops_priv, + devices[index].fd, VIDIOC_DQBUF, buf); if (result) { if (errno != EAGAIN) { int saved_err = errno;@@ -356,7 +364,8 @@ static int v4l2_read_and_convert(int index, unsigned char *dest, int dest_size) } do { - result = SYS_READ(devices[index].fd, devices[index].readbuf, buf_size); + result = devices[index].dev_ops->read(devices[index].dev_ops_priv, + devices[index].fd, devices[index].readbuf, buf_size); if (result<= 0) { if (result&& errno != EAGAIN) { int saved_err = errno;@@ -496,7 +505,8 @@ static int v4l2_buffers_mapped(int index) buf.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; buf.memory =V4L2_MEMORY_MMAP ; buf.index = i; -if (SYS_IOCTL (devices[index].fd,VIDIOC_QUERYBUF ,&buf)) { +if (devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_QUERYBUF ,&buf)) {int saved_err = errno;V4L2_LOG_ERR ("querying buffer %u: %s\n" , i,strerror (errno));@@ -561,6 +571,11 @@ int v4l2_fd_open(int fd, int v4l2_flags)struct v4l2_capability cap;struct v4l2_format fmt;struct v4lconvert_data *convert; +struct libv4l2_dev_ops *dev_ops; +void *plugin_library; +void *plugin_data; + +v4l2_plugin_init (fd,&plugin_library,&plugin_data,&dev_ops);/* If no log file was set by the app, see if one was specified through the environment */ @@ -571,9 +586,10 @@ int v4l2_fd_open(int fd, int v4l2_flags) }/* check that this is an v4l2 device */ -if (SYS_IOCTL (fd,VIDIOC_QUERYCAP ,&cap)) { +if (dev_ops->ioctl (plugin_data, fd,VIDIOC_QUERYCAP ,&cap)) {int saved_err = errno; +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops);V4L2_LOG_ERR ("getting capabilities: %s\n" ,strerror (errno)); errno = saved_err;return -1 ;@@ -581,29 +597,38 @@ int v4l2_fd_open(int fd, int v4l2_flags)/* we only add functionality for video capture devices */ if (!(cap.capabilities&V4L2_CAP_VIDEO_CAPTURE ) || - !(cap.capabilities& (V4L2_CAP_STREAMING |V4L2_CAP_READWRITE ))) + !(cap.capabilities& (V4L2_CAP_STREAMING |V4L2_CAP_READWRITE ))) { +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops);return fd; + }/* Get current cam format */ fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; -if (SYS_IOCTL (fd,VIDIOC_G_FMT ,&fmt)) { +if (dev_ops->ioctl (plugin_data, fd,VIDIOC_G_FMT ,&fmt)) {int saved_err = errno; +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops);V4L2_LOG_ERR ("getting pixformat: %s\n" ,strerror (errno)); errno = saved_err;return -1 ; }/* init libv4lconvert */ - convert =v4lconvert_create (fd); -if (!convert) + convert =v4lconvert_create (fd, plugin_data, dev_ops); +if (!convert) { +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops);return -1 ; + }/* So we have a v4l2 capture device, register it in our devices array */ pthread_mutex_lock (&v4l2_open_mutex);for (index =0 ; index<V4L2_MAX_DEVICES ; index++)if (devices[index].fd ==-1 ) { devices[index].fd = fd; + + devices[index].plugin_library = plugin_library; + devices[index].dev_ops_priv = plugin_data; + devices[index].dev_ops = dev_ops;break ; }pthread_mutex_unlock (&v4l2_open_mutex);@@ -611,6 +636,7 @@ int v4l2_fd_open(int fd, int v4l2_flags)if (index ==V4L2_MAX_DEVICES ) {V4L2_LOG_ERR ("attempting to open more then %d video devices\n" ,V4L2_MAX_DEVICES ); +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops); errno =EBUSY ;return -1 ; }
lib/libv4l2/libv4l2.c int v4l2_close(int fd) · line 721
Quoted 6 lines
lib/libv4l2/libv4l2.c +3
-0@@ -690,6 +716,9 @@ int v4l2_close(int fd)if (index ==-1 )return SYS_CLOSE (fd); +v4l2_plugin_cleanup (devices[index].dev_ops_priv, + devices[index].plugin_library, devices[index].dev_ops); +
This should be moved lower, to were the actual fd gets closed, if the fd was opened multiple times (through dup) the plugin stuff should not be cleaned up yet...
Quoted 12 lines
lib/libv4l2/libv4l2.c +1
-0/* Abuse stream_lock to stop 2 closes from racing and trying to free the resources twice */ pthread_mutex_lock (&devices[index].stream_lock);@@ -808,6 +837,7 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)va_list ap;int result, index, saved_err;int is_capture_request =0 , stream_needs_locking =0 ; +void *plugin_data;va_start (ap, request); arg = va_arg(ap, void *);
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 853
Quoted 7 lines
lib/libv4l2/libv4l2.c +1
-0@@ -817,6 +847,7 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)if (index ==-1 )return SYS_IOCTL (fd, request, arg); + plugin_data = devices[index].dev_ops_priv;/* Appearantly the kernel and / or glibc ignore the 32 most significant bits when long = 64 bits, and some applications pass an int holding the req to ioctl, causing it to get sign extended, depending upon this behavior */
You don't seem to use plugin_data consistently in the function, see below.
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 916
Quoted 9 lines
lib/libv4l2/libv4l2.c +1
-1@@ -879,7 +910,7 @@ int v4l2_ioctl(int fd, unsigned long int request, ...) }if (!is_capture_request) { - result =SYS_IOCTL (fd, request, arg); + result = devices[index].dev_ops->ioctl (plugin_data, fd, request, arg); saved_err = errno;v4l2_log_ioctl (request, arg, result); errno = saved_err;
This is the 1 of places where you actually use plugin_data, either use it everywhere, or drop it.
Quoted 72 lines
lib/libv4l2/libv4l2.c +14
-8@@ -927,7 +958,8 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)case VIDIOC_QUERYCAP : {struct v4l2_capability *cap = arg; - result =SYS_IOCTL (devices[index].fd,VIDIOC_QUERYCAP , cap); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_QUERYCAP , cap);if (result ==0 )/* We always support read() as we fake it using mmap mode */ cap->capabilities |=V4L2_CAP_READWRITE ;@@ -977,8 +1009,8 @@ int v4l2_ioctl(int fd, unsigned long int request, ...) }if (devices[index].flags&V4L2_DISABLE_CONVERSION ) { - result =SYS_IOCTL (devices[index].fd,VIDIOC_TRY_FMT , - dest_fmt); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_TRY_FMT , dest_fmt); src_fmt = *dest_fmt; }else { result = v4lconvert_try_format(devices[index].convert, dest_fmt,@@ -1018,7 +1050,8 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)break ; req_pix_fmt = src_fmt.fmt.pix; - result =SYS_IOCTL (devices[index].fd,VIDIOC_S_FMT ,&src_fmt); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_S_FMT ,&src_fmt);if (result) { saved_err = errno;V4L2_LOG_ERR ("setting pixformat: %s\n" ,strerror (errno));@@ -1067,7 +1100,8 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)if (req->count>V4L2_MAX_NO_FRAMES ) req->count =V4L2_MAX_NO_FRAMES ; - result =SYS_IOCTL (devices[index].fd,VIDIOC_REQBUFS , req); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_REQBUFS , req);if (result<0 )break ; result =0 ;/* some drivers return the number of buffers on success */ @@ -1088,7 +1122,8 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)/* Do a real query even when converting to let the driver fill in things like buf->field */ - result =SYS_IOCTL (devices[index].fd,VIDIOC_QUERYBUF , buf); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_QUERYBUF , buf);if (result || !v4l2_needs_conversion (index))break ;@@ -1115,7 +1150,8 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)break ; } - result =SYS_IOCTL (devices[index].fd,VIDIOC_QBUF , arg); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_QBUF , arg);break ;case VIDIOC_DQBUF : {@@ -1128,7 +1164,8 @@ int v4l2_ioctl(int fd, unsigned long int request, ...) }if (!v4l2_needs_conversion (index)) { - result =SYS_IOCTL (devices[index].fd,VIDIOC_DQBUF , buf); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_DQBUF , buf);if (result) {int saved_err = errno;
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 1230
Quoted 8 lines
lib/libv4l2/libv4l2.c +1
-1@@ -1187,7 +1224,7 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)break ;default : - result =SYS_IOCTL (fd, request, arg); + result = devices[index].dev_ops->ioctl (plugin_data, fd, request, arg);break ; }
This is the only other place you use plugin_data.
Quoted 13 lines
lib/libv4l2/libv4l2.c +3
-0@@ -1206,18 +1243,21 @@ ssize_t v4l2_read(int fd, void *dest, size_t n) {ssize_t result;int saved_errno; +void *plugin_data;int index =v4l2_get_index (fd);if (index ==-1 )return SYS_READ (fd, dest, n); + plugin_data = devices[index].dev_ops_priv; +pthread_mutex_lock (&devices[index].stream_lock);
lib/libv4l2/libv4l2.c ssize_t v4l2_read(int fd, void *dest, size_t n) · line 1263
Quoted 10 lines
lib/libv4l2/libv4l2.c +1
-1/* When not converting and the device supports read let the kernel handle it */ if ((devices[index].flags&V4L2_SUPPORTS_READ )&& !v4l2_needs_conversion (index)) { - result =SYS_READ (fd, dest, n); + result = devices[index].dev_ops->read (plugin_data, fd, dest, n); goto leave; }
I so no need for the plugin_data variable here, just use devices[index].dev_ops_priv directly when you call dev_ops->read.
Quoted 55 lines
lib/libv4l2/v4l2-plugin.c new file +49
-0@@ -0,0 +1,160 @@ +/* +* Copyright (C) 2010 Nokia Corporation<[email protected]> + +* 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 +* Lesser 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 <stdarg.h> +#include <dlfcn.h> +#include <fcntl.h> +#include <glob.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include "libv4l2.h" +#include "libv4l2-priv.h" +#include "libv4l2-plugin.h" + +/* libv4l plugin support: +it is provided by functions v4l2_plugin_[open,close,etc]. + +When open() is called libv4l dlopens files in /usr/lib[64]/libv4l/plugins +1 at a time and call open callback passing through the applications +parameters unmodified. + +If a plugin is relevant for the specified device node, it can indicate so +by returning a value other then -1 (the actual file descriptor). +As soon as a plugin returns another value then -1 plugin loading stops and +information about it (fd and corresponding library handle) is stored. For +each function v4l2_[ioctl,read,close,etc] is called corresponding +v4l2_plugin_* function which looks if there is loaded plugin for that file +and call it's callbacks. + +v4l2_plugin_* function indicates by it's first argument if plugin was used, +and if it was not then v4l2_* functions proceed with their usual behavior. +*/ + +#define PLUGINS_PATTERN "/usr/lib/libv4l/plugins/*.so" +
lib/libv4l2/v4l2-plugin.c line 59
Quoted 10 lines
lib/libv4l2/v4l2-plugin.c new file +10
-0+static void *dev_init (int fd) +{ +return NULL ; +} + +static int dev_close (void *dev_ops_priv) +{ +return -1 ; +} +
-1 is an error? Why would the default plugin always return error on close? Anyways as said before just make it void.
lib/libv4l2/v4l2-plugin.c line 69
Quoted 10 lines
lib/libv4l2/v4l2-plugin.c new file +10
-0+static int dev_ioctl (void *dev_ops_priv,int fd,unsigned long cmd,void *arg) +{ +return syscall (SYS_ioctl, (int )(fd), (unsigned long )(cmd), + (void *)(arg)); +} + +static ssize_t dev_read (void *dev_ops_priv,int fd,void *buf,size_t len) +{ +return syscall (SYS_read, (int )(fd), (void *)(buf), (size_t )(len)); +}
Please use the SYS_IOCTL and SYS_READ macro's here for compat with freebsd.
Quoted 108 lines
lib/libv4l2/v4l2-plugin.c new file +91
-0+ + +struct libv4l2_dev_ops default_operations = { + .init =&dev_init, + .close =&dev_close, + .ioctl =&dev_ioctl, + .read =&dev_read +}; + +void v4l2_plugin_init (int fd,void **plugin_lib_ret,void **plugin_priv_ret, +struct libv4l2_dev_ops **dev_ops_ret) +{ +char *error; +int glob_ret, plugin_num; +void *plugin_library =NULL ; +struct libv4l2_dev_ops *libv4l2_plugin =NULL ; +glob_t globbuf; + + *dev_ops_ret =&default_operations; + + glob_ret =glob (PLUGINS_PATTERN ,0 ,NULL ,&globbuf); + +if (glob_ret ==GLOB_NOSPACE ) { + *plugin_lib_ret =NULL ; + *plugin_priv_ret =NULL ; +return ; + } + +if (glob_ret ==GLOB_ABORTED || glob_ret ==GLOB_NOMATCH ) { + *plugin_lib_ret =NULL ; + *plugin_priv_ret =NULL ; + goto leave; + } + +for (plugin_num =0 ; plugin_num< globbuf.gl_pathc; plugin_num++) { + +V4L2_LOG ("PLUGIN: dlopen(%s);\n" , globbuf.gl_pathv[plugin_num]); + + plugin_library =dlopen (globbuf.gl_pathv[plugin_num], +RTLD_LAZY ); + +if (!plugin_library) +continue ; + +dlerror ();/* Clear any existing error */ + libv4l2_plugin = (struct libv4l2_dev_ops *) +dlsym (plugin_library,"libv4l2_plugin" ); + + error =dlerror (); +if (error !=NULL ) { +V4L2_LOG_ERR ("PLUGIN: dlsym failed: %s\n" , error); +dlclose (plugin_library); + +continue ; + } + + *plugin_priv_ret =NULL ; +if (libv4l2_plugin->init) + *plugin_priv_ret = libv4l2_plugin->init (fd); + +if (!*plugin_priv_ret) { +V4L2_LOG ("PLUGIN: plugin open() returned NULL\n" ); +dlclose (plugin_library); + *plugin_lib_ret =NULL ; +continue ; + } + + (*dev_ops_ret)->init = libv4l2_plugin->init; +if (libv4l2_plugin->close !=NULL ) + (*dev_ops_ret)->close = libv4l2_plugin->close; +if (libv4l2_plugin->ioctl !=NULL ) + (*dev_ops_ret)->ioctl = libv4l2_plugin->ioctl; +if (libv4l2_plugin->read !=NULL ) + (*dev_ops_ret)->read = libv4l2_plugin->read; + +break ; + + } + +leave: +globfree (&globbuf); +} + +void v4l2_plugin_cleanup (void *plugin_priv,void *plugin_lib, +struct libv4l2_dev_ops *dev_ops) +{ +if (plugin_priv) { + dev_ops->close (plugin_priv); +dlclose (plugin_lib); + } +}lib/libv4l2/v4l2convert.c +0
-2@@ -46,7 +46,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...) {int fd; -struct v4l2_capability cap;int v4l_device =0 ;/* check if we're opening a video4linux2 device */ @@ -76,14 +75,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...)if (fd ==-1 || !v4l_device)return fd; -/* check that this is an v4l2 device, libv4l2 only supports v4l2 devices */
lib/libv4l2/v4l2convert.c LIBV4L_PUBLIC int open(const char *file, int oflag, ...) · line 80
Quoted 10 lines
lib/libv4l2/v4l2convert.c +0
-7-if (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,0 );
Hmm, why are you removing this check ?
Quoted 292 lines
lib/libv4lconvert/control/libv4lcontrol-priv.h +4
-0@@ -22,6 +22,8 @@#ifndef __LIBV4LCONTROL_PRIV_H#define __LIBV4LCONTROL_PRIV_H +#include "libv4l2-plugin.h" +#define V4LCONTROL_SHM_SIZE 4096#define V4LCONTROL_SUPPORTS_NEXT_CTRL 0x01@@ -37,6 +39,8 @@ struct v4lcontrol_data {unsigned int *shm_values;/* shared memory control value store */ unsigned int old_values[V4LCONTROL_COUNT ];/* for controls_changed() */ const struct v4lcontrol_flags_info *flags_info; +struct libv4l2_dev_ops *dev_ops; +void *dev_ops_priv; };struct v4lcontrol_flags_info {lib/libv4lconvert/control/libv4lcontrol.c +23
-12@@ -701,7 +701,8 @@ static void v4lcontrol_get_flags_from_db(struct v4lcontrol_data *data, } } -struct v4lcontrol_data *v4lcontrol_create (int fd,int always_needs_conversion) +struct v4lcontrol_data *v4lcontrol_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops,int always_needs_conversion) {int shm_fd;int i, rc, got_usb_ids, init =0 ;@@ -721,10 +722,12 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion) } data->fd = fd; + data->dev_ops = dev_ops; + data->dev_ops_priv = dev_ops_priv;/* Check if the driver has indicated some form of flipping is needed */ -if ((SYS_IOCTL (data->fd,VIDIOC_G_INPUT ,&input.index) ==0 )&& - (SYS_IOCTL (data->fd,VIDIOC_ENUMINPUT ,&input) ==0 )) { +if ((data->dev_ops->ioctl (data->dev_ops_priv, data->fd,VIDIOC_G_INPUT ,&input.index) ==0 )&& + (data->dev_ops->ioctl (data->dev_ops_priv, data->fd,VIDIOC_ENUMINPUT ,&input) ==0 )) {if (input.status&V4L2_IN_ST_HFLIP ) data->flags |=V4LCONTROL_HFLIPPED ;if (input.status&V4L2_IN_ST_VFLIP )@@ -741,7 +744,8 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion) data->flags =strtol (s,NULL ,0 ); ctrl.id =V4L2_CTRL_FLAG_NEXT_CTRL ; -if (SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl) ==0 ) +if (data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl) ==0 ) data->priv_flags |=V4LCONTROL_SUPPORTS_NEXT_CTRL ;/* If the device always needs conversion, we can add fake controls at no cost @@ -749,7 +753,8 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)if (always_needs_conversion ||v4lcontrol_needs_conversion (data)) {for (i =0 ; i<V4LCONTROL_AUTO_ENABLE_COUNT ; i++) { ctrl.id = fake_controls[i].id; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl);if (rc ==-1 || (rc ==0 && (ctrl.flags&V4L2_CTRL_FLAG_DISABLED ))) data->controls |=1 << i; }@@ -761,17 +766,20 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)different sensors with / without autogain or the necessary controls. */ while (data->flags&V4LCONTROL_WANTS_AUTOGAIN ) { ctrl.id =V4L2_CID_AUTOGAIN ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl);if (rc ==0 && !(ctrl.flags&V4L2_CTRL_FLAG_DISABLED ))break ; ctrl.id =V4L2_CID_EXPOSURE ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl);if (rc !=0 || (ctrl.flags&V4L2_CTRL_FLAG_DISABLED ))break ; ctrl.id =V4L2_CID_GAIN ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl);if (rc !=0 || (ctrl.flags&V4L2_CTRL_FLAG_DISABLED ))break ;@@ -788,7 +796,7 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)if (data->controls ==0 )return data;/* No need to create a shared memory segment */ -if (SYS_IOCTL (fd,VIDIOC_QUERYCAP ,&cap)) { +if (data->dev_ops->ioctl (data->dev_ops_priv, fd,VIDIOC_QUERYCAP ,&cap)) {perror ("libv4lcontrol: error querying device capabilities" ); goto error; }@@ -974,7 +982,8 @@ int v4lcontrol_vidioc_queryctrl(struct v4lcontrol_data *data, void *arg) }/* find out what the kernel driver would respond. */ - retval =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL , arg); + retval = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL , arg);if ((data->priv_flags&V4LCONTROL_SUPPORTS_NEXT_CTRL )&& (orig_id&V4L2_CTRL_FLAG_NEXT_CTRL )) {@@ -1011,7 +1020,8 @@ int v4lcontrol_vidioc_g_ctrl(struct v4lcontrol_data *data, void *arg)return 0 ; } -return SYS_IOCTL (data->fd,VIDIOC_G_CTRL , arg); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_G_CTRL , arg); }int v4lcontrol_vidioc_s_ctrl (struct v4lcontrol_data *data,void *arg)@@ -1032,7 +1042,8 @@ int v4lcontrol_vidioc_s_ctrl(struct v4lcontrol_data *data, void *arg)return 0 ; } -return SYS_IOCTL (data->fd,VIDIOC_S_CTRL , arg); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_S_CTRL , arg); }int v4lcontrol_get_flags (struct v4lcontrol_data *data)lib/libv4lconvert/control/libv4lcontrol.h +4
-1@@ -22,6 +22,8 @@#ifndef __LIBV4LCONTROL_H#define __LIBV4LCONTROL_H +#include "libv4l2-plugin.h" +/* Flags */ #define V4LCONTROL_HFLIPPED 0x01#define V4LCONTROL_VFLIPPED 0x02@@ -47,7 +49,8 @@ enum {struct v4lcontrol_data ; -struct v4lcontrol_data *v4lcontrol_create (int fd,int always_needs_conversion); +struct v4lcontrol_data *v4lcontrol_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops,int always_needs_conversion);void v4lcontrol_destroy (struct v4lcontrol_data *data);/* Functions used by v4lprocessing to get the control state */ lib/libv4lconvert/libv4lconvert-priv.h +2
-0@@ -65,6 +65,8 @@ struct v4lconvert_data {unsigned char *convert_pixfmt_buf;struct v4lcontrol_data *control;struct v4lprocessing_data *processing; +struct libv4l2_dev_ops *dev_ops; +void *dev_ops_priv;/* Data for external decompression helpers code */ pid_t decompress_pid;lib/libv4lconvert/libv4lconvert.c +23
-11@@ -91,7 +91,8 @@ static const int v4lconvert_crop_res[][2] = { { 176, 144 }, }; -struct v4lconvert_data *v4lconvert_create (int fd) +struct v4lconvert_data *v4lconvert_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops) {int i, j;struct v4lconvert_data *data =calloc (1 ,sizeof (struct v4lconvert_data ));@@ -107,6 +108,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) } data->fd = fd; + data->dev_ops = dev_ops; + data->dev_ops_priv = dev_ops_priv; data->decompress_pid =-1 ;/* Check supported formats */ @@ -115,7 +118,7 @@ struct v4lconvert_data *v4lconvert_create(int fd) fmt.index = i; -if (SYS_IOCTL (data->fd,VIDIOC_ENUM_FMT ,&fmt)) +if (data->dev_ops->ioctl (data->dev_ops_priv, data->fd,VIDIOC_ENUM_FMT ,&fmt))break ;for (j =0 ; j<ARRAY_SIZE (supported_src_pixfmts); j++)@@ -134,7 +137,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) data->no_formats = i;/* Check if this cam has any special flags */ -if (SYS_IOCTL (data->fd,VIDIOC_QUERYCAP ,&cap) ==0 ) { +if (data->dev_ops->ioctl (data->dev_ops_priv, + data->fd,VIDIOC_QUERYCAP ,&cap) ==0 ) {if (!strcmp ((char *)cap.driver,"uvcvideo" )) data->flags |=V4LCONVERT_IS_UVC ;@@ -142,7 +146,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) always_needs_conversion =0 ; } - data->control =v4lcontrol_create (fd, always_needs_conversion); + data->control =v4lcontrol_create (fd, dev_ops_priv, dev_ops, + always_needs_conversion);if (!data->control) {free (data);return NULL ;@@ -205,7 +210,8 @@ int v4lconvert_enum_fmt(struct v4lconvert_data *data, struct v4l2_fmtdesc *fmt)if (fmt->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE || (!v4lconvert_supported_dst_fmt_only (data)&& fmt->index< data->no_formats)) -return SYS_IOCTL (data->fd,VIDIOC_ENUM_FMT , fmt); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FMT , fmt);for (i =0 ; i<ARRAY_SIZE (supported_dst_pixfmts); i++) if (v4lconvert_supported_dst_fmt_only(data) ||@@ -313,7 +319,8 @@ static int v4lconvert_do_try_format(struct v4lconvert_data *data, try_fmt = *dest_fmt; try_fmt.fmt.pix.pixelformat = supported_src_pixfmts[i].fmt; -if (!SYS_IOCTL (data->fd,VIDIOC_TRY_FMT ,&try_fmt)) { +if (!data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_TRY_FMT ,&try_fmt)) {if (try_fmt.fmt.pix.pixelformat == supported_src_pixfmts[i].fmt) {int size_x_diff =abs ((int )try_fmt.fmt.pix.width - (int )dest_fmt->fmt.pix.width);@@ -381,7 +388,8 @@ int v4lconvert_try_format(struct v4lconvert_data *data,if (!v4lconvert_supported_dst_format (dest_fmt->fmt.pix.pixelformat) || dest_fmt->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE ||v4lconvert_do_try_format (data,&try_dest,&try_src)) { - result =SYS_IOCTL (data->fd,VIDIOC_TRY_FMT , dest_fmt); + result = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_TRY_FMT , dest_fmt);if (src_fmt) *src_fmt = *dest_fmt;return result;@@ -1236,7 +1244,8 @@ static void v4lconvert_get_framesizes(struct v4lconvert_data *data,for (i =0 ; ; i++) { frmsize.index = i; -if (SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMESIZES ,&frmsize)) +if (data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMESIZES ,&frmsize))break ;/* We got a framesize, check we don't have the same one already */ @@ -1296,7 +1305,8 @@ int v4lconvert_enum_framesizes(struct v4lconvert_data *data, errno =EINVAL ;return -1 ; } -return SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMESIZES , frmsize); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMESIZES , frmsize); }if (frmsize->index>= data->no_framesizes) {@@ -1332,7 +1342,8 @@ int v4lconvert_enum_frameintervals(struct v4lconvert_data *data, errno =EINVAL ;return -1 ; } - res =SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMEINTERVALS , frmival); + res = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMEINTERVALS , frmival);if (res)V4LCONVERT_ERR ("%s\n" ,strerror (errno));return res;@@ -1377,7 +1388,8 @@ int v4lconvert_enum_frameintervals(struct v4lconvert_data *data, frmival->pixel_format = src_fmt.fmt.pix.pixelformat; frmival->width = src_fmt.fmt.pix.width; frmival->height = src_fmt.fmt.pix.height; - res =SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMEINTERVALS , frmival); + res = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMEINTERVALS , frmival);if (res) {int dest_pixfmt = dest_fmt.fmt.pix.pixelformat;int src_pixfmt = src_fmt.fmt.pix.pixelformat;
Re: [PATCH 1/1 v3] libv4l: Add plugin support to libv4l
Quoted 1 line · Hans de Goede
Hi,
Hi Hans, Yordan,
Quoted 7 lines
First of all my apologies for taking so long to get around to reviewing this.
Over all it looks good, I've put some small remarks inline, if you fix these I can merge this. I wonder though, given the recent limbo around Nokia's change of focus, if there are any plans to actually move forward with a plugin using this... ?
Yes, there are. That hasn't changed a bit.
Quoted 2 lines
The reason I'm asking is that adding the plugin framework if nothing is going to use it seems a bit senseless.
I agree with that. I also hope others would find the plugin framework useful as well. :-)
A minor comment on the patch itself: there are a few checkpatch.pl warnings from it, mostly lines over 80 characters, but also others.
Cheers,
Signature · 2 lines
Sakari Ailus [email protected]
Re: [PATCH 1/1 v3] libv4l: Add plugin support to libv4l
In reply to Hans de GoedeYupeng,
Can you take a look at this as well? After all, Qualcomm is one of the intended users.
Regards,
Hans
Quoted 13 lines · On Thursday, April 28, 2011 14:46:27 Hans de Goede wrote:
Hi,
First of all my apologies for taking so long to get around to reviewing this.
Over all it looks good, I've put some small remarks inline, if you fix these I can merge this. I wonder though, given the recent limbo around Nokia's change of focus, if there are any plans to actually move forward with a plugin using this... ?
The reason I'm asking is that adding the plugin framework if nothing is going to use it seems a bit senseless.
Quoted 19 lines
Regards,
Hans
Quoted 13 lines · Yordan Kamenov
A libv4l2 plugin will sit in between libv4l2 itself and the actual
/dev/videodevice node a fd refers to. It will be called each time libv4l2 wants to do an operation (read/write/ioctl) on the actual/dev/videonode in question.Signed-off-by Yordan Kamenov<[email protected]>--- lib/include/libv4l2-plugin.h | 36 ++++++ lib/include/libv4lconvert.h | 5 +- lib/libv4l2/Makefile | 4 +- lib/libv4l2/libv4l2-priv.h | 10 ++ lib/libv4l2/libv4l2.c | 90 ++++++++++---- lib/libv4l2/v4l2-plugin.c | 160
++++++++++++++++++++++++
Quoted 10 lines
Quoted 10 lines
lib/libv4l2/v4l2convert.c | 9 -- lib/libv4lconvert/control/libv4lcontrol-priv.h | 4 + lib/libv4lconvert/control/libv4lcontrol.c | 35 ++++-- lib/libv4lconvert/control/libv4lcontrol.h | 5 +- lib/libv4lconvert/libv4lconvert-priv.h | 2 + lib/libv4lconvert/libv4lconvert.c | 34 ++++-- 12 files changed, 333 insertions(+), 61 deletions(-)create mode 100644
lib/include/libv4l2-plugin.h
create mode 100644lib/libv4l2/v4l2-plugin.c
Quoted 11 lines
lib/include/libv4l2-plugin.h line 5
Quoted 11 lines
lib/include/libv4l2-plugin.h new file +5
-0@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2010 Nokia Corporation<[email protected]> + +* 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
Quoted 9 lines
lib/include/libv4l2-plugin.h
Quoted 9 lines
lib/include/libv4l2-plugin.h new file +9
-0+* 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public
License
Quoted 2 lines
lib/include/libv4l2-plugin.h line 16
Quoted 2 lines
lib/include/libv4l2-plugin.h new file +2
-0+* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
Quoted 9 lines
lib/include/libv4l2-plugin.h
Quoted 9 lines
lib/include/libv4l2-plugin.h new file +9
-0+*/ + +#ifndef __LIBV4L2_PLUGIN_H +#define __LIBV4L2_PLUGIN_H + +#include <sys/types.h> + +/* Structure libv4l2_dev_ops holds the calls from libv4ls to video nodes. +They can be normal open/close/ioctl etc. or any of them may be
replaced
Quoted 11 lines
lib/include/libv4l2-plugin.h line 31
Quoted 6 lines
lib/include/libv4l2-plugin.h new file +6
-0+with a callback by a loaded plugin. +*/ + +struct libv4l2_dev_ops { +void * (*init)(int fd); +int (*close)(void *dev_ops_priv);Since you don't error check the close callback's return value in the single place you call it, you might just as well make it void
Quoted 1 line
lib/include/libv4l2-plugin.h new file +1
-0+ int (*ioctl)(void *dev_ops_priv, int fd, unsigned long int request,
void *arg);
Quoted 56 lines
Quoted 56 lines
lib/include/libv4l2-plugin.h new file +4
-0+ ssize_t (*read)(void *dev_ops_priv, int fd, void *buffer, size_t n); +}; + +#endif lib/include/libv4lconvert.h +4
-1@@ -38,6 +38,8 @@#include <linux/videodev2.h> +#include "libv4l2-plugin.h" +#ifdef __cplusplusextern "C" {#endif /* __cplusplus */ @@ -50,7 +52,8 @@ extern "C" {struct v4lconvert_data ; -LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create(int fd); +LIBV4L_PUBLIC struct v4lconvert_data *v4lconvert_create(int fd, +void *dev_ops_priv,struct libv4l2_dev_ops *dev_ops); LIBV4L_PUBLIC void v4lconvert_destroy(struct v4lconvert_data *data);/* When doing flipping / rotating / video-processing, only supported lib/libv4l2/Makefile +2
-2@@ -1,8 +1,8 @@ override CPPFLAGS += -I../include -fvisibility=hidden -LIBS_libv4l2 = -lpthread +LIBS_libv4l2 = -lpthread -ldl -V4L2_OBJS = libv4l2.o log.o +V4L2_OBJS = libv4l2.o v4l2-plugin.o log.o V4L2CONVERT = v4l2convert.so V4L2CONVERT_O = v4l2convert.o libv4l2.so TARGETS = $(V4L2_LIB) libv4l2.pclib/libv4l2/libv4l2-priv.h +4
-0@@ -85,8 +85,18 @@ struct v4l2_dev_info {/* buffer when doing conversion and using read() for read() */ int readbuf_size;unsigned char *readbuf; +struct libv4l2_dev_ops *dev_ops; +/* plugin info */ +void *plugin_library; +void *dev_ops_priv; };
Quoted 1 line
lib/libv4l2/libv4l2-priv.h struct v4l2_dev_info { · line 94
Quoted 1 line
lib/libv4l2/libv4l2-priv.h +1
-0+void v4l2_plugin_init(int fd, void **plugin_lib_ret, void
**plugin_priv_ret,
Quoted 18 lines
Quoted 18 lines
lib/libv4l2/libv4l2-priv.h +5
-0+ struct libv4l2_dev_ops **dev_ops_ret); +void v4l2_plugin_cleanup (void *plugin_priv,void *plugin_lib, +struct libv4l2_dev_ops *dev_ops); + +/* From log.c */ void v4l2_log_ioctl (unsigned long int request,void *arg,int result);lib/libv4l2/libv4l2.c +1
-0@@ -67,6 +67,7 @@#include <sys/stat.h> #include "libv4l2.h" #include "libv4l2-priv.h" +#include "libv4l2-plugin.h"
Quoted 1 line
lib/libv4l2/libv4l2.c line 72
Quoted 1 line
lib/libv4l2/libv4l2.c +0
-0/* Note these flags are stored together with the flags passed to
v4l2_fd_open()
Quoted 1 line
lib/libv4l2/libv4l2.c line 73
Quoted 1 line
lib/libv4l2/libv4l2.c +0
-0in v4l2_dev_info's flags member, so care should be taken that the do
not
Quoted 49 lines
Quoted 21 lines
lib/libv4l2/libv4l2.c +4
-2@@ -102,7 +103,8 @@ static int v4l2_request_read_buffers(int index) devices[index].nreadbuffers; req.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; req.memory =V4L2_MEMORY_MMAP ; - result =SYS_IOCTL (devices[index].fd,VIDIOC_REQBUFS ,&req); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_REQBUFS ,&req);if (result<0 ) {int saved_err = errno;@@ -131,7 +133,8 @@ static void v4l2_unrequest_read_buffers(int index) req.count =0 ; req.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; req.memory =V4L2_MEMORY_MMAP ; -if (SYS_IOCTL (devices[index].fd,VIDIOC_REQBUFS ,&req)<0 ) +if (devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_REQBUFS ,&req)<0 )return ; devices[index].no_frames =MIN (req.count,V4L2_MAX_NO_FRAMES );lib/libv4l2/libv4l2.c static int v4l2_map_buffers(int index) · line 158
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-1@@ -152,7 +155,8 @@ static int v4l2_map_buffers(int index) buf.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; buf.memory =V4L2_MEMORY_MMAP ; buf.index = i; - result =SYS_IOCTL (devices[index].fd,VIDIOC_QUERYBUF ,&buf); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c static int v4l2_streamon(int index) · line 209
Quoted 10 lines
lib/libv4l2/libv4l2.c +2
-1+ devices[index].fd, VIDIOC_QUERYBUF,&buf);if (result) {int saved_err = errno;@@ -202,7 +206,8 @@ static int v4l2_streamon(int index)enum v4l2_buf_type type =V4L2_BUF_TYPE_VIDEO_CAPTURE ;if (!(devices[index].flags&V4L2_STREAMON )) { - result =SYS_IOCTL (devices[index].fd,VIDIOC_STREAMON ,&type); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c static int v4l2_streamoff(int index) · line 231
Quoted 10 lines
lib/libv4l2/libv4l2.c +2
-1+ devices[index].fd, VIDIOC_STREAMON,&type);if (result) {int saved_err = errno;@@ -223,7 +228,8 @@ static int v4l2_streamoff(int index)enum v4l2_buf_type type =V4L2_BUF_TYPE_VIDEO_CAPTURE ;if (devices[index].flags&V4L2_STREAMON ) { - result =SYS_IOCTL (devices[index].fd,VIDIOC_STREAMOFF ,&type); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
Quoted 5 lines
lib/libv4l2/libv4l2.c static int v4l2_queue_read_buffer(int index, int
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_STREAMOFF,&type);if (result) {int saved_err = errno;@@ -252,7 +258,8 @@ static int v4l2_queue_read_buffer(int index, int
buffer_index)
Quoted 10 lines
lib/libv4l2/libv4l2.c static int v4l2_dequeue_and_convert(int index, struct
Quoted 10 lines
lib/libv4l2/libv4l2.c +2
-1buf.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; buf.memory =V4L2_MEMORY_MMAP ; buf.index = buffer_index; - result =SYS_IOCTL (devices[index].fd,VIDIOC_QBUF ,&buf); + result = devices[index].dev_ops->ioctl (devices[index].dev_ops_priv, + devices[index].fd,VIDIOC_QBUF ,&buf);if (result) {int saved_err = errno;@@ -277,7 +284,8 @@ static int v4l2_dequeue_and_convert(int index, struct
v4l2_buffer *buf,
Quoted 11 lines
lib/libv4l2/libv4l2.c static int v4l2_dequeue_and_convert(int index, struct v4l2_buffer *buf,
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-1return result; do { - result = SYS_IOCTL(devices[index].fd, VIDIOC_DQBUF, buf); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c static int v4l2_read_and_convert(int index, unsigned
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_DQBUF, buf);if (result) {if (errno !=EAGAIN ) {int saved_err = errno;@@ -356,7 +364,8 @@ static int v4l2_read_and_convert(int index, unsigned
char *dest, int dest_size)
Quoted 4 lines
lib/libv4l2/libv4l2.c static int v4l2_read_and_convert(int index, unsigned · line 359
Quoted 4 lines
lib/libv4l2/libv4l2.c +0
-1} do { - result = SYS_READ(devices[index].fd, devices[index].readbuf,
buf_size);
Quoted 13 lines
lib/libv4l2/libv4l2.c static int v4l2_read_and_convert(int index, unsigned · line 367
Quoted 1 line
lib/libv4l2/libv4l2.c +1
-0+ result = devices[index].dev_ops-read(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c static int v4l2_buffers_mapped(int index) · line 508
Quoted 10 lines
lib/libv4l2/libv4l2.c +2
-1+ devices[index].fd, devices[index].readbuf, buf_size);if (result<=0 ) {if (result&& errno !=EAGAIN ) {int saved_err = errno;@@ -496,7 +505,8 @@ static int v4l2_buffers_mapped(int index) buf.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; buf.memory =V4L2_MEMORY_MMAP ; buf.index = i; -if (SYS_IOCTL (devices[index].fd,VIDIOC_QUERYBUF ,&buf)) { + if (devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
Quoted 4 lines
lib/libv4l2/libv4l2.c static int v4l2_request_read_buffers(int index)
Quoted 4 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_QUERYBUF,&buf)) {int saved_err = errno; V4L2_LOG_ERR("querying buffer %u: %s\n", i,
strerror(errno));
Quoted 11 lines
lib/libv4l2/libv4l2.c int v4l2_fd_open(int fd, int v4l2_flags) · line 580
Quoted 11 lines
lib/libv4l2/libv4l2.c +5
-0@@ -561,6 +571,11 @@ int v4l2_fd_open(int fd, int v4l2_flags)struct v4l2_capability cap;struct v4l2_format fmt;struct v4lconvert_data *convert; +struct libv4l2_dev_ops *dev_ops; +void *plugin_library; +void *plugin_data; + +v4l2_plugin_init (fd,&plugin_library,&plugin_data,&dev_ops);/* If no log file was set by the app, see if one was specified
through the
Quoted 15 lines
Quoted 15 lines
lib/libv4l2/libv4l2.c +2
-1environment */ @@ -571,9 +586,10 @@ int v4l2_fd_open(int fd, int v4l2_flags) }/* check that this is an v4l2 device */ -if (SYS_IOCTL (fd,VIDIOC_QUERYCAP ,&cap)) { +if (dev_ops->ioctl (plugin_data, fd,VIDIOC_QUERYCAP ,&cap)) {int saved_err = errno; +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops);V4L2_LOG_ERR ("getting capabilities: %s\n" ,strerror (errno)); errno = saved_err;return -1 ;@@ -581,29 +597,38 @@ int v4l2_fd_open(int fd, int v4l2_flags)
Quoted 3 lines
lib/libv4l2/libv4l2.c int v4l2_fd_open(int fd, int v4l2_flags) · line 584
Quoted 3 lines
lib/libv4l2/libv4l2.c +0
-1/* we only add functionality for video capture devices */ if (!(cap.capabilities& V4L2_CAP_VIDEO_CAPTURE) || - !(cap.capabilities& (V4L2_CAP_STREAMING |
V4L2_CAP_READWRITE)))
Quoted 1 line
lib/libv4l2/libv4l2.c int v4l2_fd_open(int fd, int v4l2_flags) · line 600
Quoted 1 line
lib/libv4l2/libv4l2.c +1
-0+ !(cap.capabilities& (V4L2_CAP_STREAMING |
V4L2_CAP_READWRITE))) {
Quoted 25 lines
Quoted 25 lines
lib/libv4l2/libv4l2.c +8
-3+v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops);return fd; + }/* Get current cam format */ fmt.type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; -if (SYS_IOCTL (fd,VIDIOC_G_FMT ,&fmt)) { +if (dev_ops->ioctl (plugin_data, fd,VIDIOC_G_FMT ,&fmt)) {int saved_err = errno; +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops);V4L2_LOG_ERR ("getting pixformat: %s\n" ,strerror (errno)); errno = saved_err;return -1 ; }/* init libv4lconvert */ - convert =v4lconvert_create (fd); -if (!convert) + convert =v4lconvert_create (fd, plugin_data, dev_ops); +if (!convert) { +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops);return -1 ; + }
Quoted 1 line
lib/libv4l2/libv4l2.c int v4l2_fd_open(int fd, int v4l2_flags) · line 623
Quoted 1 line
lib/libv4l2/libv4l2.c +0
-0/* So we have a v4l2 capture device, register it in our devices array
*/
Quoted 23 lines
Quoted 23 lines
lib/libv4l2/libv4l2.c +5
-0pthread_mutex_lock (&v4l2_open_mutex);for (index =0 ; index<V4L2_MAX_DEVICES ; index++)if (devices[index].fd ==-1 ) { devices[index].fd = fd; + + devices[index].plugin_library = plugin_library; + devices[index].dev_ops_priv = plugin_data; + devices[index].dev_ops = dev_ops;break ; }pthread_mutex_unlock (&v4l2_open_mutex);@@ -611,6 +636,7 @@ int v4l2_fd_open(int fd, int v4l2_flags)if (index ==V4L2_MAX_DEVICES ) {V4L2_LOG_ERR ("attempting to open more then %d video devices\n" ,V4L2_MAX_DEVICES ); +v4l2_plugin_cleanup (plugin_data, plugin_library, dev_ops); errno =EBUSY ;return -1 ; }@@ -690,6 +716,9 @@ int v4l2_close(int fd)if (index ==-1 )return SYS_CLOSE (fd);
Quoted 9 lines
lib/libv4l2/libv4l2.c int v4l2_close(int fd) · line 721
Quoted 3 lines
lib/libv4l2/libv4l2.c +3
-0+v4l2_plugin_cleanup (devices[index].dev_ops_priv, + devices[index].plugin_library, devices[index].dev_ops); +This should be moved lower, to were the actual fd gets closed, if the fd was opened multiple times (through dup) the plugin stuff should not be cleaned up yet...
Quoted 1 line
lib/libv4l2/libv4l2.c +0
-0/* Abuse stream_lock to stop 2 closes from racing and trying to free
the
Quoted 8 lines
Quoted 8 lines
lib/libv4l2/libv4l2.c +1
-0resources twice */ pthread_mutex_lock (&devices[index].stream_lock);@@ -808,6 +837,7 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)va_list ap;int result, index, saved_err;int is_capture_request =0 , stream_needs_locking =0 ; +void *plugin_data;
Quoted 8 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 851
Quoted 8 lines
lib/libv4l2/libv4l2.c +1
-0va_start (ap, request); arg = va_arg(ap, void *);@@ -817,6 +847,7 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)if (index ==-1 )return SYS_IOCTL (fd, request, arg); + plugin_data = devices[index].dev_ops_priv;/* Appearantly the kernel and / or glibc ignore the 32 most
significant bits
Quoted 1 line
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 852
Quoted 1 line
lib/libv4l2/libv4l2.c +0
-0when long = 64 bits, and some applications pass an int holding the
req to
Quoted 1 line
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 853
Quoted 1 line
lib/libv4l2/libv4l2.c +0
-0ioctl, causing it to get sign extended, depending upon this
behavior */
Quoted 9 lines
You don't seem to use
plugin_dataconsistently in the function, see below.lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 913
Quoted 6 lines
lib/libv4l2/libv4l2.c +1
-1@@ -879,7 +910,7 @@ int v4l2_ioctl(int fd, unsigned long int request, ...) }if (!is_capture_request) { - result =SYS_IOCTL (fd, request, arg); + result = devices[index].dev_ops->ioctl(plugin_data, fd, request,
arg);
Quoted 5 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 916
Quoted 3 lines
lib/libv4l2/libv4l2.c +0
-0saved_err = errno;v4l2_log_ioctl (request, arg, result); errno = saved_err;This is the 1 of places where you actually use
plugin_data, either use it
everywhere,
Quoted 6 lines
or drop it.
Quoted 4 lines
lib/libv4l2/libv4l2.c +0
-0@@ -927,7 +958,8 @@ int v4l2_ioctl(int fd, unsigned long int request, ...)case VIDIOC_QUERYCAP : {struct v4l2_capability *cap = arg;
Quoted 6 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...) · line 961
Quoted 2 lines
lib/libv4l2/libv4l2.c +1
-1- result =SYS_IOCTL (devices[index].fd,VIDIOC_QUERYCAP , cap); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 3 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_QUERYCAP, cap);if (result ==0 )/* We always support read() as we fake it using mmap mode
*/
Quoted 2 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request,
Quoted 2 lines
lib/libv4l2/libv4l2.c +0
-0cap->capabilities |=V4L2_CAP_READWRITE ;@@ -977,8 +1009,8 @@ int v4l2_ioctl(int fd, unsigned long int request,
...)
Quoted 11 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 6 lines
lib/libv4l2/libv4l2.c +1
-2}if (devices[index].flags&V4L2_DISABLE_CONVERSION ) { - result =SYS_IOCTL (devices[index].fd,VIDIOC_TRY_FMT , - dest_fmt); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 4 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_TRY_FMT, dest_fmt); src_fmt = *dest_fmt; }else { result = v4lconvert_try_format(devices[index].convert,
dest_fmt,
Quoted 1 line
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request,
Quoted 1 line
lib/libv4l2/libv4l2.c +0
-0@@ -1018,7 +1050,8 @@ int v4l2_ioctl(int fd, unsigned long int request,
...)
Quoted 11 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-1break ; req_pix_fmt = src_fmt.fmt.pix; - result =SYS_IOCTL (devices[index].fd,VIDIOC_S_FMT ,&src_fmt); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request,
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_S_FMT,&src_fmt);if (result) { saved_err = errno;V4L2_LOG_ERR ("setting pixformat: %s\n" ,strerror (errno));@@ -1067,7 +1100,8 @@ int v4l2_ioctl(int fd, unsigned long int request,
...)
Quoted 10 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-1if (req->count>V4L2_MAX_NO_FRAMES ) req->count =V4L2_MAX_NO_FRAMES ; - result =SYS_IOCTL (devices[index].fd,VIDIOC_REQBUFS , req); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 4 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_REQBUFS, req);if (result<0 )break ; result =0 ;/* some drivers return the number of buffers on
success */
Quoted 1 line
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request,
Quoted 1 line
lib/libv4l2/libv4l2.c +0
-0@@ -1088,7 +1122,8 @@ int v4l2_ioctl(int fd, unsigned long int request,
...)
Quoted 2 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, · line 1122
Quoted 2 lines
lib/libv4l2/libv4l2.c +0
-0/* Do a real query even when converting to let the driver fill
in
Quoted 9 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 3 lines
lib/libv4l2/libv4l2.c +1
-1things like buf->field */ - result =SYS_IOCTL (devices[index].fd,VIDIOC_QUERYBUF , buf); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request,
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_QUERYBUF, buf);if (result || !v4l2_needs_conversion (index))break ;@@ -1115,7 +1150,8 @@ int v4l2_ioctl(int fd, unsigned long int request,
...)
Quoted 11 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-1break ; } - result =SYS_IOCTL (devices[index].fd,VIDIOC_QBUF , arg); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request,
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_QBUF, arg);break ;case VIDIOC_DQBUF : {@@ -1128,7 +1164,8 @@ int v4l2_ioctl(int fd, unsigned long int request,
...)
Quoted 11 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-1}if (!v4l2_needs_conversion (index)) { - result =SYS_IOCTL (devices[index].fd,VIDIOC_DQBUF , buf); + result = devices[index].dev_ops-ioctl(devices[index].dev_ops_priv,
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request,
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-0+ devices[index].fd, VIDIOC_DQBUF, buf);if (result) {int saved_err = errno;@@ -1187,7 +1224,7 @@ int v4l2_ioctl(int fd, unsigned long int request,
...)
Quoted 5 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, ...)
Quoted 5 lines
lib/libv4l2/libv4l2.c +1
-1break ;default : - result =SYS_IOCTL (fd, request, arg); + result = devices[index].dev_ops->ioctl(plugin_data, fd, request,
arg);
Quoted 13 lines
lib/libv4l2/libv4l2.c int v4l2_ioctl(int fd, unsigned long int request, · line 1230
Quoted 3 lines
lib/libv4l2/libv4l2.c +0
-0break ; }This is the only other place you use
plugin_data.Quoted 7 lines
lib/libv4l2/libv4l2.c +1
-0@@ -1206,18 +1243,21 @@ ssize_t v4l2_read(int fd, void *dest, size_t n) {ssize_t result;int saved_errno; +void *plugin_data;int index =v4l2_get_index (fd);
Quoted 8 lines
lib/libv4l2/libv4l2.c ssize_t v4l2_read(int fd, void *dest, size_t n)
Quoted 8 lines
lib/libv4l2/libv4l2.c +2
-0if (index ==-1 )return SYS_READ (fd, dest, n); + plugin_data = devices[index].dev_ops_priv; +pthread_mutex_lock (&devices[index].stream_lock);/* When not converting and the device supports read let the kernel
handle
Quoted 12 lines
lib/libv4l2/libv4l2.c ssize_t v4l2_read(int fd, void *dest, size_t n) · line 1263
Quoted 8 lines
lib/libv4l2/libv4l2.c +1
-1it */ if ((devices[index].flags&V4L2_SUPPORTS_READ )&& !v4l2_needs_conversion (index)) { - result =SYS_READ (fd, dest, n); + result = devices[index].dev_ops->read (plugin_data, fd, dest, n); goto leave; }I so no need for the
plugin_datavariable here, just use devices[index].dev_ops_priv directly when you calldev_ops->read.
Quoted 11 lines
lib/libv4l2/v4l2-plugin.c line 5
Quoted 11 lines
lib/libv4l2/v4l2-plugin.c new file +5
-0@@ -0,0 +1,160 @@ +/* +* Copyright (C) 2010 Nokia Corporation<[email protected]> + +* 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
Quoted 9 lines
lib/libv4l2/v4l2-plugin.c line 14
Quoted 9 lines
lib/libv4l2/v4l2-plugin.c new file +9
-0+* 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public
License
Quoted 2 lines
lib/libv4l2/v4l2-plugin.c line 16
Quoted 2 lines
lib/libv4l2/v4l2-plugin.c new file +2
-0+* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
Quoted 8 lines
Quoted 8 lines
lib/libv4l2/v4l2-plugin.c new file +8
-0+*/ + +#include <stdarg.h> +#include <dlfcn.h> +#include <fcntl.h> +#include <glob.h> +#include <sys/stat.h> +#include <sys/mman.h>
Quoted 8 lines
lib/libv4l2/v4l2-plugin.c
Quoted 8 lines
lib/libv4l2/v4l2-plugin.c new file +8
-0+#include "libv4l2.h" +#include "libv4l2-priv.h" +#include "libv4l2-plugin.h" + +/* libv4l plugin support: +it is provided by functions v4l2_plugin_[open,close,etc]. + +When open() is called libv4l dlopens files in
/usr/lib[64]/libv4l/plugins
Quoted 4 lines
lib/libv4l2/v4l2-plugin.c
Quoted 4 lines
lib/libv4l2/v4l2-plugin.c new file +4
-0+ 1 at a time and call open callback passing through the applications + parameters unmodified. + + If a plugin is relevant for the specified device node, it can indicate
so
Quoted 2 lines
lib/libv4l2/v4l2-plugin.c line 38
Quoted 2 lines
lib/libv4l2/v4l2-plugin.c new file +2
-0+ by returning a value other then -1 (the actual file descriptor). + As soon as a plugin returns another value then -1 plugin loading stops
and
Quoted 1 line
lib/libv4l2/v4l2-plugin.c line 39
Quoted 1 line
lib/libv4l2/v4l2-plugin.c new file +1
-0+ information about it (fd and corresponding library handle) is stored.
For
Quoted 2 lines
lib/libv4l2/v4l2-plugin.c line 41
Quoted 2 lines
lib/libv4l2/v4l2-plugin.c new file +2
-0+ each function v4l2_[ioctl,read,close,etc] is called corresponding + v4l2_plugin_* function which looks if there is loaded plugin for that
file
Quoted 3 lines
lib/libv4l2/v4l2-plugin.c
Quoted 3 lines
lib/libv4l2/v4l2-plugin.c new file +3
-0+ and call it's callbacks. + + v4l2_plugin_* function indicates by it's first argument if plugin was
used,
Quoted 1 line
lib/libv4l2/v4l2-plugin.c line 45
Quoted 1 line
lib/libv4l2/v4l2-plugin.c new file +1
-0+ and if it was not then v4l2_* functions proceed with their usual
behavior.
Quoted 9 lines
Quoted 9 lines
lib/libv4l2/v4l2-plugin.c new file +9
-0+*/ + +#define PLUGINS_PATTERN "/usr/lib/libv4l/plugins/*.so" + +static void *dev_init (int fd) +{ +return NULL ; +} +
Quoted 10 lines
lib/libv4l2/v4l2-plugin.c line 59
Quoted 5 lines
lib/libv4l2/v4l2-plugin.c new file +5
-0+static int dev_close (void *dev_ops_priv) +{ +return -1 ; +} +-1 is an error? Why would the default plugin always return error on close? Anyways as said before just make it void.
Quoted 1 line
lib/libv4l2/v4l2-plugin.c new file +1
-0+static int dev_ioctl(void *dev_ops_priv, int fd, unsigned long cmd, void
*arg)
Quoted 6 lines
lib/libv4l2/v4l2-plugin.c
Quoted 6 lines
lib/libv4l2/v4l2-plugin.c new file +6
-0+{ +return syscall (SYS_ioctl, (int )(fd), (unsigned long )(cmd), + (void *)(arg)); +} + +static ssize_t dev_read(void *dev_ops_priv, int fd, void *buf, size_t
len)
Quoted 6 lines
lib/libv4l2/v4l2-plugin.c line 69
Quoted 3 lines
lib/libv4l2/v4l2-plugin.c new file +3
-0+{ +return syscall (SYS_read, (int )(fd), (void *)(buf), (size_t )(len)); +}Please use the
SYS_IOCTLandSYS_READmacro's here for compat with freebsd.
Quoted 10 lines
lib/libv4l2/v4l2-plugin.c
Quoted 10 lines
lib/libv4l2/v4l2-plugin.c new file +10
-0+ + +struct libv4l2_dev_ops default_operations = { + .init =&dev_init, + .close =&dev_close, + .ioctl =&dev_ioctl, + .read =&dev_read +}; + +void v4l2_plugin_init(int fd, void **plugin_lib_ret, void
**plugin_priv_ret,
Quoted 92 lines
Quoted 92 lines
lib/libv4l2/v4l2-plugin.c new file +81
-0+ struct libv4l2_dev_ops **dev_ops_ret) +{ +char *error; +int glob_ret, plugin_num; +void *plugin_library =NULL ; +struct libv4l2_dev_ops *libv4l2_plugin =NULL ; +glob_t globbuf; + + *dev_ops_ret =&default_operations; + + glob_ret =glob (PLUGINS_PATTERN ,0 ,NULL ,&globbuf); + +if (glob_ret ==GLOB_NOSPACE ) { + *plugin_lib_ret =NULL ; + *plugin_priv_ret =NULL ; +return ; + } + +if (glob_ret ==GLOB_ABORTED || glob_ret ==GLOB_NOMATCH ) { + *plugin_lib_ret =NULL ; + *plugin_priv_ret =NULL ; + goto leave; + } + +for (plugin_num =0 ; plugin_num< globbuf.gl_pathc; plugin_num++) { + +V4L2_LOG ("PLUGIN: dlopen(%s);\n" , globbuf.gl_pathv[plugin_num]); + + plugin_library =dlopen (globbuf.gl_pathv[plugin_num], +RTLD_LAZY ); + +if (!plugin_library) +continue ; + +dlerror ();/* Clear any existing error */ + libv4l2_plugin = (struct libv4l2_dev_ops *) +dlsym (plugin_library,"libv4l2_plugin" ); + + error =dlerror (); +if (error !=NULL ) { +V4L2_LOG_ERR ("PLUGIN: dlsym failed: %s\n" , error); +dlclose (plugin_library); + +continue ; + } + + *plugin_priv_ret =NULL ; +if (libv4l2_plugin->init) + *plugin_priv_ret = libv4l2_plugin->init (fd); + +if (!*plugin_priv_ret) { +V4L2_LOG ("PLUGIN: plugin open() returned NULL\n" ); +dlclose (plugin_library); + *plugin_lib_ret =NULL ; +continue ; + } + + (*dev_ops_ret)->init = libv4l2_plugin->init; +if (libv4l2_plugin->close !=NULL ) + (*dev_ops_ret)->close = libv4l2_plugin->close; +if (libv4l2_plugin->ioctl !=NULL ) + (*dev_ops_ret)->ioctl = libv4l2_plugin->ioctl; +if (libv4l2_plugin->read !=NULL ) + (*dev_ops_ret)->read = libv4l2_plugin->read; + +break ; + + } + +leave: +globfree (&globbuf); +} + +void v4l2_plugin_cleanup (void *plugin_priv,void *plugin_lib, +struct libv4l2_dev_ops *dev_ops) +{ +if (plugin_priv) { + dev_ops->close (plugin_priv); +dlclose (plugin_lib); + } +}lib/libv4l2/v4l2convert.c +0
-1@@ -46,7 +46,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...) {int fd; -struct v4l2_capability cap;int v4l_device =0 ;
Quoted 2 lines
lib/libv4l2/v4l2convert.c LIBV4L_PUBLIC int open(const char *file, int oflag,
Quoted 2 lines
lib/libv4l2/v4l2convert.c +0
-0/* check if we're opening a video4linux2 device */ @@ -76,14 +75,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag,
...)
Quoted 4 lines
lib/libv4l2/v4l2convert.c LIBV4L_PUBLIC int open(const char *file, int oflag, ...)
Quoted 4 lines
lib/libv4l2/v4l2convert.c +0
-1if (fd ==-1 || !v4l_device)return fd; -/* check that this is an v4l2 device, libv4l2 only supports v4l2
devices */
Quoted 8 lines
lib/libv4l2/v4l2convert.c LIBV4L_PUBLIC int open(const char *file, int oflag, ...)
Quoted 8 lines
lib/libv4l2/v4l2convert.c +0
-7-if (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
Quoted 6 lines
lib/libv4l2/v4l2convert.c LIBV4L_PUBLIC int open(const char *file, int oflag, ...) · line 80
Quoted 2 lines
lib/libv4l2/v4l2convert.c +0
-0application as is) */ v4l2_fd_open (fd,0 );Hmm, why are you removing this check ?
Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/libv4lconvert/control/libv4lcontrol-priv.h
Quoted 7 lines
Quoted 7 lines
index 22cdf34..1259e6b 100644
lib/libv4lconvert/control/libv4lcontrol-priv.h +0
-0@@ -22,6 +22,8 @@#ifndef __LIBV4LCONTROL_PRIV_H#define __LIBV4LCONTROL_PRIV_H
Quoted 8 lines
lib/libv4lconvert/control/libv4lcontrol-priv.h struct v4lcontrol_data { · line 40
Quoted 8 lines
lib/libv4lconvert/control/libv4lcontrol-priv.h +2
-0+#include "libv4l2-plugin.h" +#define V4LCONTROL_SHM_SIZE 4096#define V4LCONTROL_SUPPORTS_NEXT_CTRL 0x01@@ -37,6 +39,8 @@ struct v4lcontrol_data {unsigned int *shm_values;/* shared memory control value store */ unsigned int old_values[V4LCONTROL_COUNT ];/* for controls_changed()
*/
Quoted 7 lines
Review
Quoted 7 lines
lib/libv4lconvert/control/libv4lcontrol-priv.h +2
-0const struct v4lcontrol_flags_info *flags_info; +struct libv4l2_dev_ops *dev_ops; +void *dev_ops_priv; };struct v4lcontrol_flags_info {(quoted diff) +0
-0
b/lib/libv4lconvert/control/libv4lcontrol.c
Quoted 4 lines
lib/libv4lconvert/control/libv4lcontrol.c static void v4lcontrol_get_flags_from_db(struct
Quoted 4 lines
index 6a09d38..2ef642c 100644
lib/libv4lconvert/control/libv4lcontrol.c +0
-0@@ -701,7 +701,8 @@ static void v4lcontrol_get_flags_from_db(struct
v4lcontrol_data *data,
Quoted 4 lines
lib/libv4lconvert/control/libv4lcontrol.c static void v4lcontrol_get_flags_from_db(struct · line 704
Quoted 4 lines
lib/libv4lconvert/control/libv4lcontrol.c +0
-1} } -struct v4lcontrol_data *v4lcontrol_create(int fd, int
always_needs_conversion)
Quoted 6 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd,
Quoted 6 lines
lib/libv4lconvert/control/libv4lcontrol.c +2
-0+struct v4lcontrol_data *v4lcontrol_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops,int always_needs_conversion) {int shm_fd;int i, rc, got_usb_ids, init =0 ;@@ -721,10 +722,12 @@ struct v4lcontrol_data *v4lcontrol_create(int fd,
int always_needs_conversion)
Quoted 7 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)
Quoted 7 lines
lib/libv4lconvert/control/libv4lcontrol.c +2
-0} data->fd = fd; + data->dev_ops = dev_ops; + data->dev_ops_priv = dev_ops_priv;/* Check if the driver has indicated some form of flipping is needed
*/
Quoted 3 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, · line 729
Quoted 3 lines
lib/libv4lconvert/control/libv4lcontrol.c +1
-2-if ((SYS_IOCTL (data->fd,VIDIOC_G_INPUT ,&input.index) ==0 )&& - (SYS_IOCTL (data->fd,VIDIOC_ENUMINPUT ,&input) ==0 )) { + if ((data->dev_ops->ioctl(data->dev_ops_priv, data->fd,
VIDIOC_G_INPUT,&input.index) == 0)&&
Quoted 1 line
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, · line 730
Quoted 1 line
lib/libv4lconvert/control/libv4lcontrol.c +1
-0+ (data->dev_ops->ioctl(data->dev_ops_priv, data->fd,
VIDIOC_ENUMINPUT,&input) == 0)) {
Quoted 4 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, int
Quoted 4 lines
lib/libv4lconvert/control/libv4lcontrol.c +0
-0if (input.status&V4L2_IN_ST_HFLIP ) data->flags |=V4LCONTROL_HFLIPPED ;if (input.status&V4L2_IN_ST_VFLIP )@@ -741,7 +744,8 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int
always_needs_conversion)
Quoted 9 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)
Quoted 9 lines
lib/libv4lconvert/control/libv4lcontrol.c +2
-1data->flags =strtol (s,NULL ,0 ); ctrl.id =V4L2_CTRL_FLAG_NEXT_CTRL ; -if (SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl) ==0 ) +if (data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl) ==0 ) data->priv_flags |=V4LCONTROL_SUPPORTS_NEXT_CTRL ;/* If the device always needs conversion, we can add fake controls at
no cost
Quoted 1 line
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, int
Quoted 1 line
lib/libv4lconvert/control/libv4lcontrol.c +0
-0@@ -749,7 +753,8 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int
always_needs_conversion)
Quoted 7 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, int · line 758
Quoted 7 lines
lib/libv4lconvert/control/libv4lcontrol.c +2
-1if (always_needs_conversion ||v4lcontrol_needs_conversion (data)) {for (i =0 ; i<V4LCONTROL_AUTO_ENABLE_COUNT ; i++) { ctrl.id = fake_controls[i].id; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl); if (rc == -1 || (rc == 0&& (ctrl.flags&
V4L2_CTRL_FLAG_DISABLED)))
Quoted 3 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd,
Quoted 3 lines
lib/libv4lconvert/control/libv4lcontrol.c +0
-0data->controls |=1 << i; }@@ -761,17 +766,20 @@ struct v4lcontrol_data *v4lcontrol_create(int fd,
int always_needs_conversion)
Quoted 1 line
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, · line 766
Quoted 1 line
lib/libv4lconvert/control/libv4lcontrol.c +0
-0different sensors with / without autogain or the necessary
controls. */
Quoted 15 lines
Quoted 15 lines
lib/libv4lconvert/control/libv4lcontrol.c +4
-2while (data->flags&V4LCONTROL_WANTS_AUTOGAIN ) { ctrl.id =V4L2_CID_AUTOGAIN ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl);if (rc ==0 && !(ctrl.flags&V4L2_CTRL_FLAG_DISABLED ))break ; ctrl.id =V4L2_CID_EXPOSURE ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl);if (rc !=0 || (ctrl.flags&V4L2_CTRL_FLAG_DISABLED ))break ;
Quoted 8 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, int
Quoted 8 lines
lib/libv4lconvert/control/libv4lcontrol.c +2
-1ctrl.id =V4L2_CID_GAIN ; - rc =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL ,&ctrl); + rc = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL ,&ctrl);if (rc !=0 || (ctrl.flags&V4L2_CTRL_FLAG_DISABLED ))break ;@@ -788,7 +796,7 @@ struct v4lcontrol_data *v4lcontrol_create(int fd, int
always_needs_conversion)
Quoted 5 lines
lib/libv4lconvert/control/libv4lcontrol.c struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)
Quoted 5 lines
lib/libv4lconvert/control/libv4lcontrol.c +1
-1if (data->controls ==0 )return data;/* No need to create a shared memory segment */ -if (SYS_IOCTL (fd,VIDIOC_QUERYCAP ,&cap)) { + if (data->dev_ops->ioctl(data->dev_ops_priv, fd,
VIDIOC_QUERYCAP,&cap)) {
Quoted 4 lines
lib/libv4lconvert/control/libv4lcontrol.c int v4lcontrol_vidioc_queryctrl(struct v4lcontrol_data
Quoted 4 lines
lib/libv4lconvert/control/libv4lcontrol.c +0
-0perror ("libv4lcontrol: error querying device capabilities" ); goto error; }@@ -974,7 +982,8 @@ int v4lcontrol_vidioc_queryctrl(struct v4lcontrol_data
*data, void *arg)
Quoted 10 lines
lib/libv4lconvert/control/libv4lcontrol.c int v4lcontrol_vidioc_g_ctrl(struct v4lcontrol_data
Quoted 10 lines
lib/libv4lconvert/control/libv4lcontrol.c +2
-1}/* find out what the kernel driver would respond. */ - retval =SYS_IOCTL (data->fd,VIDIOC_QUERYCTRL , arg); + retval = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_QUERYCTRL , arg);if ((data->priv_flags&V4LCONTROL_SUPPORTS_NEXT_CTRL )&& (orig_id&V4L2_CTRL_FLAG_NEXT_CTRL )) {@@ -1011,7 +1020,8 @@ int v4lcontrol_vidioc_g_ctrl(struct v4lcontrol_data
*data, void *arg)
Quoted 10 lines
lib/libv4lconvert/control/libv4lcontrol.c int v4lcontrol_vidioc_s_ctrl(struct v4lcontrol_data
Quoted 10 lines
lib/libv4lconvert/control/libv4lcontrol.c +2
-1return 0 ; } -return SYS_IOCTL (data->fd,VIDIOC_G_CTRL , arg); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_G_CTRL , arg); }int v4lcontrol_vidioc_s_ctrl (struct v4lcontrol_data *data,void *arg)@@ -1032,7 +1042,8 @@ int v4lcontrol_vidioc_s_ctrl(struct v4lcontrol_data
*data, void *arg)
Quoted 10 lines
Review
Quoted 10 lines
lib/libv4lconvert/control/libv4lcontrol.c +2
-1return 0 ; } -return SYS_IOCTL (data->fd,VIDIOC_S_CTRL , arg); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_S_CTRL , arg); }int v4lcontrol_get_flags (struct v4lcontrol_data *data)(quoted diff) +0
-0
b/lib/libv4lconvert/control/libv4lcontrol.h
Quoted 14 lines
Quoted 14 lines
index 974e97a..1c09546 100644
lib/libv4lconvert/control/libv4lcontrol.h +2
-0@@ -22,6 +22,8 @@#ifndef __LIBV4LCONTROL_H#define __LIBV4LCONTROL_H +#include "libv4l2-plugin.h" +/* Flags */ #define V4LCONTROL_HFLIPPED 0x01#define V4LCONTROL_VFLIPPED 0x02@@ -47,7 +49,8 @@ enum {
Quoted 3 lines
lib/libv4lconvert/control/libv4lcontrol.h enum {
Quoted 3 lines
lib/libv4lconvert/control/libv4lcontrol.h +0
-1struct v4lcontrol_data ; -struct v4lcontrol_data *v4lcontrol_create(int fd, int
always_needs_conversion);
Quoted 6 lines
Review
Quoted 6 lines
lib/libv4lconvert/control/libv4lcontrol.h +2
-0+struct v4lcontrol_data *v4lcontrol_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops,int always_needs_conversion);void v4lcontrol_destroy (struct v4lcontrol_data *data);/* Functions used by v4lprocessing to get the control state */ (quoted diff) +0
-0
b/lib/libv4lconvert/libv4lconvert-priv.h
Quoted 10 lines
Quoted 10 lines
index d8fe899..edc118b 100644
lib/libv4lconvert/libv4lconvert-priv.h +2
-0@@ -65,6 +65,8 @@ struct v4lconvert_data {unsigned char *convert_pixfmt_buf;struct v4lcontrol_data *control;struct v4lprocessing_data *processing; +struct libv4l2_dev_ops *dev_ops; +void *dev_ops_priv;
Quoted 3 lines
Review
Quoted 3 lines
lib/libv4lconvert/libv4lconvert-priv.h +0
-0/* Data for external decompression helpers code */ pid_t decompress_pid;(quoted diff) +0
-0
b/lib/libv4lconvert/libv4lconvert.c
Quoted 7 lines
Quoted 7 lines
index 0d8b29f..f6e0327 100644
lib/libv4lconvert/libv4lconvert.c +0
-0@@ -91,7 +91,8 @@ static const int v4lconvert_crop_res[][2] = { { 176, 144 }, };
Quoted 6 lines
lib/libv4lconvert/libv4lconvert.c static const int v4lconvert_crop_res[][2] = {
Quoted 6 lines
lib/libv4lconvert/libv4lconvert.c +2
-1-struct v4lconvert_data *v4lconvert_create (int fd) +struct v4lconvert_data *v4lconvert_create (int fd,void *dev_ops_priv, +struct libv4l2_dev_ops *dev_ops) {int i, j; struct v4lconvert_data *data = calloc(1, sizeof(struct
v4lconvert_data));
Quoted 8 lines
Quoted 8 lines
lib/libv4lconvert/libv4lconvert.c +2
-0@@ -107,6 +108,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) } data->fd = fd; + data->dev_ops = dev_ops; + data->dev_ops_priv = dev_ops_priv; data->decompress_pid =-1 ;
Quoted 7 lines
lib/libv4lconvert/libv4lconvert.c struct v4lconvert_data *v4lconvert_create(int fd) · line 121
Quoted 7 lines
lib/libv4lconvert/libv4lconvert.c +1
-1/* Check supported formats */ @@ -115,7 +118,7 @@ struct v4lconvert_data *v4lconvert_create(int fd) fmt.index = i; -if (SYS_IOCTL (data->fd,VIDIOC_ENUM_FMT ,&fmt)) + if (data->dev_ops->ioctl(data->dev_ops_priv, data->fd,
VIDIOC_ENUM_FMT,&fmt))
Quoted 17 lines
Quoted 17 lines
lib/libv4lconvert/libv4lconvert.c +2
-1break ;for (j =0 ; j<ARRAY_SIZE (supported_src_pixfmts); j++)@@ -134,7 +137,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) data->no_formats = i;/* Check if this cam has any special flags */ -if (SYS_IOCTL (data->fd,VIDIOC_QUERYCAP ,&cap) ==0 ) { +if (data->dev_ops->ioctl (data->dev_ops_priv, + data->fd,VIDIOC_QUERYCAP ,&cap) ==0 ) {if (!strcmp ((char *)cap.driver,"uvcvideo" )) data->flags |=V4LCONVERT_IS_UVC ;@@ -142,7 +146,8 @@ struct v4lconvert_data *v4lconvert_create(int fd) always_needs_conversion =0 ; }
Quoted 7 lines
lib/libv4lconvert/libv4lconvert.c int v4lconvert_enum_fmt(struct v4lconvert_data *data,
Quoted 7 lines
lib/libv4lconvert/libv4lconvert.c +2
-1- data->control =v4lcontrol_create (fd, always_needs_conversion); + data->control =v4lcontrol_create (fd, dev_ops_priv, dev_ops, + always_needs_conversion);if (!data->control) {free (data);return NULL ;@@ -205,7 +210,8 @@ int v4lconvert_enum_fmt(struct v4lconvert_data *data,
struct v4l2_fmtdesc *fmt)
Quoted 10 lines
lib/libv4lconvert/libv4lconvert.c static int v4lconvert_do_try_format(struct
Quoted 10 lines
lib/libv4lconvert/libv4lconvert.c +2
-1if (fmt->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE || (!v4lconvert_supported_dst_fmt_only (data)&& fmt->index< data->no_formats)) -return SYS_IOCTL (data->fd,VIDIOC_ENUM_FMT , fmt); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FMT , fmt);for (i =0 ; i<ARRAY_SIZE (supported_dst_pixfmts); i++) if (v4lconvert_supported_dst_fmt_only(data) ||@@ -313,7 +319,8 @@ static int v4lconvert_do_try_format(struct
v4lconvert_data *data,
Quoted 7 lines
lib/libv4lconvert/libv4lconvert.c static int v4lconvert_do_try_format(struct v4lconvert_data *data,
Quoted 7 lines
lib/libv4lconvert/libv4lconvert.c +2
-1try_fmt = *dest_fmt; try_fmt.fmt.pix.pixelformat = supported_src_pixfmts[i].fmt; -if (!SYS_IOCTL (data->fd,VIDIOC_TRY_FMT ,&try_fmt)) { +if (!data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_TRY_FMT ,&try_fmt)) { if (try_fmt.fmt.pix.pixelformat ==
supported_src_pixfmts[i].fmt) {
Quoted 3 lines
lib/libv4lconvert/libv4lconvert.c int v4lconvert_try_format(struct v4lconvert_data
Quoted 3 lines
lib/libv4lconvert/libv4lconvert.c +0
-0int size_x_diff =abs ((int )try_fmt.fmt.pix.width - (int )dest_fmt->fmt.pix.width);@@ -381,7 +388,8 @@ int v4lconvert_try_format(struct v4lconvert_data
*data,
Quoted 1 line
lib/libv4lconvert/libv4lconvert.c int v4lconvert_try_format(struct v4lconvert_data · line 388
Quoted 1 line
lib/libv4lconvert/libv4lconvert.c +0
-0if (!v4lconvert_supported_dst_format(dest_fmt->fmt.pix.pixelformat)
||
> > dest_fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
> > v4lconvert_do_try_format(data,&try_dest,&try_src)) {Quoted 7 lines
lib/libv4lconvert/libv4lconvert.c static void v4lconvert_get_framesizes(struct
Quoted 7 lines
lib/libv4lconvert/libv4lconvert.c +2
-1- result =SYS_IOCTL (data->fd,VIDIOC_TRY_FMT , dest_fmt); + result = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_TRY_FMT , dest_fmt);if (src_fmt) *src_fmt = *dest_fmt;return result;@@ -1236,7 +1244,8 @@ static void v4lconvert_get_framesizes(struct
v4lconvert_data *data,
Quoted 9 lines
lib/libv4lconvert/libv4lconvert.c static void v4lconvert_get_framesizes(struct v4lconvert_data *data,
Quoted 9 lines
lib/libv4lconvert/libv4lconvert.c +2
-1for (i =0 ; ; i++) { frmsize.index = i; -if (SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMESIZES ,&frmsize)) +if (data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMESIZES ,&frmsize))break ;/* We got a framesize, check we don't have the same one already
*/
Quoted 1 line
lib/libv4lconvert/libv4lconvert.c int v4lconvert_enum_framesizes(struct
Quoted 1 line
lib/libv4lconvert/libv4lconvert.c +0
-0@@ -1296,7 +1305,8 @@ int v4lconvert_enum_framesizes(struct
v4lconvert_data *data,
Quoted 10 lines
lib/libv4lconvert/libv4lconvert.c int v4lconvert_enum_frameintervals(struct
Quoted 10 lines
lib/libv4lconvert/libv4lconvert.c +2
-1errno =EINVAL ;return -1 ; } -return SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMESIZES , frmsize); +return data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMESIZES , frmsize); }if (frmsize->index>= data->no_framesizes) {@@ -1332,7 +1342,8 @@ int v4lconvert_enum_frameintervals(struct
v4lconvert_data *data,
Quoted 10 lines
lib/libv4lconvert/libv4lconvert.c int v4lconvert_enum_frameintervals(struct
Quoted 10 lines
lib/libv4lconvert/libv4lconvert.c +2
-1errno =EINVAL ;return -1 ; } - res =SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMEINTERVALS , frmival); + res = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMEINTERVALS , frmival);if (res)V4LCONVERT_ERR ("%s\n" ,strerror (errno));return res;@@ -1377,7 +1388,8 @@ int v4lconvert_enum_frameintervals(struct
v4lconvert_data *data,
Quoted 15 lines
lib/libv4lconvert/libv4lconvert.c int v4lconvert_enum_frameintervals(struct v4lconvert_data *data, · line 1395
Quoted 9 lines
lib/libv4lconvert/libv4lconvert.c +2
-1frmival->pixel_format = src_fmt.fmt.pix.pixelformat; frmival->width = src_fmt.fmt.pix.width; frmival->height = src_fmt.fmt.pix.height; - res =SYS_IOCTL (data->fd,VIDIOC_ENUM_FRAMEINTERVALS , frmival); + res = data->dev_ops->ioctl (data->dev_ops_priv, data->fd, +VIDIOC_ENUM_FRAMEINTERVALS , frmival);if (res) {int dest_pixfmt = dest_fmt.fmt.pix.pixelformat;int src_pixfmt = src_fmt.fmt.pix.pixelformat;--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/1 v3] libv4l: Add plugin support to libv4l
In reply to Hans de GoedeQuoted 2 lines · Hans de Goede
Hi,
Hi Hans,
Thanks for your comments.
Quoted 10 lines
First of all my apologies for taking so long to get around to reviewing this.
Over all it looks good, I've put some small remarks inline, if you fix these I can merge this. I wonder though, given the recent limbo around Nokia's change of focus, if there are any plans to actually move forward with a plugin using this... ?
The reason I'm asking is that adding the plugin framework if nothing is going to use it seems a bit senseless.
We are working on a "media controller" plugin which allows
a traditional v4l2 application to work with Media Controller framework. The idea is when the application opens /dev/video0, then the plugin initializes media controller and creates appropriate pipeline, after that the plugin redirects all ioctl's from the application to this pipeline and on close call the pipeline is deinitialized.
Quoted 7 lines
Regards,
Hans
On 02/14/2011 12:02 PM, Yordan Kamenov wrote:
[snip]
Quoted 18 lines
Quoted 18 lines
lib/libv4l2/v4l2convert.c +0
-1@@ -46,7 +46,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...) {int fd; -struct v4l2_capability cap;int v4l_device =0 ;/* check if we're opening a video4linux2 device */ @@ -76,14 +75,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...)if (fd ==-1 || !v4l_device)return fd;
Quoted 16 lines
Quoted 10 lines
lib/libv4l2/v4l2convert.c +0
-1-/* check that this is an v4l2 device, libv4l2 only supports v4l2 devices */
lib/libv4l2/v4l2convert.c +0
-7-if (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 Quoted 3 lines
to the
application as is) */
v4l2_fd_open(fd, 0);Hmm, why are you removing this check ?
In case of above example of media controller plugin when the application opens /dev/video0, then this plugin should be used. But in media controller framework /dev/video0 file might correspond to a subdevice which is not a capture device and this fd will not be registered in libv4l2 at all.
Regards
Yordan
Re: [PATCH 1/1 v3] libv4l: Add plugin support to libv4l
Hi,
Quoted 14 lines · Yordan Kamenov
Quoted 2 lines · Hans de Goede
Hi,
Hi Hans,
Thanks for your comments.
Quoted 8 lines
First of all my apologies for taking so long to get around to reviewing this.
Over all it looks good, I've put some small remarks inline, if you fix these I can merge this. I wonder though, given the recent limbo around Nokia's change of focus, if there are any plans to actually move forward with a plugin using this... ?
Quoted 8 lines
Quoted 2 lines
The reason I'm asking is that adding the plugin framework if nothing is going to use it seems a bit senseless.
We are working on a "media controller" plugin which allows
a traditional v4l2 application to work with Media Controller framework. The idea is when the application opens/dev/video0, then the plugin initializes media controller and creates appropriate pipeline, after that the plugin redirects all ioctl's from the application to this pipeline and on close call the pipeline is deinitialized.
Cool.
Quoted 39 lines
Quoted 7 lines
Regards,
Hans
On 02/14/2011 12:02 PM, Yordan Kamenov wrote:
[snip]
Quoted 17 lines
Quoted 17 lines
lib/libv4l2/v4l2convert.c +0
-1@@ -46,7 +46,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...) {int fd; -struct v4l2_capability cap;int v4l_device =0 ;/* check if we're opening a video4linux2 device */ @@ -76,14 +75,6 @@ LIBV4L_PUBLIC int open(const char *file, int oflag, ...)if (fd ==-1 || !v4l_device)return fd;Quoted 14 lines
Quoted 11 lines
lib/libv4l2/v4l2convert.c +0
-8-/* check that this is an v4l2 device, libv4l2 only supports v4l2 devices */ -if (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, 0);Hmm, why are you removing this check ?
Quoted 5 lines
In case of above example of media controller plugin when the application opens
/dev/video0, then this plugin should be used. But in media controller framework/dev/video0file might correspond to a subdevice which is not a capture device and this fd will not be registered in libv4l2 at all.
Ok, on second thought this is fine, you can leave it in :)
Regards,
Hans