Media controller plugin for libv4l2
Subsystems (2)
cover Media controller plugin for libv4l2
Hi,
This is the Media Controller plugin for libv4l. It uses libv4l2 plugin support which is accepted by Hans De Goede, but not yet included in mainline libv4l2:
http://www.spinics.net/lists/linux-media/msg32017.html
The plugin allows a traditional v4l2 applications to work with Media Controller framework. The plugin is loaded when application opens /dev/video0 and it configures the media controller and then all ioctl's by the applicatin are handled by the plugin.
The plugin implements init, close and ioctl callbacks. The init callback checks it's input file descriptor and if it coresponds to /dev/video0, then the media controller is initialized and appropriate pipeline is created. The close callback deinitializes the pipeline, and closes the media device. The ioctl callback is responsible to handle ioctl calls from application by using the media controller pipeline.
The plugin uses media-ctl library for media controller operations:
http://git.ideasonboard.org/?p=media-ctl.git;a=summary
The plugin is divided in three separate patches:
* Media Controller pipelines initialization, configuration and destruction
* v4l operations - uses some functionality from the first one
* Plugin interface operations (init, close and ioctl) - uses functionality from first two
Yordan Kamenov (3):
Add files for media controller pipelines Add files for v4l operations
Add libv4l2 media controller plugin interface files
PATCH 1/3 Add files for media controller pipelines
Add Makefile.
Add files for Media Controller pipelines initialization, configuration and destruction.
Add file for list operations.
Add config file.
--- Makefile | 30 ++ omap3-mc.conf | 82 +++++ paths.c | 959 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ paths.h | 64 ++++ sl_list.h | 65 ++++ 5 files changed, 1200 insertions(+), 0 deletions(-) create mode 100644 Makefile create mode 100644 omap3-mc.conf create mode 100644 paths.c create mode 100644 paths.h create mode 100644 sl_list.h
Makefile new file +30 -0
@@ -0,0 +1,30 @@ +ARCH ?= arm +KDIR ?= /usr/src/linux +LIBV4LINCDIR ?= ../../v4l-utils/lib/include/ +LIBMEDIACTLDIR ?= /usr/local/lib +CONF_INST_DIR := $(DESTDIR)/etc/libv4l2plugins +PLUGIN_INST_DIR := $(DESTDIR)/usr/lib/libv4l/plugins + +KINC := -I$(KDIR)/include -I$(KDIR)/arch/$(ARCH)/include +INC := -I$(LIBV4LINCDIR) $(KINC) +CC := $(CROSS_COMPILE)gcc + +LDFLAGS += -L$(LIBMEDIACTLDIR) -lmediactl + +CFLAGS += -O2 -Wall -fpic -I. $(INC) +OBJS = libv4l2plugin-omap3mc.o paths.o operations.o + +all: libv4l2plugin-omap3mc.so + +libv4l2plugin-omap3mc.so: $(OBJS) + $(CC) $(CFLAGS) -shared $(LDFLAGS) -o libv4l2plugin-omap3mc.so $(OBJS) +clean: + rm -f $(OBJS) libv4l2plugin-omap3mc.so + +install: libv4l2plugin-omap3mc.so + test -z "$(CONF_INST_DIR)" || mkdir -p "$(CONF_INST_DIR)" + install -m 666 omap3-mc.conf "$(CONF_INST_DIR)" + test -z "$(PLUGIN_INST_DIR)" || mkdir -p "$(PLUGIN_INST_DIR)" + install -m 755 libv4l2plugin-omap3mc.so "$(PLUGIN_INST_DIR)" + +.PHONY: clean all
omap3-mc.conf new file +82 -0
82 lines not on this page · raw message
paths.c new file +959 -0
959 lines not on this page · raw message
paths.h new file +64 -0
64 lines not on this page · raw message
sl_list.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.7.3.1
PATCH 2/3 Add files for v4l operations
In reply to Yordan KamenovAdd files with implementation of v4l ioctls.
--- operations.c | 611 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ operations.h | 44 +++++ 2 files changed, 655 insertions(+), 0 deletions(-) create mode 100644 operations.c create mode 100644 operations.h
operations.c new file +611 -0
@@ -0,0 +1,611 @@ +/* +* Copyright (C) 2011 Nokia Corporation +* +* Contact: Yordan Kamenov <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +*/ + +#include <stdarg.h> +#include <unistd.h> +#include <sys/syscall.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <stddef.h> + +#include <linux/v4l2-subdev.h> + +#include "sl_list.h" +#include "operations.h" +#include "paths.h" + +#define CHECK_DST_SUBMODULE (dst_sm, error_msg) {\ + if ((dst_sm) == NULL) {\ + MC_PLUGIN_PRINTF(error_msg);\ + errno = EBADF;\ + return -1;\ + }\ +} + +int mc_vidioc_streamon (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +enum v4l2_buf_type type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; +struct sub_module *dst_sub_module =NULL ; + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"streamon failed\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_STREAMON , &type); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("streamon: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +} + +int mc_vidioc_streamoff (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +enum v4l2_buf_type type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; +struct sub_module *dst_sub_module =NULL ; + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"streamoff failed\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_STREAMOFF , &type); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("streamoff: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +} + +int mc_vidioc_s_fmt (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int pix_count, res_count, found =0 , ret =-1 ; +enum mc_plugin_pixelformat src_pixfmt, dst_pixfmt, temp_pixfmt; +struct v4l2_rect src_res, dst_res; +const int max_rect =10 ; +struct v4l2_rect res[max_rect]; +struct v4l2_format *arg; +va_list ap; +enum mc_plugin_pixelformat pixfmt; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_format *); +va_end (ap); + + pixfmt =pixel_v4l_to_mc_plugin (arg->fmt.pix.pixelformat); + +/* Check if destionation format is supported from pipeline */ +for (pix_count =0 ; +MC_PLUGIN_PIX_FMT_INVALID != plugin->path->pipe->out_pixfmt[pix_count]; + pix_count++) +if (pixfmt == plugin->path->pipe->out_pixfmt[pix_count]) { + dst_pixfmt = pixfmt; + ret =0 ; +break ; + } + +if (ret <0 ) { +MC_PLUGIN_PRINTF ("Destination format not supported\n" ); + errno =EINVAL ; +return ret; + } + +for (pix_count =0 ; +MC_PLUGIN_PIX_FMT_INVALID != plugin->path->pipe->in_pixfmt[pix_count]; + pix_count++) { + +memset (res,0x0 ,sizeof (res)); + src_pixfmt = plugin->path->pipe->in_pixfmt[pix_count]; + temp_pixfmt = src_pixfmt; + + ret =path_enum_src_framesizes (plugin, &src_pixfmt, res, max_rect); + +/* Find Best capture resolution */ +for (res_count =0 ; res_count < max_rect; res_count++) { + + src_res = res[res_count]; + dst_res.width = arg->fmt.pix.width; + dst_res.height = arg->fmt.pix.height; + +/* If width and height are not valid we reach end of resolutions */ +if (0 == res[res_count].width &&0 == res[res_count].height) +break ; + + ret =path_set_resolution (plugin, &src_res, &src_pixfmt, + &dst_res, &dst_pixfmt); +if (ret <0 ) { +MC_PLUGIN_PRINTF ("Set Resolution fail!\n" ); +break ; + } + +if (dst_res.width == arg->fmt.pix.width && + dst_res.height == arg->fmt.pix.height && + temp_pixfmt == src_pixfmt) { +/* Capture resolution found */ + found =1 ; +break ; + } + } + +if (1 == found) +break ; + } + +return ret; +} + +int mc_vidioc_g_fmt (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_format *arg; +va_list ap; +struct sub_module *dst_sub_module =NULL ; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_format *); +va_end (ap); + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"get format failed\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_G_FMT , arg); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("get format: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +} + +int mc_vidioc_try_fmt (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int pix_count, res_count, found =0 , ret =-1 ; +enum mc_plugin_pixelformat src_pixfmt, dst_pixfmt, temp_pixfmt; +struct v4l2_rect src_res, dst_res; +const int max_rect =10 ; +struct v4l2_rect res[max_rect]; +struct v4l2_format *arg; +va_list ap; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_format *); +va_end (ap); + +enum mc_plugin_pixelformat pixfmt =pixel_v4l_to_mc_plugin (arg->fmt.pix.pixelformat); + +/* Check if destionation format is supported from pipeline */ +for (pix_count =0 ; +MC_PLUGIN_PIX_FMT_INVALID != plugin->path->pipe->out_pixfmt[pix_count]; + pix_count++) +if (pixfmt == plugin->path->pipe->out_pixfmt[pix_count]) { + dst_pixfmt = pixfmt; + ret =0 ; +break ; + } + +if (ret <0 ) { +MC_PLUGIN_PRINTF ("Destination format not supported\n" ); + errno =EINVAL ; +return ret; + } + +for (pix_count =0 ; +MC_PLUGIN_PIX_FMT_INVALID != plugin->path->pipe->in_pixfmt[pix_count]; + pix_count++) { + +memset (res,0x0 ,sizeof (res)); + src_pixfmt = plugin->path->pipe->in_pixfmt[pix_count]; + temp_pixfmt = src_pixfmt; + + ret =path_enum_src_framesizes (plugin, &src_pixfmt, res, max_rect); + +/* Find Best capture resolution */ +for (res_count =0 ; res_count < max_rect; res_count++) { + + src_res = res[res_count]; + dst_res.width = arg->fmt.pix.width; + dst_res.height = arg->fmt.pix.height; + +/* If width and height are not valid we reach end of resolutions */ +if (0 == res[res_count].width &&0 == res[res_count].height) +break ; + + ret =path_try_resolution (plugin, &src_res, &src_pixfmt, + &dst_res, &dst_pixfmt); +if (ret <0 ) { +MC_PLUGIN_PRINTF ("Set Resolution fail!\n" ); +break ; + } + +if (dst_res.width == arg->fmt.pix.width && + dst_res.height == arg->fmt.pix.height && + temp_pixfmt == src_pixfmt) { +/* Capture resolution found */ + found =1 ; +break ; + } + } + +if (1 == found) +break ; + } + +return ret; +} + +int mc_vidioc_s_crop (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_subdev_crop s_crop; +struct v4l2_crop *arg; +va_list ap; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_crop *); +va_end (ap); + +memset (&s_crop,0 ,sizeof (s_crop)); + s_crop.pad =0 ;/* It has only one sink pad */ + s_crop.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + s_crop.rect.top = arg->c.top; + s_crop.rect.left = arg->c.left; + s_crop.rect.width = arg->c.width; + s_crop.rect.height = arg->c.height; + + ret =SYS_IOCTL (plugin->fd,VIDIOC_SUBDEV_S_CROP , &s_crop); +if (ret <0 ) { +MC_PLUGIN_PRINTF ("set crop: %s\n" ,strerror (errno)); + }else { + arg->c.top = s_crop.rect.top; + arg->c.left = s_crop.rect.left; + arg->c.width = s_crop.rect.width; + arg->c.height = s_crop.rect.height; + } + +return ret; +} + +int mc_vidioc_g_crop (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_subdev_crop g_crop; +struct v4l2_crop *arg; +va_list ap; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_crop *); +va_end (ap); + +memset (&g_crop,0 ,sizeof (g_crop)); + g_crop.pad =0 ;/* It has only one sink pad */ + g_crop.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + + ret =SYS_IOCTL (plugin->fd,VIDIOC_SUBDEV_G_CROP , &g_crop); +if (ret <0 ) { +MC_PLUGIN_PRINTF ("get crop: %s\n" ,strerror (errno)); + }else { + arg->c.top = g_crop.rect.top; + arg->c.left = g_crop.rect.left; + arg->c.width = g_crop.rect.width; + arg->c.height = g_crop.rect.height; + } + +return ret; +} + +int mc_vidioc_queryctrl (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct sub_module *sub_mod; +struct v4l2_queryctrl *arg; +va_list ap; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_queryctrl *); +va_end (ap); + +list_for_each_entry (sub_mod, &plugin->path->container, list) { + ret =SYS_IOCTL (sub_mod->entity->fd,VIDIOC_QUERYCTRL , arg); +if (ret ==0 ) +break ; + } + +return ret; +} + +int mc_vidioc_g_ctrl (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct sub_module *sub_mod; +struct v4l2_control *arg; +va_list ap; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_control *); +va_end (ap); + +list_for_each_entry (sub_mod, &plugin->path->container, list) { + ret =SYS_IOCTL (sub_mod->entity->fd,VIDIOC_G_CTRL , arg); +if (ret ==0 ) +break ; + } + +return ret; +} + +int mc_vidioc_s_ctrl (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct sub_module *sub_mod; +struct v4l2_control *arg; +va_list ap; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_control *); +va_end (ap); + +list_for_each_entry (sub_mod, &plugin->path->container, list) { + ret =SYS_IOCTL (sub_mod->entity->fd,VIDIOC_S_CTRL , arg); +if (ret ==0 ) +break ; + } + +return ret; +} + +int mc_vidioc_querycap (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_capability *arg; +va_list ap; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_capability *); +va_end (ap); + + ret =SYS_IOCTL (plugin->fd,VIDIOC_QUERYCAP , arg); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("query capabilities: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +} + +int mc_vidioc_enum_fmt (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_fmtdesc *arg; +va_list ap; +struct v4l2_subdev_mbus_code_enum mbus_format; +struct sub_module *dst_sub_module =NULL ; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_fmtdesc *); +va_end (ap); + + mbus_format.pad =0 ; + mbus_format.index = arg->index; + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"enum fmt failed\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_SUBDEV_ENUM_MBUS_CODE , &mbus_format); +if (ret ==0 ) { + arg->flags =0 ; + arg->pixelformat =pixel_mc_plugin_to_v4l (mbus_format.code); + } + +return ret; +} + +int mc_vidioc_enum_framesizes (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_frmsizeenum *arg; +va_list ap; +struct sub_module *dst_sub_module =NULL ; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_frmsizeenum *); +va_end (ap); + + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"enum framesizes\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_ENUM_FRAMESIZES , arg); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("enum framesizes: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +} + +int mc_vidioc_enum_frameintervals (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct media_entity *source, *sink; +struct media_link *link; +struct v4l2_subdev_frame_interval_enum e_interval; +const char *sink_name, *source_name; +struct v4l2_frmivalenum *arg; +va_list ap; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_frmivalenum *); +va_end (ap); + + source_name = plugin->path->pipe->path[0 ]; + sink_name = plugin->path->pipe->path[1 ]; + + source =media_get_entity_by_name (plugin->media, source_name,strlen (source_name)); + sink =media_get_entity_by_name (plugin->media, sink_name,strlen (sink_name)); + +if ((NULL == sink) || (NULL == source)) { +MC_PLUGIN_PRINTF ("Error finding entities\n" ); + errno =EBADF ; +return -1 ; + } + + link =media_find_link (plugin->media, source, sink); + +if (NULL == link) { +MC_PLUGIN_PRINTF ("No link present between source and sink\n" ); + errno =EBADF ; +return -1 ; + } + + e_interval.index = arg->index; + e_interval.code = arg->pixel_format; + e_interval.width = arg->width; + e_interval.height = arg->height; + e_interval.pad = link->source->index; + + ret =SYS_IOCTL (source->fd,VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL , &e_interval); +if (ret ==0 ) { + arg->type =V4L2_FRMIVAL_TYPE_DISCRETE ; + arg->discrete.numerator = e_interval.interval.numerator; + arg->discrete.denominator = e_interval.interval.denominator; + } + +return ret; +} + +int mc_vidioc_reqbufs (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_requestbuffers *arg; +va_list ap; +struct sub_module *dst_sub_module =NULL ; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_requestbuffers *); +va_end (ap); + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"request buffer failed\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_REQBUFS , arg); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("request buffer: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +} + +int mc_vidioc_querybuf (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_buffer *arg; +va_list ap; +struct sub_module *dst_sub_module =NULL ; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_buffer *); +va_end (ap); + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"query failed\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_QUERYBUF , arg); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("query buffer: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +} + +int mc_vidioc_qbuf (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_buffer *arg; +va_list ap; +struct sub_module *dst_sub_module =NULL ; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_buffer *); +va_end (ap); + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"queue buffer failed\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_QBUF , arg); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("queue buffer: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +} + +int mc_vidioc_dqbuf (struct omap3mcplugin *plugin,unsigned long int request, ...) +{ +int ret =-1 ; +struct v4l2_buffer *arg; +va_list ap; +struct sub_module *dst_sub_module =NULL ; + +va_start (ap, request); + arg = va_arg(ap, struct v4l2_buffer *); +va_end (ap); + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +CHECK_DST_SUBMODULE (dst_sub_module,"dequeue failed\n" ); + + ret =SYS_IOCTL (dst_sub_module->entity->fd,VIDIOC_DQBUF , arg); +if (ret) { +int saved_err = errno; +MC_PLUGIN_PRINTF ("dequeue buffer: %s\n" ,strerror (errno)); + errno = saved_err; + } + +return ret; +}
operations.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
1.7.3.1
PATCH 3/3 Add libv4l2 media controller plugin interface files
In reply to Yordan KamenovAdd interface functions init(), close() and ioctl(), called by libv4l2.
--- libv4l2plugin-omap3mc.c | 241 +++++++++++++++++++++++++++++++++++++++++++++++ libv4l2plugin-omap3mc.h | 91 ++++++++++++++++++ 2 files changed, 332 insertions(+), 0 deletions(-) create mode 100644 libv4l2plugin-omap3mc.c create mode 100644 libv4l2plugin-omap3mc.h
libv4l2plugin-omap3mc.c new file +241 -0
@@ -0,0 +1,241 @@ +/* +* Copyright (C) 2011 Nokia Corporation +* +* Contact: Yordan Kamenov <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +*/ + +#include <unistd.h> +#include <sys/syscall.h> +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <glob.h> +#include <linux/videodev2.h> +#include <mediactl/media.h> + +#include "libv4l2-plugin.h" +#include "libv4l2plugin-omap3mc.h" +#include "paths.h" +#include "operations.h" + +#if __GNUC__ >=4 +#define PLUGIN_PUBLIC __attribute__ ((visibility("default"))) +#define PLUGIN_HIDDEN __attribute__ ((visibility("hidden"))) +#else +#define PLUGIN_PUBLIC +#define PLUGIN_HIDDEN +#endif + +/* Check if /dev/media0 is already open*/ +int media_in_use () +{ +int glob_ret, file, ret =0 ; +glob_t globbuf; +ssize_t link_len; +char file_name[16 ]; + + glob_ret =glob ("/proc/self/fd/*" ,0 ,NULL , &globbuf); + +if (glob_ret ==GLOB_NOSPACE ) +return ret; + +if (glob_ret ==GLOB_ABORTED || glob_ret ==GLOB_NOMATCH ) + goto leave; + +for (file =0 ; file < globbuf.gl_pathc; file++) { + link_len =readlink (globbuf.gl_pathv[file], + file_name,strlen (MEDIA_DEVICE )); +if (link_len ==strlen (MEDIA_DEVICE )) + file_name[link_len] ='\0' ; +else +continue ; + +if (!strncmp (file_name,MEDIA_DEVICE ,strlen (MEDIA_DEVICE ))) { + ret =1 ; +break ; + } + } + +leave: +globfree (&globbuf); + +return ret; +} + +PLUGIN_HIDDEN void * omap3mc_init(int fd) +{ +int ret =-1 , primary; +struct omap3mcplugin *plugin; +const struct capture_pipeline *pipe =NULL ; +struct sub_module *dst_sub_module =NULL ; +char link_path[20 ]; +ssize_t link_len; +char file[VIDEO_NODE_LENGTH +1 ]; + +/* Get filename from fd */ +sprintf (link_path,"/proc/self/fd/%d" , fd); + link_len =readlink (link_path, file,VIDEO_NODE_LENGTH ); +if (link_len ==VIDEO_NODE_LENGTH ) + link_path[link_len] ='\0' ; +else +return NULL ; + +/* FIXME: What we do if the application is aware of video nodes +and tries to open() real /dev/video0 (CSI2 capture) */ +if (strncmp (file,VIDEO_PRIMARY ,strlen (VIDEO_PRIMARY )) ==0 ) + primary =1 ; +else if (strncmp (file,VIDEO_SECONDARY ,strlen (VIDEO_SECONDARY )) ==0 ) + primary =0 ; +else +return NULL ; + +if (media_in_use ()) +return NULL ; + + plugin =calloc (1 ,sizeof (*plugin)); +if (plugin ==NULL ) +return NULL ; + + plugin->media =media_open (MEDIA_DEVICE ,1 ); +if (plugin->media ==NULL ) { +free (plugin); +return NULL ; + } + + pipe =pipe_sensor_yuv (primary); + +if (pipe) + plugin->path =path_allocate (plugin->media, pipe); + +if (plugin->path) + dst_sub_module =path_destination_submodule (plugin->path); + +if (dst_sub_module) + ret =path_power_on (plugin->path, fd); + +if (ret ==0 ) + ret =path_connect_entities (plugin->media, plugin->path); + + plugin->fd = dst_sub_module->entity->fd; + +if (ret !=0 ) { +path_disconnect_entities (plugin->media, plugin->path); +path_power_off (plugin->path); + +media_close (plugin->media); +free (plugin); + plugin =NULL ; + } + +return plugin; +} + +PLUGIN_HIDDEN void omap3mc_close(void *dev_ops_priv) +{ +struct omap3mcplugin *plugin; + +if (dev_ops_priv ==NULL ) +return ; + + plugin = (struct omap3mcplugin *)dev_ops_priv; + +path_disconnect_entities (plugin->media, plugin->path); +path_power_off (plugin->path); + +media_close (plugin->media); + +free (plugin); +} + +PLUGIN_HIDDEN int omap3mc_ioctl(void *dev_ops_priv, int fd, +unsigned long int request,void *arg) +{ +int ret =-1 ; +struct omap3mcplugin *plugin; + + plugin = (struct omap3mcplugin *)dev_ops_priv; + +switch (request) { +case VIDIOC_STREAMON : + ret =mc_vidioc_streamon (plugin, request, arg); +break ; +case VIDIOC_STREAMOFF : + ret =mc_vidioc_streamoff (plugin, request, arg); +break ; +case VIDIOC_S_FMT : + ret =mc_vidioc_s_fmt (plugin, request, arg); +break ; +case VIDIOC_G_FMT : + ret =mc_vidioc_g_fmt (plugin, request, arg); +break ; +case VIDIOC_TRY_FMT : + ret =mc_vidioc_try_fmt (plugin, request, arg); +break ; +case VIDIOC_S_CROP : + ret =mc_vidioc_s_crop (plugin, request, arg); +break ; +case VIDIOC_G_CROP : + ret =mc_vidioc_g_crop (plugin, request, arg); +break ; +case VIDIOC_QUERYCTRL : + ret =mc_vidioc_queryctrl (plugin, request, arg); +break ; +case VIDIOC_G_CTRL : + ret =mc_vidioc_g_ctrl (plugin, request, arg); +break ; +case VIDIOC_S_CTRL : + ret =mc_vidioc_s_ctrl (plugin, request, arg); +break ; +case VIDIOC_QUERYCAP : + ret =mc_vidioc_querycap (plugin, request, arg); +break ; +case VIDIOC_ENUM_FMT : + ret =mc_vidioc_enum_fmt (plugin, request, arg); +break ; +case VIDIOC_ENUM_FRAMESIZES : + ret =mc_vidioc_enum_framesizes (plugin, request, arg); +break ; +case VIDIOC_ENUM_FRAMEINTERVALS : + ret =mc_vidioc_enum_frameintervals (plugin, request, arg); +break ; +case VIDIOC_REQBUFS : + ret =mc_vidioc_reqbufs (plugin, request, arg); +break ; +case VIDIOC_QUERYBUF : + ret =mc_vidioc_querybuf (plugin, request, arg); +break ; +case VIDIOC_QBUF : + ret =mc_vidioc_qbuf (plugin, request, arg); +break ; +case VIDIOC_DQBUF : + ret =mc_vidioc_dqbuf (plugin, request, arg); +break ; +default : + errno =EINVAL ; + ret =-1 ; +break ; + } + +return ret; +} + +PLUGIN_PUBLIC const struct libv4l2_dev_ops libv4l2_plugin = { + .init = &omap3mc_init, + .close = &omap3mc_close, + .ioctl = &omap3mc_ioctl, + .read =NULL +};
libv4l2plugin-omap3mc.h new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.3.1
Hi,
So judging from the directory layout, this is supposed to be a separate project, and not part of v4l-utils / libv4l, right?
WRT my merging plans for libv4l. I've recently done some much needed work to better support high-res usb cameras. I plan to do a 0.8.4 release with that work included real soon. Once that is done I'll change the version in the Make.rules to 0.9.0-test and merge the plugin. Then we'll have some 0.9.x releases followed by some 0.9.9x release (all testing releases) followed by a 0.10.0 which should be the first stable release with plugin support.
Regards,
Hans
Quoted 38 lines · Yordan Kamenov
Hi,
This is the Media Controller plugin for libv4l. It uses libv4l2 plugin support which is accepted by Hans De Goede, but not yet included in mainline libv4l2:
http://www.spinics.net/lists/linux-media/msg32017.htmlThe plugin allows a traditional v4l2 applications to work with Media Controller framework. The plugin is loaded when application opens
/dev/video0and it configures the media controller and then all ioctl's by the applicatin are handled by the plugin.The plugin implements init, close and ioctl callbacks. The init callback checks it's input file descriptor and if it coresponds to
/dev/video0, then the media controller is initialized and appropriate pipeline is created. The close callback deinitializes the pipeline, and closes the media device. The ioctl callback is responsible to handle ioctl calls from application by using the media controller pipeline.The plugin uses media-ctl library for media controller operations:
http://git.ideasonboard.org/?p=media-ctl.git;a=summaryThe plugin is divided in three separate patches:
* Media Controller pipelines initialization, configuration and destruction
* v4l operations - uses some functionality from the first one
* Plugin interface operations (init, close and ioctl) - uses functionality from first twoYordan Kamenov (3):
Add files for media controller pipelines Add files for v4l operations
Add libv4l2 media controller plugin interface files--
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
Quoted 1 line · Hans de Goede
Hi,
Hi Hans,
Quoted 4 lines
So judging from the directory layout, this is supposed to be a separate project, and not part of v4l-utils / libv4l, right?
It is separate now, but I guess that at some point it would be good to have 'plugins' directory containing some generic plugins as part of libv4l.
Regards
Yordan
Quoted 58 lines
WRT my merging plans for libv4l. I've recently done some much needed work to better support high-res usb cameras. I plan to do a 0.8.4 release with that work included real soon. Once that is done I'll change the version in the Make.rules to 0.9.0-test and merge the plugin. Then we'll have some 0.9.x releases followed by some 0.9.9x release (all testing releases) followed by a 0.10.0 which should be the first stable release with plugin support.
Regards,
Hans
Quoted 40 lines · Yordan Kamenov
Hi,
This is the Media Controller plugin for libv4l. It uses libv4l2 plugin support which is accepted by Hans De Goede, but not yet included in mainline libv4l2:
http://www.spinics.net/lists/linux-media/msg32017.htmlThe plugin allows a traditional v4l2 applications to work with Media Controller framework. The plugin is loaded when application opens
/dev/video0and it configures the media controller and then all ioctl's by the applicatin are handled by the plugin.The plugin implements init, close and ioctl callbacks. The init callback checks it's input file descriptor and if it coresponds to
/dev/video0, then the media controller is initialized and appropriate pipeline is created. The close callback deinitializes the pipeline, and closes the media device. The ioctl callback is responsible to handle ioctl calls from application by using the media controller pipeline.The plugin uses media-ctl library for media controller operations:
http://git.ideasonboard.org/?p=media-ctl.git;a=summaryThe plugin is divided in three separate patches:
* Media Controller pipelines initialization, configuration and
destruction
* v4l operations - uses some functionality from the first one
* Plugin interface operations (init, close and ioctl) - uses
functionality
from first twoYordan Kamenov (3):
Add files for media controller pipelines Add files for v4l operations
Add libv4l2 media controller plugin interface filesSignature · 3 lines
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.htmlSignature · 3 lines
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