Add a plugin for the Exynos4 camera
Subsystems (3)
v3 cover Add a plugin for the Exynos4 camera
This is a third version of the patch series adding a plugin for the Exynos4 camera.
Temporarily the plugin doesn't link against libmediactl, but has its sources compiled in. Currently libmediactl.la is built after the plugins and this will have to be resolved somehow.
================
Changes from v2:
================
- switched to using mediatext library for parsing
the media device configuration
- extended libmediactl
- switched to using libmediactl
================
Changes from v1:
================
- removed redundant mbus code negotiation
- split the parser, media device helpers and ioctl wrappers to the separate modules
- added mechanism for querying extended controls
- applied various fixes and modifications
The plugin was tested on latest media-tree.git master with patches for exynos4-is that fix failing open when a sensor sub-device is not linked [1] [2] [3].
The plugin expects a configuration file:/var/lib/libv4l/exynos4_capture_conf
Exemplary configuration file:
==========================================
link-conf "s5p-mipi-csis.0":1 -> "FIMC.0":0 [1] ctrl-to-subdev-conf 0x0098091f -> "fimc.0.capture" ctrl-to-subdev-conf 0x00980902 -> "S5C73M3" ctrl-to-subdev-conf 0x00980922 -> "fimc.0.capture" ctrl-to-subdev-conf 0x009a0914 -> "S5C73M3"
==========================================
With this settings the plugin can be tested on the exynos4412-trats2 board using following gstreamer pipeline:
gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-raw,width=960,height=720 ! fbdevsink
In order to avoid fbdevsink element failure the fix [4] for exynos-drm driver is required.
Thanks,
Jacek Anaszewski
[1] https://patchwork.linuxtv.org/patch/26366/
[2] https://patchwork.linuxtv.org/patch/26367/
[3] https://patchwork.linuxtv.org/patch/26368/
[4] http://www.spinics.net/lists/dri-devel/msg66494.html
Jacek Anaszewski (10):
mediactl: Introduce ctrl_to_subdev configuration
mediatext: Add library
mediactl: Add media device graph helpers
mediactl: Add media_device creation helpers
mediactl: Add subdev_fmt property to the media_entity
mediactl: Add VYUY8_2X8 media bus format
mediactl: Add support for media device pipelines
mediactl: Add media device ioctl API
mediactl: Close only pipeline sub-devices Add a libv4l plugin for Exynos4 camera
Sakari Ailus (1):
mediactl: Separate entity and pad parsing
configure.ac | 1 + lib/Makefile.am | 5 +- lib/libv4l-exynos4-camera/Makefile.am | 7 + lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c | 599 +++++++++++++++++++++ libmediatext.pc.in | 10 + utils/media-ctl/Makefile.am | 12 +- utils/media-ctl/libmediactl.c | 489 ++++++++++++++++- utils/media-ctl/libmediatext.pc.in | 10 + utils/media-ctl/libv4l2media_ioctl.c | 342 ++++++++++++ utils/media-ctl/libv4l2media_ioctl.h | 47 ++ utils/media-ctl/libv4l2subdev.c | 66 +++ utils/media-ctl/mediactl-priv.h | 17 + utils/media-ctl/mediactl.h | 282 ++++++++++ utils/media-ctl/mediatext-test.c | 66 +++ utils/media-ctl/mediatext.c | 303 +++++++++++ utils/media-ctl/mediatext.h | 52 ++ utils/media-ctl/v4l2subdev.h | 27 + 17 files changed, 2324 insertions(+), 11 deletions(-) create mode 100644 lib/libv4l-exynos4-camera/Makefile.am create mode 100644 lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c create mode 100644 libmediatext.pc.in create mode 100644 utils/media-ctl/libmediatext.pc.in create mode 100644 utils/media-ctl/libv4l2media_ioctl.c create mode 100644 utils/media-ctl/libv4l2media_ioctl.h create mode 100644 utils/media-ctl/mediatext-test.c create mode 100644 utils/media-ctl/mediatext.c create mode 100644 utils/media-ctl/mediatext.h
Signature · 1 line
1.7.9.5
RFC v3 1/11 mediactl: Introduce ctrl_to_subdev configuration
Add an infrastructure for a ctrl_to_subdev configuration data. The ctrl_to_subdev config entry is designed for conveying information about the target sub-device in the media device pipeline for a v4l2 control related ioctl calls.
--- utils/media-ctl/libmediactl.c | 26 ++++++++++++++++++++++++++ utils/media-ctl/libv4l2subdev.c | 31 +++++++++++++++++++++++++++++++ utils/media-ctl/mediactl-priv.h | 8 ++++++++ utils/media-ctl/mediactl.h | 16 ++++++++++++++++ utils/media-ctl/v4l2subdev.h | 15 +++++++++++++++ 5 files changed, 96 insertions(+)
utils/media-ctl/libmediactl.c +26 -0
@@ -647,12 +647,20 @@ static struct media_device *__media_device_new(void)if (media ==NULL )return NULL ; + media->ctrl_to_subdev =malloc (sizeof (*media->ctrl_to_subdev)); +if (!media->ctrl_to_subdev) + goto err_cts_alloc; + media->fd =-1 ; media->refcount =1 ;media_debug_set_handler (media,NULL ,NULL );return media; + +err_cts_alloc: +free (media); +return NULL ; }struct media_device *media_device_new (const char *devnode)
@@ -710,6 +718,7 @@ void media_device_unref(struct media_device *media)free (media->entities);free (media->devnode); +free (media->ctrl_to_subdev);free (media); }
@@ -955,3 +964,20 @@ int media_parse_setup_links(struct media_device *media, const char *p)return *end ? -EINVAL :0 ; } + +/* ----------------------------------------------------------------------------- +* Configuration access +*/ + +struct media_entity *media_config_get_entity_by_cid (struct media_device *media, +int cid) +{ +int i; + +for (i =0 ; i < media->ctrl_to_subdev_count; ++i) { +if (media->ctrl_to_subdev[i].ctrl_id == cid) +return media->ctrl_to_subdev[i].entity; + } + +return NULL ; +}
utils/media-ctl/libv4l2subdev.c +31 -0
@@ -755,3 +755,34 @@ enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode(const char *string,return mbus_formats[i].code; } + +int v4l2_subdev_validate_v4l2_ctrl (struct media_device *media, +struct media_entity *entity, +__u32 ctrl_id) +{ +struct v4l2_query_ext_ctrl queryctrl; +int ret; + + ret =v4l2_subdev_open (entity); +if (ret <0 ) +return ret; + +/* Iterate through control ids */ + + queryctrl.id = ctrl_id; + + ret =ioctl (entity->fd,VIDIOC_QUERY_EXT_CTRL , &queryctrl); +if (!ret) { +media_dbg (media,"Validated control \"%s\" (0x%8.8x) on entity %s\n" , + queryctrl.name, + ctrl_id, + entity->info.name); +return 1 ; + } + +media_dbg (media,"Control (0x%8.8x) not supported on entity %s\n" , + queryctrl.name, + ctrl_id, + entity->info.name); +return 0 ; +}
utils/media-ctl/mediactl-priv.h +8 -0
@@ -47,6 +47,9 @@ struct media_device {struct media_entity *entities;unsigned int entities_count; +struct media_v4l2_ctrl_to_subdev *ctrl_to_subdev; +unsigned int ctrl_to_subdev_count; +void (*debug_handler)(void *, ...);void *debug_priv;
@@ -58,6 +61,11 @@ struct media_device { } def; }; +struct media_v4l2_ctrl_to_subdev { +__u32 ctrl_id; +struct media_entity *entity; +}; +#define media_dbg (media, ...) \ (media)->debug_handler((media)->debug_priv, __VA_ARGS__)
utils/media-ctl/mediactl.h +16 -0
@@ -420,4 +420,20 @@ int media_parse_setup_link(struct media_device *media,*/ int media_parse_setup_links (struct media_device *media,const char *p); +/** +* @brief Find target sub-device for the control +* @param media - media device. +* @param cid - v4l2 control identifier +* +* Check if there was a target sub-device defined +* for the control through a ctrl-to-subdev-conf config +* directive. +* +* @return associated entity if defined, or NULL when no +* config entry for the control was found +*/ +struct media_entity *media_config_get_entity_by_cid ( +struct media_device *media, +int cid); +#endif
utils/media-ctl/v4l2subdev.h +15 -0
@@ -255,4 +255,19 @@ const char *v4l2_subdev_pixelcode_to_string(enum v4l2_mbus_pixelcode code);*/ enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode (const char *string,unsigned int length); + +/** +* @brief Validate v4l2 control for a sub-device +* @param media - media device. +* @param entity - subdev-device media entity. +* @param ctrl_id - v4l2 control identifier +* +* Verify if the entity supports v4l2-control with ctrl_id. +* +* @return 1 if the control is supported, 0 otherwise. +*/ +int v4l2_subdev_validate_v4l2_ctrl (struct media_device *media, +struct media_entity *entity, +__u32 ctrl_id); +#endif
Signature · 1 line
1.7.9.5
Re: [v4l-utils RFC v3 01/11] mediactl: Introduce ctrl_to_subdev configuration
Hi Jacek,
Thanks for the update!
A few comments below.
Quoted 88 lines · Jacek Anaszewski
Add an infrastructure for a
ctrl_to_subdevconfiguration data. Thectrl_to_subdevconfig entry is designed for conveying information about the target sub-device in the media device pipeline for a v4l2 control related ioctl calls.Signed-off-by Jacek Anaszewski <[email protected]>Acked-by Kyungmin Park <[email protected]>--- utils/media-ctl/libmediactl.c | 26 ++++++++++++++++++++++++++ utils/media-ctl/libv4l2subdev.c | 31 +++++++++++++++++++++++++++++++ utils/media-ctl/mediactl-priv.h | 8 ++++++++ utils/media-ctl/mediactl.h | 16 ++++++++++++++++ utils/media-ctl/v4l2subdev.h | 15 +++++++++++++++ 5 files changed, 96 insertions(+)utils/media-ctl/libmediactl.c +26
-0@@ -647,12 +647,20 @@ static struct media_device *__media_device_new(void)if (media ==NULL )return NULL ; + media->ctrl_to_subdev =malloc (sizeof (*media->ctrl_to_subdev)); +if (!media->ctrl_to_subdev) + goto err_cts_alloc; + media->fd =-1 ; media->refcount =1 ;media_debug_set_handler (media,NULL ,NULL );return media; + +err_cts_alloc: +free (media); +return NULL ; }struct media_device *media_device_new (const char *devnode)@@ -710,6 +718,7 @@ void media_device_unref(struct media_device *media)free (media->entities);free (media->devnode); +free (media->ctrl_to_subdev);free (media); }@@ -955,3 +964,20 @@ int media_parse_setup_links(struct media_device *media, const char *p)return *end ? -EINVAL :0 ; } + +/* ----------------------------------------------------------------------------- +* Configuration access +*/ + +struct media_entity *media_config_get_entity_by_cid (struct media_device *media, +int cid) +{ +int i; + +for (i =0 ; i < media->ctrl_to_subdev_count; ++i) { +if (media->ctrl_to_subdev[i].ctrl_id == cid) +return media->ctrl_to_subdev[i].entity; + } + +return NULL ; +}utils/media-ctl/libv4l2subdev.c +10
-0@@ -755,3 +755,34 @@ enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode(const char *string,return mbus_formats[i].code; } + +int v4l2_subdev_validate_v4l2_ctrl (struct media_device *media, +struct media_entity *entity, +__u32 ctrl_id) +{ +struct v4l2_query_ext_ctrl queryctrl; +int ret; + + ret =v4l2_subdev_open (entity); +if (ret <0 )
utils/media-ctl/libv4l2subdev.c enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode(const char *string, · line 777
Quoted 10 lines
utils/media-ctl/libv4l2subdev.c +10
-0+return ret; + +/* Iterate through control ids */ + + queryctrl.id = ctrl_id; + + ret =ioctl (entity->fd,VIDIOC_QUERY_EXT_CTRL , &queryctrl); +if (!ret) { + media_dbg(media, "Validated control \"%s\" (0x%8.8x) on entity %s\n", + queryctrl.name,
Could you align the line start to right of the opening parenthesis?
Quoted 16 lines
utils/media-ctl/libv4l2subdev.c +11
-0+ ctrl_id, + entity->info.name); +return 1 ; + } + +media_dbg (media,"Control (0x%8.8x) not supported on entity %s\n" , + queryctrl.name, + ctrl_id, + entity->info.name); +return 0 ; +}utils/media-ctl/mediactl-priv.h +0
-0
utils/media-ctl/mediactl-priv.h struct media_device { · line 51
Quoted 5 lines
utils/media-ctl/mediactl-priv.h +2
-0@@ -47,6 +47,9 @@ struct media_device {struct media_entity *entities;unsigned int entities_count; +struct media_v4l2_ctrl_to_subdev *ctrl_to_subdev; +unsigned int ctrl_to_subdev_count;
The media device shouldn't have information related to subsystems that use it.
Instead of making this specific to controls, could you instead add a V4L2 (sub-device) specific pointer to each media entity? Controls information could be stored there.
I think we're going to need other information there as well.
Quoted 29 lines
utils/media-ctl/mediactl-priv.h +6
-0+void (*debug_handler)(void *, ...);void *debug_priv;@@ -58,6 +61,11 @@ struct media_device { } def; }; +struct media_v4l2_ctrl_to_subdev { +__u32 ctrl_id; +struct media_entity *entity; +}; +#define media_dbg (media, ...) \ (media)->debug_handler((media)->debug_priv, __VA_ARGS__)utils/media-ctl/mediactl.h +5
-0@@ -420,4 +420,20 @@ int media_parse_setup_link(struct media_device *media,*/ int media_parse_setup_links (struct media_device *media,const char *p); +/** +* @brief Find target sub-device for the control +* @param media - media device. +* @param cid - v4l2 control identifier +*
utils/media-ctl/mediactl.h int media_parse_setup_link(struct media_device *media, · line 437
Quoted 10 lines
utils/media-ctl/mediactl.h +10
-0+* Check if there was a target sub-device defined +* for the control through a ctrl-to-subdev-conf config +* directive. +* +* @return associated entity if defined, or NULL when no +* config entry for the control was found +*/ +struct media_entity *media_config_get_entity_by_cid ( +struct media_device *media, +int cid);
The two fit on a single line.
cid should be __u32 (or uint32_t).
Quoted 25 lines
utils/media-ctl/mediactl.h +0
-0#endif utils/media-ctl/v4l2subdev.h +15
-0@@ -255,4 +255,19 @@ const char *v4l2_subdev_pixelcode_to_string(enum v4l2_mbus_pixelcode code);*/ enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode (const char *string,unsigned int length); + +/** +* @brief Validate v4l2 control for a sub-device +* @param media - media device. +* @param entity - subdev-device media entity. +* @param ctrl_id - v4l2 control identifier +* +* Verify if the entity supports v4l2-control with ctrl_id. +* +* @return 1 if the control is supported, 0 otherwise. +*/ +int v4l2_subdev_validate_v4l2_ctrl (struct media_device *media, +struct media_entity *entity, +__u32 ctrl_id); +#endif
Signature · 4 lines
Kind regards, Sakari Ailus [email protected]
RFC v3 2/11 mediactl: Separate entity and pad parsing
In reply to Jacek AnaszewskiFrom: Sakari Ailus <[email protected]>
Sometimes it's useful to be able to parse the entity independent of the pad. Separate entity parsing into media_parse_entity().
--- utils/media-ctl/libmediactl.c | 28 ++++++++++++++++++++++++---- utils/media-ctl/mediactl.h | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-)
utils/media-ctl/libmediactl.c +24 -4
@@ -779,10 +779,10 @@ int media_device_add_entity(struct media_device *media,return 0 ; } -struct media_pad *media_parse_pad (struct media_device *media, -const char *p,char **endp) +struct media_entity *media_parse_entity (struct media_device *media, +const char *p,char **endp) { -unsigned int entity_id, pad; +unsigned int entity_id;struct media_entity *entity;char *end;
@@ -819,7 +819,27 @@ struct media_pad *media_parse_pad(struct media_device *media,return NULL ; } } -for (;isspace (*end); ++end); +for (p = end;isspace (*p); ++p); + + *endp = (char *)p; + +return entity; +} + +struct media_pad *media_parse_pad (struct media_device *media, +const char *p,char **endp) +{ +unsigned int pad; +struct media_entity *entity; +char *end; + +if (endp ==NULL ) + endp = &end; + + entity =media_parse_entity (media, p, &end); +if (!entity) +return NULL ; + *endp = end;if (*end !=':' ) {media_dbg (media,"Expected ':'\n" , *end);
utils/media-ctl/mediactl.h +14 -0
@@ -368,6 +368,20 @@ int media_setup_link(struct media_device *media,int media_reset_links (struct media_device *media);/** +* @brief Parse string to an entity on the media device. +* @param media - media device. +* @param p - input string +* @param endp - pointer to string where parsing ended +* +* Parse NULL terminated string describing an entity and return its +* struct media_entity instance. +* +* @return Pointer to struct media_entity on success, NULL on failure. +*/ +struct media_entity *media_parse_entity (struct media_device *media, +const char *p,char **endp); + +/** * @brief Parse string to a pad on the media device. * @param media - media device. * @param p - input string
Signature · 1 line
1.7.9.5
RFC v3 3/11 mediatext: Add library
In reply to Jacek Anaszewskilibmediatext is a helper library for converting configurations (Media controller links, V4L2 controls and V4L2 sub-device media bus formats and selections) from text-based form into IOCTLs.
libmediatext depends on libv4l2subdev and libmediactl.
--- libmediatext.pc.in | 10 ++ utils/media-ctl/Makefile.am | 10 +- utils/media-ctl/libmediatext.pc.in | 10 ++ utils/media-ctl/mediatext-test.c | 66 ++++++++ utils/media-ctl/mediatext.c | 303 ++++++++++++++++++++++++++++++++++++ utils/media-ctl/mediatext.h | 52 +++++++ 6 files changed, 449 insertions(+), 2 deletions(-) create mode 100644 libmediatext.pc.in create mode 100644 utils/media-ctl/libmediatext.pc.in create mode 100644 utils/media-ctl/mediatext-test.c create mode 100644 utils/media-ctl/mediatext.c create mode 100644 utils/media-ctl/mediatext.h
libmediatext.pc.in new file +10 -0
@@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libmediatext +Description: Media controller and V4L2 text-based configuration library +Version: @PACKAGE_VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -lmediatext
utils/media-ctl/Makefile.am +8 -2
@@ -1,4 +1,4 @@ -noinst_LTLIBRARIES = libmediactl.la libv4l2subdev.la +noinst_LTLIBRARIES = libmediactl.la libv4l2subdev.la libmediatext.la libmediactl_la_SOURCES = libmediactl.c mediactl-priv.h libmediactl_la_CFLAGS = -static $(LIBUDEV_CFLAGS)
@@ -9,9 +9,15 @@ libv4l2subdev_la_LIBADD = libmediactl.la libv4l2subdev_la_CFLAGS = -static libv4l2subdev_la_LDFLAGS = -static +libmediatext_la_SOURCES = mediatext.c +libmediatext_la_CFLAGS = -static $(LIBUDEV_CFLAGS) +libmediatext_la_LDFLAGS = -static $(LIBUDEV_LIBS) + mediactl_includedir=$(includedir)/mediactl noinst_HEADERS = mediactl.h v4l2subdev.h -bin_PROGRAMS = media-ctl +bin_PROGRAMS = media-ctl mediatext-test media_ctl_SOURCES = media-ctl.c options.c options.h tools.h media_ctl_LDADD = libmediactl.la libv4l2subdev.la +mediatext_test_SOURCES = mediatext-test.c +mediatext_test_LDADD = libmediatext.la libmediactl.la libv4l2subdev.la
utils/media-ctl/libmediatext.pc.in new file +10 -0
@@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libmediatext +Description: Media controller and V4L2 text-based configuration library +Version: @PACKAGE_VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -lmediatext
utils/media-ctl/mediatext-test.c new file +66 -0
66 lines not on this page · raw message
utils/media-ctl/mediatext.c new file +303 -0
303 lines not on this page · raw message
utils/media-ctl/mediatext.h new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC v3 4/11 mediactl: Add media device graph helpers
In reply to Jacek AnaszewskiAdd new graph helpers useful for video pipeline discovering.
--- utils/media-ctl/libmediactl.c | 184 +++++++++++++++++++++++++++++++++++++++++ utils/media-ctl/mediactl.h | 132 +++++++++++++++++++++++++++++ 2 files changed, 316 insertions(+)
utils/media-ctl/libmediactl.c +184 -0
@@ -35,6 +35,7 @@#include <unistd.h> #include <linux/media.h> +#include <linux/kdev_t.h> #include <linux/videodev2.h> #include "mediactl.h"
@@ -45,6 +46,7 @@* Graph access */ +struct media_pad *media_entity_remote_source (struct media_pad *pad) {unsigned int i;
@@ -87,6 +89,28 @@ struct media_entity *media_get_entity_by_name(struct media_device *media,return NULL ; } +struct media_entity *media_get_entity_by_devname (struct media_device *media, +const char *devname,size_t length) +{ +unsigned int i; + +/* A match is impossible if the entity devname is longer than the maximum +* size we can get from the kernel. +*/ + if (length >= FIELD_SIZEOF(struct media_entity, devname)) +return NULL ; + +for (i =0 ; i < media->entities_count; ++i) { +struct media_entity *entity = &media->entities[i]; + +if (strncmp (entity->devname, devname, length) ==0 && + entity->devname[length] =='\0' ) +return entity; + } + +return NULL ; +} +struct media_entity *media_get_entity_by_id (struct media_device *media,__u32 id) {
@@ -145,6 +169,11 @@ const char *media_entity_get_devname(struct media_entity *entity)return entity->devname[0 ] ? entity->devname :NULL ; } +const char *media_entity_get_name (struct media_entity *entity) +{ +return entity->info.name ? entity->info.name :NULL ; +} +struct media_entity *media_get_default_entity (struct media_device *media,unsigned int type) {
@@ -177,6 +206,152 @@ const struct media_entity_desc *media_entity_get_info(struct media_entity *entitreturn &entity->info; } +int media_get_link_by_sink_pad (struct media_device *media, +struct media_pad *pad, +struct media_link **link) +{ +struct media_link *cur_link =NULL ; +int i, j; + +if (pad ==NULL || link ==NULL ) +return -EINVAL ; + +for (i =0 ; i < media->entities_count; ++i) { +for (j =0 ; j < media->entities[i].num_links; ++j) { + cur_link = &media->entities[i].links[j]; +if ((cur_link->flags &MEDIA_LNK_FL_ENABLED ) && +/* check if cur_link's sink entity matches the pad parent entity */ + (cur_link->sink->entity->info.id == pad->entity->info.id) && +/* check if cur_link's sink pad id matches */ + (cur_link->sink->index == pad->index)) { + *link = cur_link; +return 0 ; + } + } + } + +return -EINVAL ; +} + +int media_get_link_by_source_pad (struct media_entity *entity, +struct media_pad *pad, +struct media_link **link) +{ +int i; + +if (entity ==NULL || pad ==NULL || link ==NULL ) +return -EINVAL ; + +for (i =0 ; i < entity->num_links; ++i) { +if ((entity->links[i].flags &MEDIA_LNK_FL_ENABLED ) && + (entity->links[i].source->index == pad->index)) { + *link = &entity->links[i]; +return 0 ; + } + } + +return -EINVAL ; +} + +int media_get_pads_by_entity (struct media_entity *entity,unsigned int type, +struct media_pad **pads,int *num_pads) +{ +struct media_pad *entity_pads; +int cnt_pads, i; + +if (entity ==NULL || pads ==NULL || num_pads ==NULL ) +return -EINVAL ; + + entity_pads =malloc (sizeof (*entity_pads)); + cnt_pads =0 ; + +for (i =0 ; i < entity->info.pads; ++i) { +if (entity->pads[i].flags & type) { + entity_pads =realloc (entity_pads, (i +1 ) * +sizeof (*entity_pads)); + entity_pads[cnt_pads++] = entity->pads[i]; + } + } + +if (cnt_pads ==0 ) +free (entity_pads); + + *pads = entity_pads; + *num_pads = cnt_pads; + +return 0 ; +} + +int media_get_busy_pads_by_entity (struct media_device *media, +struct media_entity *entity, +unsigned int type, +struct media_pad **busy_pads, +int *num_busy_pads) +{ +struct media_pad *bpads, *pads; +struct media_link *link; +int cnt_bpads =0 , num_pads, i, ret; + +if (entity ==NULL || busy_pads ==NULL || num_busy_pads ==NULL || + (type ==MEDIA_PAD_FL_SINK && media ==NULL )) +return -EINVAL ; + + ret =media_get_pads_by_entity (entity, type, &pads, &num_pads); +if (ret <0 ) +return -EINVAL ; + +if (num_pads ==0 ) + goto done; + + bpads =malloc (sizeof (*pads)); +if (bpads ==NULL ) + goto error_ret; + +for (i =0 ; i < num_pads; ++i) { +if (type ==MEDIA_PAD_FL_SINK ) + ret =media_get_link_by_sink_pad (media, &pads[i], &link); +else + ret =media_get_link_by_source_pad (entity, &pads[i], &link); +if (ret ==0 ) { + bpads =realloc (bpads, (i +1 ) * +sizeof (*bpads)); + bpads[cnt_bpads++] = pads[i]; + } + } +if (num_pads >0 ) +free (pads); + +if (cnt_bpads ==0 ) +free (bpads); + +done: + *busy_pads = bpads; + *num_busy_pads = cnt_bpads; + +return 0 ; + +error_ret: +return -EINVAL ; +} + +int media_get_pad_by_index (struct media_pad *pads,int num_pads, +int index,struct media_pad *out_pad) +{ +int i; + +if (pads ==NULL || out_pad ==NULL ) +return -EINVAL ; + +for (i =0 ; i < num_pads; ++i) { +if (pads[i].index == index) { + *out_pad = pads[i]; +return 0 ; + } + } + +return -EINVAL ; +} +/* ----------------------------------------------------------------------------- * Open/close */
@@ -1001,3 +1176,12 @@ struct media_entity *media_config_get_entity_by_cid(struct media_device *media,return NULL ; } + +/* ----------------------------------------------------------------------------- +* Media entity access +*/ + +int media_entity_get_fd (struct media_entity *entity) +{ +return entity->fd; +}
utils/media-ctl/mediactl.h +132 -0
154 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC v3 5/11 mediactl: Add media_device creation helpers
In reply to Jacek AnaszewskiAdd helper functions that allow for easy instantiation of media_device object basing on whether the media device contains video device with given node name.
--- utils/media-ctl/libmediactl.c | 75 +++++++++++++++++++++++++++++++++++++++++ utils/media-ctl/mediactl.h | 29 ++++++++++++++++ 2 files changed, 104 insertions(+)
utils/media-ctl/libmediactl.c +75 -0
@@ -855,6 +855,43 @@ struct media_device *media_device_new(const char *devnode)return media; } +struct media_device *media_device_new_by_entity_devname (char *entity_devname) +{ +struct media_device *media; +char media_devname[32 ]; +int i, ret; + +if (entity_devname ==NULL ) +return NULL ; + +/* query all available media devices */ +for (i =0 ;; ++i) { +sprintf (media_devname,"/dev/media%d" , i); + + media =media_device_new (media_devname); +if (media ==NULL ) +return NULL ; + + ret =media_device_enumerate (media); +if (ret <0 ) { +media_dbg (media,"Failed to enumerate %s (%d)\n" , media_devname, ret); + goto err_dev_enum; + } + +/* Check if the media device contains entity with entity_devname */ +if (media_get_entity_by_devname (media, entity_devname,strlen (entity_devname))) +return media; + +if (media) +media_device_unref (media); + } + +err_dev_enum: +if (media) +media_device_unref (media); +return NULL ; +} +struct media_device *media_device_new_emulated (struct media_device_info *info) {struct media_device *media;
@@ -897,6 +934,44 @@ void media_device_unref(struct media_device *media)free (media); } +int media_get_devname_by_fd (int fd,char *node_name) +{ +struct udev *udev; +struct media_entity tmp_entity; +struct stat stat; +int ret; + +if (node_name ==NULL ) +return -EINVAL ; + + ret =fstat (fd, &stat); +if (ret <0 ) +return -EINVAL ; + + tmp_entity.info.v4l.major =MAJOR (stat.st_rdev); + tmp_entity.info.v4l.minor =MINOR (stat.st_rdev); + + ret =media_udev_open (&udev); +if (ret <0 ) +printf ("Can't get udev context\n" ); + +/* Try to get the device name via udev */ + ret =media_get_devname_udev (udev, &tmp_entity); +if (!ret) + goto out; + + ret =media_get_devname_sysfs (&tmp_entity); +if (ret <0 ) + goto err_get_devname; + +out: +strcpy (node_name, tmp_entity.devname); +err_get_devname: +media_udev_close (udev); +return ret; +} + +int media_device_add_entity (struct media_device *media,const struct media_entity_desc *desc,const char *devnode)
utils/media-ctl/mediactl.h +29 -0
@@ -77,6 +77,23 @@ struct media_device *media_device_new(const char *devnode);struct media_device *media_device_new_emulated (struct media_device_info *info);/** +* @brief Create a new media device if it comprises entity with entity_devname +* @param entity_devname - device node name of the entity to be matched +* +* Query all media devices available in the system to find the one comprising +* the entity with device node name equal to entity_devname. If the media +* device is matched then its instance is created and initialized with +* enumerated entities and links. The returned device can be accessed. +* +* Media devices are reference-counted, see media_device_ref() and +* media_device_unref() for more information. +* +* @return A pointer to the new media device or NULL if video_devname cannot +* be matched or memory cannot be allocated. +*/ +struct media_device *media_device_new_by_entity_devname (char *video_devname); + +/** * @brief Take a reference to the device. * @param media - device instance. *
@@ -242,6 +259,18 @@ const char *media_entity_get_devname(struct media_entity *entity);const char *media_entity_get_name (struct media_entity *entity);/** +* @brief Get the device node name by its file descriptor +* @param fd - file descriptor of a device +* @param node_name - output device node name string +* +* This function returns the full path and name to the device node corresponding +* to the given file descriptor. +* +* @return 0 on success, or a negative error code on failure. +*/ +int media_get_devname_by_fd (int fd,char *node_name); + +/** * @brief Get the type of an entity. * @param entity - the entity. *
Signature · 1 line
1.7.9.5
RFC v3 6/11 mediactl: Add subdev_fmt property to the media_entity
In reply to Jacek AnaszewskiAdd subdev_fmt field to the structure media_entity. Added is also API for setting the media_entity format and comparing two subdev formats.
--- utils/media-ctl/libmediactl.c | 6 ++++++ utils/media-ctl/libv4l2subdev.c | 34 ++++++++++++++++++++++++++++++++++ utils/media-ctl/mediactl-priv.h | 3 +++ utils/media-ctl/mediactl.h | 12 ++++++++++++ utils/media-ctl/v4l2subdev.h | 12 ++++++++++++ 5 files changed, 67 insertions(+)
utils/media-ctl/libmediactl.c +6 -0
@@ -1260,3 +1260,9 @@ int media_entity_get_fd(struct media_entity *entity) {return entity->fd; } + +void media_entity_set_subdev_fmt (struct media_entity *entity, +struct v4l2_subdev_format *fmt) +{ + entity->subdev_fmt = *fmt; +}
utils/media-ctl/libv4l2subdev.c +34 -0
@@ -786,3 +786,37 @@ int v4l2_subdev_validate_v4l2_ctrl(struct media_device *media, entity->info.name);return 0 ; } + +int v4l2_subdev_format_compare (struct v4l2_mbus_framefmt *fmt1, +struct v4l2_mbus_framefmt *fmt2) +{ +if (fmt1 ==NULL || fmt2 ==NULL ) +return 0 ; + +if (fmt1->width != fmt2->width) { +printf ("width mismatch\n" ); +return 0 ; + } + +if (fmt1->height != fmt2->height) { +printf ("height mismatch\n" ); +return 0 ; + } + +if (fmt1->code != fmt2->code) { +printf ("mbus code mismatch\n" ); +return 0 ; + } + +if (fmt1->field != fmt2->field) { +printf ("field mismatch\n" ); +return 0 ; + } + +if (fmt1->colorspace != fmt2->colorspace) { +printf ("colorspace mismatch\n" ); +return 0 ; + } + +return 1 ; +}
utils/media-ctl/mediactl-priv.h +3 -0
@@ -23,6 +23,7 @@#define __MEDIA_PRIV_H__#include <linux/media.h> +#include <linux/v4l2-subdev.h> #include "mediactl.h"
@@ -34,6 +35,8 @@ struct media_entity {unsigned int max_links;unsigned int num_links; +struct v4l2_subdev_format subdev_fmt; +char devname[32 ];int fd; };
utils/media-ctl/mediactl.h +12 -0
@@ -42,6 +42,7 @@ struct media_pad {struct media_device ;struct media_entity ; +struct v4l2_subdev_format ;/** * @brief Create a new media device.
@@ -611,4 +612,15 @@ int media_entity_get_sink_pad_index(struct media_entity *entity);*/ int media_entity_get_fd (struct media_entity *entity); +/** +* @brief Set sub-device format +* @param entity - media entity +* @param fmt - pointer to the sub-device format structure +* +* This function sets the format of the sub-device related +* to this entity. +*/ +void media_entity_set_subdev_fmt (struct media_entity *entity, +struct v4l2_subdev_format *fmt); +#endif
utils/media-ctl/v4l2subdev.h +12 -0
@@ -270,4 +270,16 @@ int v4l2_subdev_validate_v4l2_ctrl(struct media_device *media,struct media_entity *entity, __u32 ctrl_id); +/** +* @brief Compare mbus formats +* @param fmt1 - 1st mbus format to compare +* @param fmt2 - 2nd mbus format to compare +* +* Check whether two mbus formats are compatible. +* +* @return 1 if formats are compatible, 0 otherwise +*/ +int v4l2_subdev_format_compare (struct v4l2_mbus_framefmt *fmt1, +struct v4l2_mbus_framefmt *fmt2); +#endif
Signature · 1 line
1.7.9.5
RFC v3 7/11 mediactl: Add VYUY8_2X8 media bus format
In reply to Jacek AnaszewskiThe VYUY8_2X8 media bus format is the only one supported by the S5C73M3 camera sensor, that is a part of the media device on the Exynos4412-trats2 board.
--- utils/media-ctl/libv4l2subdev.c | 1 + 1 file changed, 1 insertion(+)
utils/media-ctl/libv4l2subdev.c +1 -0
@@ -705,6 +705,7 @@ static struct { { "YUYV", V4L2_MBUS_FMT_YUYV8_1X16 }, { "YUYV1_5X8", V4L2_MBUS_FMT_YUYV8_1_5X8 }, { "YUYV2X8", V4L2_MBUS_FMT_YUYV8_2X8 }, + { "VYUY8_2X8", V4L2_MBUS_FMT_VYUY8_2X8 }, { "UYVY", V4L2_MBUS_FMT_UYVY8_1X16 }, { "UYVY1_5X8", V4L2_MBUS_FMT_UYVY8_1_5X8 }, { "UYVY2X8", V4L2_MBUS_FMT_UYVY8_2X8 },
Signature · 1 line
1.7.9.5
RFC v3 8/11 mediactl: Add support for media device pipelines
In reply to Jacek AnaszewskiAdd infrastructure for linking media entities, discovering pipelines of media entities and opening/closing all sub-devices in the pipeline at one go.
--- utils/media-ctl/libmediactl.c | 166 +++++++++++++++++++++++++++++++++++++++ utils/media-ctl/mediactl-priv.h | 6 ++ utils/media-ctl/mediactl.h | 79 +++++++++++++++++++ 3 files changed, 251 insertions(+)
utils/media-ctl/libmediactl.c +166 -0
@@ -1253,9 +1253,165 @@ struct media_entity *media_config_get_entity_by_cid(struct media_device *media, }/* ----------------------------------------------------------------------------- +* Pipeline operations +*/ + +int media_discover_pipeline_by_entity (struct media_device *media, +struct media_entity *entity) +{ +struct media_entity *pipe_head =NULL ; +struct media_pad *sink_pads, sink_pad, *src_pad; +struct media_link *link; +int num_sink_pads, ret; +struct media_pad *prev_link_src_pad =NULL ; + +if (entity ==NULL ) +return -EINVAL ; + +for (;;) { +if (pipe_head ==NULL ) { + pipe_head = entity; + }else { + entity->next = pipe_head; + pipe_head = entity; + } + + entity->pipe_src_pad = prev_link_src_pad; + + ret =media_get_busy_pads_by_entity (media, entity, +MEDIA_PAD_FL_SINK , + &sink_pads, + &num_sink_pads); +if (ret <0 ) +return ret; + +/* check if pipeline source entity has been reached */ +if (num_sink_pads >2 ) { +media_dbg (media,"Unexpected number of busy sink pads (%d)\n" , num_sink_pads); + goto err_check_sink_pads; + }else if (num_sink_pads ==2 ) { +/* Allow two active pads only in case of S5C73M3-OIF entity */ +if (strcmp (entity->info.name,"S5C73M3-OIF" )) { +media_dbg (media,"Ambiguous media device topology: two busy sink pads" ); + goto err_check_sink_pads; + } +/* +* Two active links are allowed betwen S5C73M3-OIF and S5C73M3 entities. +* In such a case a route through pad 0 has to be selected. +*/ + ret =media_get_pad_by_index (sink_pads, num_sink_pads, +0 , &sink_pad); +if (ret <0 ) + goto err_check_sink_pads; + }else if (num_sink_pads ==1 ) { + sink_pad = sink_pads[0 ]; + }else { +break ; + } +if (num_sink_pads >0 ) +free (sink_pads); + + ret =media_get_link_by_sink_pad (media, &sink_pad, &link); + + prev_link_src_pad = link->source; + entity->pipe_sink_pad = link->sink; + + src_pad =media_entity_remote_source (link->sink); +if (!src_pad) +return -EINVAL ; + + entity = src_pad->entity; + } + + media->pipeline = pipe_head; + +return 0 ; + +err_check_sink_pads: +free (sink_pads); +return -EINVAL ; +} + +int media_has_pipeline_entity (struct media_entity *pipeline,char *entity_name) +{ +if (pipeline ==NULL || entity_name ==NULL ) +return -EINVAL ; + +while (pipeline) { +if (!strcmp (pipeline->info.name, entity_name)) +return 1 ; + pipeline = pipeline->next; + } + +return 0 ; +} + +int media_open_pipeline_subdevs (struct media_device *media) +{ +struct media_entity *entity = media->pipeline; + +if (entity ==NULL ) +return 0 ; + +while (entity->next) { +media_dbg (media,"Opening sub-device: %s\n" , entity->devname); + entity->fd =open (entity->devname,O_RDWR ); + +if (entity->fd <0 ) { +media_dbg (media,"Could not open device %s" , entity->devname); + goto err_open_subdev; + } + + entity = entity->next; + } + +return 0 ; + +err_open_subdev: +media_close_pipeline_subdevs (media); + +return -EINVAL ; +} + +void media_close_pipeline_subdevs (struct media_device *media) +{ +struct media_entity *entity = media->pipeline; + +if (entity ==NULL ) +return ; + +while (entity->next) { +if (entity->fd >=0 ) { +media_dbg (media,"Closing sub-device: %s\n" , entity->devname); +close (entity->fd); + }else { +break ; + } + + entity->fd =-1 ; + entity = entity->next; + } +} + +/* ----------------------------------------------------------------------------- * Media entity access */ +struct media_entity *media_get_pipeline (struct media_device *media) +{ +return media->pipeline; +} + +int media_entity_get_src_pad_index (struct media_entity *entity) +{ +return entity->pipe_src_pad->index; +} + +int media_entity_get_sink_pad_index (struct media_entity *entity) +{ +return entity->pipe_sink_pad->index; +} +int media_entity_get_fd (struct media_entity *entity) {return entity->fd;
@@ -1266,3 +1422,13 @@ void media_entity_set_subdev_fmt(struct media_entity *entity, { entity->subdev_fmt = *fmt; } + +struct media_entity *media_entity_get_next (struct media_entity *entity) +{ +return entity->next; +} + +void media_entity_set_next (struct media_entity *entity,struct media_entity *next) +{ + entity->next = next; +}
utils/media-ctl/mediactl-priv.h +6 -0
@@ -35,10 +35,15 @@ struct media_entity {unsigned int max_links;unsigned int num_links; +struct media_pad *pipe_src_pad; +struct media_pad *pipe_sink_pad; +struct v4l2_subdev_format subdev_fmt;char devname[32 ];int fd; + +struct media_entity *next; };struct media_device {
@@ -49,6 +54,7 @@ struct media_device {struct media_device_info info;struct media_entity *entities;unsigned int entities_count; +struct media_entity *pipeline;struct media_v4l2_ctrl_to_subdev *ctrl_to_subdev;unsigned int ctrl_to_subdev_count;
utils/media-ctl/mediactl.h +79 -0
89 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC v3 9/11 mediactl: Add media device ioctl API
In reply to Jacek AnaszewskiIoctls executed on complex media devices need special handling. E.g. S_FMT requires negotiation for the whole pipeline of sub-devices. On the other hand some ioctls need to be targeted for specific sub-devices. The API being introduced address such requirements.
--- utils/media-ctl/Makefile.am | 2 +- utils/media-ctl/libv4l2media_ioctl.c | 342 ++++++++++++++++++++++++++++++++++ utils/media-ctl/libv4l2media_ioctl.h | 47 +++++ 3 files changed, 390 insertions(+), 1 deletion(-) create mode 100644 utils/media-ctl/libv4l2media_ioctl.c create mode 100644 utils/media-ctl/libv4l2media_ioctl.h
utils/media-ctl/Makefile.am +1 -1
@@ -1,6 +1,6 @@ noinst_LTLIBRARIES = libmediactl.la libv4l2subdev.la libmediatext.la -libmediactl_la_SOURCES = libmediactl.c mediactl-priv.h +libmediactl_la_SOURCES = libmediactl.c mediactl-priv.h libv4l2media_ioctl.c libv4l2media_ioctl.h libmediactl_la_CFLAGS = -static $(LIBUDEV_CFLAGS) libmediactl_la_LDFLAGS = -static $(LIBUDEV_LIBS)
utils/media-ctl/libv4l2media_ioctl.c new file +342 -0
342 lines not on this page · raw message
utils/media-ctl/libv4l2media_ioctl.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC v3 10/11 mediactl: Close only pipeline sub-devices
In reply to Jacek AnaszewskiThe function media_device_new_by_entity_devname queries media devices available in the system for containment if given media entity. If a verification is negative the media_device is released with media_device_unref. In the previous approach media_device_unref was closing all media entities it contained, which was undesirable behavior as there might exist other initialized plugins which had opened the same media_device and initialized a pipeline. With this patch only the sub-devices that belong to the pipeline of current media_device instance will be closed.
--- utils/media-ctl/libmediactl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
utils/media-ctl/libmediactl.c +2 -2
@@ -919,13 +919,13 @@ void media_device_unref(struct media_device *media)if (media->refcount >0 )return ; +media_close_pipeline_subdevs (media); +for (i =0 ; i < media->entities_count; ++i) {struct media_entity *entity = &media->entities[i];free (entity->pads);free (entity->links); -if (entity->fd !=-1 ) -close (entity->fd); }free (media->entities);
Signature · 1 line
1.7.9.5
RFC v3 11/11 Add a libv4l plugin for Exynos4 camera
In reply to Jacek AnaszewskiThe plugin provides support for the media device on Exynos4 SoC. It performs single plane <-> multi plane API conversion, video pipeline linking and takes care of automatic data format negotiation for the whole pipeline, after intercepting VIDIOC_S_FMT or VIDIOC_TRY_FMT ioctls.
--- configure.ac | 1 + lib/Makefile.am | 5 +- lib/libv4l-exynos4-camera/Makefile.am | 7 + lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c | 599 +++++++++++++++++++++ 4 files changed, 610 insertions(+), 2 deletions(-) create mode 100644 lib/libv4l-exynos4-camera/Makefile.am create mode 100644 lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c
configure.ac +1 -0
@@ -17,6 +17,7 @@ AC_CONFIG_FILES([Makefile lib/libdvbv5/Makefile lib/libv4l2rds/Makefile lib/libv4l-mplane/Makefile + lib/libv4l-exynos4-camera/Makefile utils/Makefile utils/libv4l2util/Makefile
lib/Makefile.am +3 -2
@@ -3,9 +3,10 @@ SUBDIRS = \ libv4l2 \ libv4l1 \ libv4l2rds \ - libv4l-mplane + libv4l-mplane \ + libv4l-exynos4-camera if LINUX_OS SUBDIRS += \ libdvbv5 -endif +endif
lib/libv4l-exynos4-camera/Makefile.am new file +7 -0
@@ -0,0 +1,7 @@ +if WITH_V4L_PLUGINS +libv4l2plugin_LTLIBRARIES = libv4l-exynos4-camera.la +endif + +libv4l_exynos4_camera_la_SOURCES = libv4l-exynos4-camera.c ../../utils/media-ctl/libmediactl.c ../../utils/media-ctl/libv4l2subdev.c ../../utils/media-ctl/libv4l2media_ioctl.c ../../utils/media-ctl/mediatext.c +libv4l_exynos4_camera_la_CFLAGS = -fvisibility=hidden -std=gnu99 +libv4l_exynos4_camera_la_LDFLAGS = -avoid-version -module -shared -export-dynamic -lpthread
lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c new file +599 -0
599 lines not on this page · raw message
Signature · 1 line
1.7.9.5