Skip to contentSkip to conversation

Add a plugin for Exynos4 camera

PATCH In review Jacek Anaszewski 2 participants 19 messages Feb 26, 2015 – Jun 8, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover Add a plugin for Exynos4 camera

This is a fifth 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 utils are built after the plugins, but libv4l-exynos4-camera plugin depends on the utils. In order to link the plugin against libmediactl the build system would have to be modified.

================
Changes from v4:
================

- removed some redundant functions for traversing media device graph and switched over to using existing ones
- avoided accessing struct v4l2_subdev from libmediactl
- applied various improvements

================
Changes from v3:
================

- added struct v4l2_subdev and put entity fd and information about supported controls to it
- improved functions for negotiating and setting pipeline format by using available libv4lsubdev API
- applied minor improvements and cleanups

================
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 linux-next_20150223 with patches for exynos4-is that fix failing open ioctl 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

Thanks,
Jacek Anaszewski

[1] https://patchwork.linuxtv.org/patch/26366/
[2] https://patchwork.linuxtv.org/patch/26367/
[3] https://patchwork.linuxtv.org/patch/26368/

Jacek Anaszewski (13):
mediactl: Introduce v4l2_subdev structure
mediactl: Add support for v4l2-ctrl-redir config
mediatext: Add library
mediactl: Add media device graph helpers
mediactl: Add media_device creation helpers
mediactl: libv4l2subdev: add VYUY8_2X8 mbus code
mediactl: Add support for media device pipelines
mediactl: libv4l2subdev: add support for comparing mbus formats
mediactl: libv4l2subdev: add support for setting pipeline format
mediactl: libv4l2subdev: add get_pipeline_entity_by_cid function
mediactl: Add media device ioctl API
mediactl: libv4l2subdev: Enable opening/closing pipelines 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 |  586 +++++++++++++++++++++
 utils/media-ctl/Makefile.am                       |   12 +-
 utils/media-ctl/libmediactl.c                     |  271 +++++++++-
 utils/media-ctl/libmediatext.pc.in                |   10 +
 utils/media-ctl/libv4l2media_ioctl.c              |  369 +++++++++++++
 utils/media-ctl/libv4l2media_ioctl.h              |   40 ++
 utils/media-ctl/libv4l2subdev.c                   |  301 ++++++++++-
 utils/media-ctl/mediactl-priv.h                   |   11 +-
 utils/media-ctl/mediactl.h                        |  151 ++++++
 utils/media-ctl/mediatext-test.c                  |   64 +++
 utils/media-ctl/mediatext.c                       |  311 +++++++++++
 utils/media-ctl/mediatext.h                       |   52 ++
 utils/media-ctl/v4l2subdev.h                      |  131 +++++
 16 files changed, 2292 insertions(+), 30 deletions(-)
 create mode 100644 lib/libv4l-exynos4-camera/Makefile.am
 create mode 100644 lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c
 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
#1 lore raw

PATCH v5 1/14 mediactl: Introduce v4l2_subdev structure

Add struct v4l2_subdev - a representation of the v4l2 sub-device, related to the media entity. Add field 'sd', the pointer to the newly introduced structure, to the struct media_entity and move 'fd' property from struct media entity to struct v4l2_subdev. Avoid accessing sub-device file descriptor from libmediactl and make the v4l2_subdev_open capable of creating the v4l2_subdev if the 'sd' pointer is uninitialized.

---
 utils/media-ctl/libmediactl.c   |    4 --
 utils/media-ctl/libv4l2subdev.c |   82 +++++++++++++++++++++++++++++++--------
 utils/media-ctl/mediactl-priv.h |    5 ++-
 utils/media-ctl/v4l2subdev.h    |   38 ++++++++++++++++++
 4 files changed, 107 insertions(+), 22 deletions(-)
utils/media-ctl/libmediactl.c +0 -4
index ec360bd..4bb955f 100644
@@ -511,7 +511,6 @@ static int media_enum_entities(struct media_device *media)
 
 		entity = &media->entities[media->entities_count];
 		memset(entity, 0, sizeof(*entity));
-		entity->fd = -1;
 		entity->info.id = id | MEDIA_ENT_ID_FLAG_NEXT;
 		entity->media = media;
 
@@ -704,8 +703,6 @@ void media_device_unref(struct media_device *media)
 
 		free(entity->pads);
 		free(entity->links);
-		if (entity->fd != -1)
-			close(entity->fd);
 	}
 
 	free(media->entities);
@@ -732,7 +729,6 @@ int media_device_add_entity(struct media_device *media,
 	entity = &media->entities[media->entities_count - 1];
 	memset(entity, 0, sizeof *entity);
 
-	entity->fd = -1;
 	entity->media = media;
 	strncpy(entity->devname, devnode, sizeof entity->devname);
 	entity->devname[sizeof entity->devname - 1] = '\0';
utils/media-ctl/libv4l2subdev.c +65 -17

170 lines not on this page · raw message

utils/media-ctl/mediactl-priv.h +4 -1
index a0d3a55..f531c52 100644
@@ -26,6 +26,8 @@
 
 #include "mediactl.h"
 
+struct v4l2_subdev;
+
 struct media_entity {
 	struct media_device *media;
 	struct media_entity_desc info;
@@ -34,8 +36,9 @@ struct media_entity {
 	unsigned int max_links;
 	unsigned int num_links;
 
+	struct v4l2_subdev *sd;
+
 	char devname[32];
-	int fd;
 };
 
 struct media_device {
utils/media-ctl/v4l2subdev.h +38 -0
index 1cb53ff..b386294 100644
@@ -26,6 +26,44 @@
 
 struct media_entity;
 
+struct v4l2_subdev {
+	int fd;
+};
+
+/**
+ * @brief Create a v4l2-subdev
+ * @param entity - sub-device media entity.
+ *
+ * Create the representation of the entity sub-device.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_create(struct media_entity *entity);
+
+/**
+ * @brief Create a representation of the already opened v4l2-subdev
+ * @param entity - sub-device media entity.
+ * @param fd - sub-device file descriptor.
+ *
+ * Create the representation of the sub-device that had been opened
+ * before the parent media device was created, and associate it
+ * with the media entity.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_create_with_fd(struct media_entity *entity, int fd);
+
+/**
+ * @brief Release a v4l2-subdev
+ * @param entity - sub-device media entity.
+ * @param close_fd - indicates whether subdev fd should be closed.
+ *
+ * Release the representation of the entity sub-device.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+void v4l2_subdev_release(struct media_entity *entity, bool close_fd);
+
 /**
  * @brief Open a sub-device.
  * @param entity - sub-device media entity.
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v5 2/14 mediactl: Add support for v4l2-ctrl-redir config

In reply to Jacek Anaszewski

Make struct v4l2_subdev capable of aggregating v4l2-ctrl-redir media device configuration entries. Added are also functions for validating the config and checking whether a v4l2 sub-device expects to receive ioctls related to the v4l2-control with given id.

---
 utils/media-ctl/libv4l2subdev.c |   49 ++++++++++++++++++++++++++++++++++++++-
 utils/media-ctl/v4l2subdev.h    |   33 ++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)
utils/media-ctl/libv4l2subdev.c +48 -1
index 68404d4..5b9d908 100644
@@ -26,7 +26,6 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -50,7 +49,15 @@ int v4l2_subdev_create(struct media_entity *entity)
 
 	entity->sd->fd = -1;
 
+	entity->sd->v4l2_control_redir = malloc(sizeof(__u32));
+	if (entity->sd->v4l2_control_redir == NULL)
+		goto err_v4l2_control_redir_alloc;
+
 	return 0;
+
+err_v4l2_control_redir_alloc:
+	free(entity->sd);
+	return -ENOMEM;
 }
 
 int v4l2_subdev_create_with_fd(struct media_entity *entity, int fd)
@@ -803,3 +810,43 @@ 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_queryctrl queryctrl = {};
+	int ret;
+
+	ret = v4l2_subdev_open(entity);
+	if (ret < 0)
+		return ret;
+
+	queryctrl.id = ctrl_id;
+
+	ret = ioctl(entity->sd->fd, VIDIOC_QUERYCTRL, &queryctrl);
+	if (ret < 0)
+		return ret;
+
+	media_dbg(media, "Validated control \"%s\" (0x%8.8x) on entity %s\n",
+		  queryctrl.name, queryctrl.id, entity->info.name);
+
+	return 0;
+}
+
+bool v4l2_subdev_has_v4l2_control_redir(struct media_device *media,
+				  struct media_entity *entity,
+				  int ctrl_id)
+{
+	struct v4l2_subdev *sd = entity->sd;
+	int i;
+
+	if (!sd)
+		return false;
+
+	for (i = 0; i < sd->v4l2_control_redir_num; ++i)
+		if (sd->v4l2_control_redir[i] == ctrl_id)
+			return true;
+
+	return false;
+}
utils/media-ctl/v4l2subdev.h +33 -0
index b386294..07f9697 100644
@@ -23,11 +23,16 @@
 #define __SUBDEV_H__
 
 #include <linux/v4l2-subdev.h>
+#include <stdbool.h>
 
 struct media_entity;
+struct media_device;
 
 struct v4l2_subdev {
 	int fd;
+
+	__u32 *v4l2_control_redir;
+	unsigned int v4l2_control_redir_num;
 };
 
 /**
@@ -293,4 +298,32 @@ 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 - id of the v4l2 control to validate.
+ *
+ * Verify if the entity supports v4l2-control with given 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);
+
+/**
+ * @brief Check if there was a v4l2_control redirection defined for the entity
+ * @param media - media device.
+ * @param entity - subdev-device media entity.
+ * @param ctrl_id - v4l2 control identifier.
+ *
+ * Check if there was a v4l2-ctrl-redir entry defined for the entity.
+ *
+ * @return true if the entry exists, false otherwise
+ */
+bool v4l2_subdev_has_v4l2_control_redir(struct media_device *media,
+	struct media_entity *entity, int ctrl_id);
+
 #endif
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v5 3/14 mediactl: Separate entity and pad parsing

In reply to Jacek Anaszewski

From: 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
index 4bb955f..bbaf387 100644
@@ -766,10 +766,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;
 
@@ -806,7 +806,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
index 77ac182..3faee71 100644
@@ -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
#4 lore raw

PATCH v5 4/14 mediatext: Add library

In reply to Jacek Anaszewski

libmediatext 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.

---
 utils/media-ctl/Makefile.am        |   10 +-
 utils/media-ctl/libmediatext.pc.in |   10 ++
 utils/media-ctl/mediatext-test.c   |   64 ++++++++
 utils/media-ctl/mediatext.c        |  311 ++++++++++++++++++++++++++++++++++++
 utils/media-ctl/mediatext.h        |   52 ++++++
 5 files changed, 445 insertions(+), 2 deletions(-)
 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
utils/media-ctl/Makefile.am +8 -2
index a3931fb..3e883e0 100644
@@ -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
new file mode 100644
index 0000000..6aa6353
@@ -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 +64 -0

64 lines not on this page · raw message

utils/media-ctl/mediatext.c new file +311 -0

311 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
#5 lore raw

PATCH v5 5/14 mediactl: Add media device graph helpers

In reply to Jacek Anaszewski

Add new graph helpers useful for video pipeline discovering.

---
 utils/media-ctl/libmediactl.c |   48 +++++++++++++++++++++++++++++++++++++++++
 utils/media-ctl/mediactl.h    |   36 +++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
utils/media-ctl/libmediactl.c +48 -0
index bbaf387..a294ada 100644
@@ -35,6 +35,7 @@
 #include <unistd.h>
 
 #include <linux/media.h>
+#include <linux/kdev_t.h>
 #include <linux/videodev2.h>
 
 #include "mediactl.h"
@@ -87,6 +88,29 @@ 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;
+}
+
 struct media_entity *media_get_default_entity(struct media_device *media,
 					      unsigned int type)
 {
@@ -177,6 +206,25 @@ const struct media_entity_desc *media_entity_get_info(struct media_entity *entit
 	return &entity->info;
 }
 
+int media_get_backlinks_by_entity(struct media_entity *entity,
+				struct media_link **backlinks,
+				int *num_backlinks)
+{
+	int num_bklinks = 0, i;
+
+	if (entity == NULL || backlinks == NULL || num_backlinks == NULL)
+		return -EINVAL;
+
+	for (i = 0; i < entity->num_links; ++i)
+		if ((entity->links[i].flags & MEDIA_LNK_FL_ENABLED) &&
+		    (entity->links[i].sink->entity == entity))
+			backlinks[num_bklinks++] = &entity->links[i];
+
+	*num_backlinks = num_bklinks;
+
+	return 0;
+}
+
 /* -----------------------------------------------------------------------------
  * Open/close
  */
utils/media-ctl/mediactl.h +36 -0
index 3faee71..9db40a8 100644
@@ -231,6 +231,15 @@ const struct media_link *media_entity_get_link(struct media_entity *entity,
 const char *media_entity_get_devname(struct media_entity *entity);
 
 /**
+ * @brief Get the name for an entity
+ * @param entity - media entity.
+ *
+ * This function returns the name of the entity.
+ *
+ * @return A pointer to the string with entity name
+ */
+const char *media_entity_get_name(struct media_entity *entity);
+
  * @brief Get the type of an entity.
  * @param entity - the entity.
  *
@@ -255,6 +264,19 @@ struct media_entity *media_get_entity_by_name(struct media_device *media,
 	const char *name, size_t length);
 
 /**
+ * @brief Find an entity by the corresponding device node name.
+ * @param media - media device.
+ * @param devname - device node name.
+ * @param length - size of @a devname.
+ *
+ * Search for an entity with a device node name equal to @a devname.
+ *
+ * @return A pointer to the entity if found, or NULL otherwise.
+ */
+struct media_entity *media_get_entity_by_devname(struct media_device *media,
+	const char *devname, size_t length);
+
+/**
  * @brief Find an entity by its ID.
  * @param media - media device.
  * @param id - entity ID.
@@ -434,4 +456,18 @@ int media_parse_setup_link(struct media_device *media,
  */
 int media_parse_setup_links(struct media_device *media, const char *p);
 
+/**
+ * @brief Get entity's enabled backlinks
+ * @param entity - media entity.
+ * @param backlinks - array of pointers to matching backlinks.
+ * @param num_backlinks - number of matching backlinks.
+ *
+ * Get links that are connected to the entity sink pads.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+int media_get_backlinks_by_entity(struct media_entity *entity,
+				struct media_link **backlinks,
+				int *num_backlinks);
+
 #endif
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v5 6/14 mediactl: Add media_device creation helpers

In reply to Jacek Anaszewski

Add 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    |   30 +++++++++++++++++
 2 files changed, 105 insertions(+)
utils/media-ctl/libmediactl.c +75 -0
index a294ada..6d3e691 100644
@@ -719,6 +719,44 @@ 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];
+	struct media_entity *entity;
+	int i, ret;
+
+	/* 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 */
+		entity = media_get_entity_by_devname(media, entity_devname,
+							strlen(entity_devname));
+		if (entity)
+			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;
@@ -758,6 +796,43 @@ 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 +30 -0
index 9db40a8..1d62191 100644
@@ -76,6 +76,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 given 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 given 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 *entity_devname);
+
+/**
  * @brief Take a reference to the device.
  * @param media - device instance.
  *
@@ -240,6 +257,19 @@ 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
#7 lore raw

PATCH v5 7/14 mediactl: libv4l2subdev: add VYUY8_2X8 mbus code

In reply to Jacek Anaszewski

The 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
index 5b9d908..dfd3bd5 100644
@@ -760,6 +760,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
#8 lore raw

PATCH v5 8/14 mediactl: Add support for media device pipelines

In reply to Jacek Anaszewski

Add infrastructure for linking media entities and discovering media device pipelines.

---
 utils/media-ctl/libmediactl.c   |  116 +++++++++++++++++++++++++++++++++++++++
 utils/media-ctl/mediactl-priv.h |    6 ++
 utils/media-ctl/mediactl.h      |   71 ++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
utils/media-ctl/libmediactl.c +116 -0
index 6d3e691..4f2122f 100644
@@ -1094,3 +1094,119 @@ int media_parse_setup_links(struct media_device *media, const char *p)
 
 	return *end ? -EINVAL : 0;
 }
+
+/* -----------------------------------------------------------------------------
+ * 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 *src_pad;
+	struct media_link *link = NULL, *backlinks[10];
+	int i, num_backlinks, ret;
+
+	if (entity == NULL)
+		return -EINVAL;
+
+	for (;;) {
+		/* Make recently discovered entity the pipeline head */
+		if (pipe_head == NULL) {
+			pipe_head = entity;
+		} else {
+			entity->next = pipe_head;
+			pipe_head = entity;
+		}
+
+		/* Cache a source pad used for linking the entity */
+		if (link)
+			entity->pipe_src_pad = link->source;
+
+		ret = media_get_backlinks_by_entity(entity,
+						    backlinks,
+						    &num_backlinks);
+		if (ret < 0)
+			return ret;
+
+		/* check if pipeline source entity has been reached */
+		if (num_backlinks > 2) {
+			media_dbg(media, "Unexpected number of busy sink pads (%d)\n", num_backlinks);
+			return -EINVAL;
+		} else if (num_backlinks == 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");
+				return -EINVAL;
+			}
+			/*
+			 * Two active links are allowed betwen S5C73M3-OIF and
+			 * S5C73M3 entities. In such a case a route through pad
+			 * with id == 0 has to be selected.
+			 */
+			for (i = 0; i < num_backlinks; i++)
+				if (backlinks[i]->sink->index == 0)
+					link = backlinks[i];
+		} else if (num_backlinks == 1)
+			link = backlinks[0];
+		else
+			break;
+
+		/* Cache a sink pad used for linking the entity */
+		entity->pipe_sink_pad = link->sink;
+
+		media_dbg(media, "Discovered sink pad %d for the %s entity\n",
+			  entity->pipe_sink_pad->index, media_entity_get_name(entity));
+
+		src_pad = media_entity_remote_source(link->sink);
+		if (!src_pad)
+			return -EINVAL;
+
+		entity = src_pad->entity;
+	}
+
+	media->pipeline = pipe_head;
+
+	return 0;
+}
+
+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;
+}
+
+/* -----------------------------------------------------------------------------
+ * 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;
+}
+
+struct media_entity *media_entity_get_next(struct media_entity *entity)
+{
+	return entity->next;
+}
utils/media-ctl/mediactl-priv.h +6 -0
index f531c52..3378880 100644
@@ -36,9 +36,14 @@ 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 *sd;
 
 	char devname[32];
+
+	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;
 
 	void (*debug_handler)(void *, ...);
 	void *debug_priv;
utils/media-ctl/mediactl.h +71 -0

75 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v5 9/14 mediactl: libv4l2subdev: add support for comparing mbus formats

In reply to Jacek Anaszewski

This patch adds a function for checking whether two mbus formats are compatible.

---
 utils/media-ctl/libv4l2subdev.c |   34 ++++++++++++++++++++++++++++++++++
 utils/media-ctl/v4l2subdev.h    |   12 ++++++++++++
 2 files changed, 46 insertions(+)
utils/media-ctl/libv4l2subdev.c +34 -0
index dfd3bd5..b9a924c 100644
@@ -835,6 +835,40 @@ int v4l2_subdev_validate_v4l2_ctrl(struct media_device *media,
 	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;
+}
+
 bool v4l2_subdev_has_v4l2_control_redir(struct media_device *media,
 				  struct media_entity *entity,
 				  int ctrl_id)
utils/media-ctl/v4l2subdev.h +12 -0
index 07f9697..2f74975 100644
@@ -314,6 +314,18 @@ int v4l2_subdev_validate_v4l2_ctrl(struct media_device *media,
 				   __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);
+
+/**
  * @brief Check if there was a v4l2_control redirection defined for the entity
  * @param media - media device.
  * @param entity - subdev-device media entity.
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v5 10/14 mediactl: libv4l2subdev: add support for setting pipeline format

In reply to Jacek Anaszewski

This patch adds a function for setting the media device pipeline format.

---
 utils/media-ctl/libv4l2subdev.c |   61 +++++++++++++++++++++++++++++++++++++++
 utils/media-ctl/v4l2subdev.h    |   15 ++++++++++
 2 files changed, 76 insertions(+)
utils/media-ctl/libv4l2subdev.c +61 -0
index b9a924c..cc3df1e 100644
@@ -164,6 +164,67 @@ int v4l2_subdev_set_format(struct media_entity *entity,
 	return 0;
 }
 
+int v4l2_subdev_apply_pipeline_fmt(struct media_device *media,
+				   struct v4l2_format *fmt)
+{
+	struct v4l2_mbus_framefmt mbus_fmt = { 0 };
+	struct media_entity *entity = media->pipeline;
+	struct media_pad *pad;
+	int ret;
+
+	while (entity) {
+		/*
+		 * Source entity is linked only through a source pad
+		 * and this pad should be used for setting the format.
+		 * For other entities set the format on a sink pad.
+		 */
+		pad = entity->pipe_sink_pad ? entity->pipe_sink_pad :
+					      entity->pipe_src_pad;
+		if (pad == NULL)
+			return -EINVAL;
+
+		ret = v4l2_subdev_get_format(entity, &mbus_fmt, pad->index,
+					     V4L2_SUBDEV_FORMAT_TRY);
+
+		if (ret < 0)
+			return ret;
+
+		media_dbg(media, "VIDIOC_SUBDEV_G_FMT %s:%d: mbus_code: %s, width: %d, height: %d\n",
+			  media_entity_get_name(entity), pad->index,
+			  v4l2_subdev_pixelcode_to_string(mbus_fmt.code),
+			  mbus_fmt.width, mbus_fmt.height);
+
+		ret = v4l2_subdev_set_format(entity, &mbus_fmt, pad->index,
+					     V4L2_SUBDEV_FORMAT_ACTIVE);
+		if (ret < 0)
+			return ret;
+
+		media_dbg(media, "VIDIOC_SUBDEV_S_FMT %s:%d: mbus_code: %s, width: %d, height: %d\n",
+			  media_entity_get_name(entity), pad->index,
+			  v4l2_subdev_pixelcode_to_string(mbus_fmt.code),
+			  mbus_fmt.width, mbus_fmt.height);
+
+		entity = entity->next;
+
+		/* Last entity in the pipeline is not a sub-device */
+		if (entity->next == NULL)
+			break;
+	}
+
+	/*
+	 * Sink entity represents a video device node and is not
+	 * a sub-device. Nonetheless because it has associated
+	 * file descriptor and can expose v4l2-controls the
+	 * v4l2-subdev structure is used for caching the
+	 * related data.
+	 */
+	ret = ioctl(entity->sd->fd, VIDIOC_S_FMT, fmt);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 int v4l2_subdev_get_selection(struct media_entity *entity,
 	struct v4l2_rect *rect, unsigned int pad, unsigned int target,
 	enum v4l2_subdev_format_whence which)
utils/media-ctl/v4l2subdev.h +15 -0
index 2f74975..2b48fb5 100644
@@ -131,6 +131,21 @@ int v4l2_subdev_set_format(struct media_entity *entity,
 	enum v4l2_subdev_format_whence which);
 
 /**
+ * @brief Set media device pipeline format
+ * @param media - media device.
+ * @param fmt - negotiated format.
+ *
+ * Set the active format on all the media device pipeline entities.
+ * The format has to be at first negotiated with VIDIOC_SUBDEV_S_FMT
+ * by struct v4l2_subdev_format's 'whence' property set to
+ * V4L2_SUBDEV_FORMAT_TRY.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_apply_pipeline_fmt(struct media_device *media,
+				   struct v4l2_format *fmt);
+
+/**
  * @brief Retrieve a selection rectangle on a pad.
  * @param entity - subdev-device media entity.
  * @param r - rectangle to be filled.
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH v5 11/14 mediactl: libv4l2subdev: add get_pipeline_entity_by_cid function

In reply to Jacek Anaszewski

Add a function for obtaining the v4l2 sub-device for which the v4l2 control related ioctl is predestined.

---
 utils/media-ctl/libv4l2subdev.c |   14 ++++++++++++++
 utils/media-ctl/v4l2subdev.h    |   15 +++++++++++++++
 2 files changed, 29 insertions(+)
utils/media-ctl/libv4l2subdev.c +14 -0
index cc3df1e..379fe64 100644
@@ -946,3 +946,17 @@ bool v4l2_subdev_has_v4l2_control_redir(struct media_device *media,
 
 	return false;
 }
+
+struct media_entity *v4l2_subdev_get_pipeline_entity_by_cid(struct media_device *media,
+						int cid)
+{
+	struct media_entity *entity = media->pipeline;
+
+	while (entity) {
+		if (v4l2_subdev_has_v4l2_control_redir(media, entity, cid))
+			return entity;
+		entity = entity->next;
+	}
+
+	return NULL;
+}
utils/media-ctl/v4l2subdev.h +15 -0
index 2b48fb5..0f1deca 100644
@@ -353,4 +353,19 @@ int v4l2_subdev_format_compare(struct v4l2_mbus_framefmt *fmt1,
 bool v4l2_subdev_has_v4l2_control_redir(struct media_device *media,
 	struct media_entity *entity, int ctrl_id);
 
+/**
+ * @brief Get the first pipeline entity supporting the control
+ * @param media - media device.
+ * @param cid - v4l2 control identifier.
+ *
+ * Get the first entity in the media device pipeline,
+ * for which v4l2_control with cid is to be redirected
+ *
+ * @return associated entity if defined, or NULL if the
+ *	   control redirection wasn't defined for any entity
+ *	   in the pipeline
+ */
+struct media_entity *v4l2_subdev_get_pipeline_entity_by_cid(
+	struct media_device *media, int cid);
+
 #endif
Signature · 1 line
1.7.9.5
#12 lore raw

PATCH v5 12/14 mediactl: Add media device ioctl API

In reply to Jacek Anaszewski

Ioctls executed on complex media devices need special handling. For instance some ioctls need to be targeted for specific sub-devices, depending on the media device configuration. The APIs being introduced address such requirements.

---
 utils/media-ctl/Makefile.am          |    2 +-
 utils/media-ctl/libv4l2media_ioctl.c |  369 ++++++++++++++++++++++++++++++++++
 utils/media-ctl/libv4l2media_ioctl.h |   40 ++++
 3 files changed, 410 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
index 3e883e0..7f18624 100644
@@ -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 +369 -0

369 lines not on this page · raw message

utils/media-ctl/libv4l2media_ioctl.h new file +40 -0
new file mode 100644
index 0000000..2841c09
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *              http://www.samsung.com
+ *
+ * Author: Jacek Anaszewski <[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.
+ */
+
+#ifndef __LIBV4L2MEDIA_IOCTL_H
+#define __LIBV4L2MEDIA_IOCTL_H
+
+#include <linux/videodev2.h>
+
+struct media_device;
+
+int media_ioctl_ctrl(struct media_device *media, int request,
+			struct v4l2_control *arg);
+
+int media_ioctl_ext_ctrl(struct media_device *media, int request,
+			struct v4l2_ext_controls *arg);
+
+int media_ioctl_queryctrl(struct media_device *media,
+			struct v4l2_queryctrl *arg);
+
+int media_ioctl_query_ext_ctrl(struct media_device *media,
+			struct v4l2_query_ext_ctrl *arg);
+
+int media_ioctl_querymenu(struct media_device *media,
+			struct v4l2_querymenu *arg);
+
+#endif /* __LIBV4L2MEDIA_IOCTL_H */
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH v5 13/14 mediactl: libv4l2subdev: Enable opening/closing pipelines

In reply to Jacek Anaszewski

Add functions for opening and closing media entity pipelines at one go.

---
 utils/media-ctl/libv4l2subdev.c |   60 +++++++++++++++++++++++++++++++++++++++
 utils/media-ctl/v4l2subdev.h    |   18 ++++++++++++
 2 files changed, 78 insertions(+)
utils/media-ctl/libv4l2subdev.c +60 -0
index 379fe64..4475ef7 100644
@@ -117,6 +117,66 @@ void v4l2_subdev_close(struct media_entity *entity)
 	entity->sd->fd = -1;
 }
 
+int v4l2_subdev_open_pipeline(struct media_device *media)
+{
+	struct media_entity *entity = media->pipeline;
+	int ret;
+
+	if (entity == NULL)
+		return 0;
+
+	/*
+	 * Stop walking the pipeline on the last last but one entity, because
+	 * the sink entity sub-device was opened by libv4l2 core and its
+	 * file descriptor needs to be preserved.
+	 */
+	while (entity->next) {
+		media_dbg(media, "Opening sub-device: %s\n", entity->devname);
+		ret = v4l2_subdev_open(entity);
+		if (ret < 0)
+			return ret;
+
+		if (entity->sd->fd < 0)
+			goto err_open_subdev;
+
+		entity = entity->next;
+	}
+
+	return 0;
+
+err_open_subdev:
+	v4l2_subdev_release_pipeline(media);
+
+	return -EINVAL;
+}
+
+void v4l2_subdev_release_pipeline(struct media_device *media)
+{
+	struct media_entity *entity = media->pipeline;
+
+	if (entity == NULL)
+		return;
+	/*
+	 * Stop walking the pipeline on the last last but one entity, because
+	 * the sink entity sub-device should be released by the client that
+	 * instantiated it.
+	 */
+	while (entity->next) {
+		if (!entity->sd) {
+			entity = entity->next;
+			continue;
+		}
+
+		if (entity->sd->fd >= 0) {
+			media_dbg(media, "Releasing sub-device: %s\n", entity->devname);
+			v4l2_subdev_release(entity, true);
+		}
+
+		entity = entity->next;
+	}
+}
+
+
 int v4l2_subdev_get_format(struct media_entity *entity,
 	struct v4l2_mbus_framefmt *format, unsigned int pad,
 	enum v4l2_subdev_format_whence which)
utils/media-ctl/v4l2subdev.h +18 -0
index 0f1deca..2fdcb76 100644
@@ -90,6 +90,24 @@ int v4l2_subdev_open(struct media_entity *entity);
 void v4l2_subdev_close(struct media_entity *entity);
 
 /**
+ * @brief Open media device pipeline
+ * @param media - media device.
+ *
+ * Open all sub-devices in the media device pipeline.
+ *
+ * @return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_open_pipeline(struct media_device *media);
+
+/**
+ * @brief Release media device pipeline sub-devices
+ * @param media - media device.
+ *
+ * Release all sub-devices in the media device pipeline.
+ */
+void v4l2_subdev_release_pipeline(struct media_device *media);
+
+/**
  * @brief Retrieve the format on a pad.
  * @param entity - subdev-device media entity.
  * @param format - format to be filled.
Signature · 1 line
1.7.9.5
#14 lore raw

PATCH v5 14/14 Add a libv4l plugin for Exynos4 camera

In reply to Jacek Anaszewski

The 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 |  586 +++++++++++++++++++++
 4 files changed, 599 insertions(+)
 create mode 100644 lib/libv4l-exynos4-camera/Makefile.am
 create mode 100644 lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c
configure.ac +1 -0
index 85f71e0..fa3679f 100644
@@ -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 +5 -0
index ee0c3c5..56b3a9f 100644
@@ -5,6 +5,11 @@ SUBDIRS = \
 	libv4l2rds \
 	libv4l-mplane
 
+if WITH_V4LUTILS
+SUBDIRS += \
+	libv4l-exynos4-camera
+endif
+
 if LINUX_OS
 SUBDIRS += \
 	libdvbv5
lib/libv4l-exynos4-camera/Makefile.am new file +7 -0
new file mode 100644
index 0000000..23c60c6
@@ -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 +586 -0

586 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#15 lore raw
In reply to Jacek Anaszewski

Hi Jacek,

What is the status of this? It would be really useful to have a working plugin as an example in v4l-utils.

Regards,

Hans

Quoted 122 lines · Jacek Anaszewski

This is a fifth 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 utils are built after the plugins, but libv4l-exynos4-camera plugin depends on the utils. In order to link the plugin against libmediactl the build system would have to be modified.

================
Changes from v4:
================

- removed some redundant functions for traversing media device graph and switched over to using existing ones
- avoided accessing struct v4l2_subdev from libmediactl
- applied various improvements

================
Changes from v3:
================

- added struct v4l2_subdev and put entity fd and information about supported controls to it
- improved functions for negotiating and setting pipeline format by using available libv4lsubdev API
- applied minor improvements and cleanups

================
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 linux-next_20150223 with patches for exynos4-is that fix failing open ioctl 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

Thanks,
Jacek Anaszewski

[1] https://patchwork.linuxtv.org/patch/26366/
[2] https://patchwork.linuxtv.org/patch/26367/
[3] https://patchwork.linuxtv.org/patch/26368/

Jacek Anaszewski (13):
mediactl: Introduce v4l2_subdev structure
mediactl: Add support for v4l2-ctrl-redir config
mediatext: Add library
mediactl: Add media device graph helpers
mediactl: Add media_device creation helpers
mediactl: libv4l2subdev: add VYUY8_2X8 mbus code
mediactl: Add support for media device pipelines
mediactl: libv4l2subdev: add support for comparing mbus formats
mediactl: libv4l2subdev: add support for setting pipeline format
mediactl: libv4l2subdev: add get_pipeline_entity_by_cid function
mediactl: Add media device ioctl API
mediactl: libv4l2subdev: Enable opening/closing pipelines 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 |  586 +++++++++++++++++++++
 utils/media-ctl/Makefile.am                       |   12 +-
 utils/media-ctl/libmediactl.c                     |  271 +++++++++-
 utils/media-ctl/libmediatext.pc.in                |   10 +
 utils/media-ctl/libv4l2media_ioctl.c              |  369 +++++++++++++
 utils/media-ctl/libv4l2media_ioctl.h              |   40 ++
 utils/media-ctl/libv4l2subdev.c                   |  301 ++++++++++-
 utils/media-ctl/mediactl-priv.h                   |   11 +-
 utils/media-ctl/mediactl.h                        |  151 ++++++
 utils/media-ctl/mediatext-test.c                  |   64 +++
 utils/media-ctl/mediatext.c                       |  311 +++++++++++
 utils/media-ctl/mediatext.h                       |   52 ++
 utils/media-ctl/v4l2subdev.h                      |  131 +++++
 16 files changed, 2292 insertions(+), 30 deletions(-)
 create mode 100644 lib/libv4l-exynos4-camera/Makefile.am
 create mode 100644 lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c
 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
#16 lore raw

Hi Hans,

It got stuck on this version. I have some slight improvements locally but haven't sent them as there hasn't been any comment to this so far. AFAIR Sakari had some doubts about handling multiple pipelines within one media controller. In this approach only one pipeline is allowed. There has to be a new IOCTL added for locking pipelines, to handle this IIRC.

Besides there are some v4l-utils build system dependency issues to solve, I mentioned below in the cover letter.

Quoted 134 lines · Hans Verkuil

Hi Jacek,

What is the status of this? It would be really useful to have a working plugin as an example in v4l-utils.

Regards,

Hans

Quoted 122 lines · Jacek Anaszewski

This is a fifth 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 utils are built after the plugins, but libv4l-exynos4-camera plugin depends on the utils. In order to link the plugin against libmediactl the build system would have to be modified.

================
Changes from v4:
================

- removed some redundant functions for traversing media device graph and switched over to using existing ones
- avoided accessing struct v4l2_subdev from libmediactl
- applied various improvements

================
Changes from v3:
================

- added struct v4l2_subdev and put entity fd and information about supported controls to it
- improved functions for negotiating and setting pipeline format by using available libv4lsubdev API
- applied minor improvements and cleanups

================
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 linux-next_20150223 with patches for exynos4-is that fix failing open ioctl 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

Thanks,
Jacek Anaszewski

[1] https://patchwork.linuxtv.org/patch/26366/
[2] https://patchwork.linuxtv.org/patch/26367/
[3] https://patchwork.linuxtv.org/patch/26368/

Jacek Anaszewski (13):
mediactl: Introduce v4l2_subdev structure
mediactl: Add support for v4l2-ctrl-redir config
mediatext: Add library
mediactl: Add media device graph helpers
mediactl: Add media_device creation helpers
mediactl: libv4l2subdev: add VYUY8_2X8 mbus code
mediactl: Add support for media device pipelines
mediactl: libv4l2subdev: add support for comparing mbus formats
mediactl: libv4l2subdev: add support for setting pipeline format
mediactl: libv4l2subdev: add get_pipeline_entity_by_cid function
mediactl: Add media device ioctl API
mediactl: libv4l2subdev: Enable opening/closing pipelines 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 |  586 +++++++++++++++++++++
  utils/media-ctl/Makefile.am                       |   12 +-
  utils/media-ctl/libmediactl.c                     |  271 +++++++++-
  utils/media-ctl/libmediatext.pc.in                |   10 +
  utils/media-ctl/libv4l2media_ioctl.c              |  369 +++++++++++++
  utils/media-ctl/libv4l2media_ioctl.h              |   40 ++
  utils/media-ctl/libv4l2subdev.c                   |  301 ++++++++++-
  utils/media-ctl/mediactl-priv.h                   |   11 +-
  utils/media-ctl/mediactl.h                        |  151 ++++++
  utils/media-ctl/mediatext-test.c                  |   64 +++
  utils/media-ctl/mediatext.c                       |  311 +++++++++++
  utils/media-ctl/mediatext.h                       |   52 ++
  utils/media-ctl/v4l2subdev.h                      |  131 +++++
  16 files changed, 2292 insertions(+), 30 deletions(-)

create mode 100644 lib/libv4l-exynos4-camera/Makefile.am create mode 100644 lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c 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 · 2 lines
Best Regards,
Jacek Anaszewski
#17 lore raw
Quoted 8 lines · Jacek Anaszewski

Hi Hans,

It got stuck on this version. I have some slight improvements locally but haven't sent them as there hasn't been any comment to this so far. AFAIR Sakari had some doubts about handling multiple pipelines within one media controller. In this approach only one pipeline is allowed. There has to be a new IOCTL added for locking pipelines, to handle this IIRC.

Sakari, is this ioctl really needed or something that can be added later?

Quoted 2 lines

Besides there are some v4l-utils build system dependency issues to solve, I mentioned below in the cover letter.

If I remember correctly the libmediactl API may still change, which is why it isn't in lib. So statically linking it isn't a bad idea at the moment. Laurent, can you confirm this?

Is there anything else that blocks this patch series?

Regards,

Hans

Quoted 138 lines · Hans Verkuil
Quoted 134 lines

Hi Jacek,

What is the status of this? It would be really useful to have a working plugin as an example in v4l-utils.

Regards,

Hans

Quoted 122 lines · Jacek Anaszewski

This is a fifth 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 utils are built after the plugins, but libv4l-exynos4-camera plugin depends on the utils. In order to link the plugin against libmediactl the build system would have to be modified.

================
Changes from v4:
================

- removed some redundant functions for traversing media device graph and switched over to using existing ones
- avoided accessing struct v4l2_subdev from libmediactl
- applied various improvements

================
Changes from v3:
================

- added struct v4l2_subdev and put entity fd and information about supported controls to it
- improved functions for negotiating and setting pipeline format by using available libv4lsubdev API
- applied minor improvements and cleanups

================
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 linux-next_20150223 with patches for exynos4-is that fix failing open ioctl 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

Thanks,
Jacek Anaszewski

[1] https://patchwork.linuxtv.org/patch/26366/
[2] https://patchwork.linuxtv.org/patch/26367/
[3] https://patchwork.linuxtv.org/patch/26368/

Jacek Anaszewski (13):
mediactl: Introduce v4l2_subdev structure
mediactl: Add support for v4l2-ctrl-redir config
mediatext: Add library
mediactl: Add media device graph helpers
mediactl: Add media_device creation helpers
mediactl: libv4l2subdev: add VYUY8_2X8 mbus code
mediactl: Add support for media device pipelines
mediactl: libv4l2subdev: add support for comparing mbus formats
mediactl: libv4l2subdev: add support for setting pipeline format
mediactl: libv4l2subdev: add get_pipeline_entity_by_cid function
mediactl: Add media device ioctl API
mediactl: libv4l2subdev: Enable opening/closing pipelines 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 |  586 +++++++++++++++++++++
  utils/media-ctl/Makefile.am                       |   12 +-
  utils/media-ctl/libmediactl.c                     |  271 +++++++++-
  utils/media-ctl/libmediatext.pc.in                |   10 +
  utils/media-ctl/libv4l2media_ioctl.c              |  369 +++++++++++++
  utils/media-ctl/libv4l2media_ioctl.h              |   40 ++
  utils/media-ctl/libv4l2subdev.c                   |  301 ++++++++++-
  utils/media-ctl/mediactl-priv.h                   |   11 +-
  utils/media-ctl/mediactl.h                        |  151 ++++++
  utils/media-ctl/mediatext-test.c                  |   64 +++
  utils/media-ctl/mediatext.c                       |  311 +++++++++++
  utils/media-ctl/mediatext.h                       |   52 ++
  utils/media-ctl/v4l2subdev.h                      |  131 +++++
  16 files changed, 2292 insertions(+), 30 deletions(-)

create mode 100644 lib/libv4l-exynos4-camera/Makefile.am create mode 100644 lib/libv4l-exynos4-camera/libv4l-exynos4-camera.c 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

#18 lore raw
Quoted 12 lines · Hans Verkuil
Quoted 8 lines · Jacek Anaszewski

Hi Hans,

It got stuck on this version. I have some slight improvements locally but haven't sent them as there hasn't been any comment to this so far. AFAIR Sakari had some doubts about handling multiple pipelines within one media controller. In this approach only one pipeline is allowed. There has to be a new IOCTL added for locking pipelines, to handle this IIRC.

Sakari, is this ioctl really needed or something that can be added later?

Quoted 8 lines
Quoted 2 lines

Besides there are some v4l-utils build system dependency issues to solve, I mentioned below in the cover letter.

If I remember correctly the libmediactl API may still change, which is why it isn't in lib. So statically linking it isn't a bad idea at the moment. Laurent, can you confirm this?

Is there anything else that blocks this patch series?

v4l-utils side issues:

I'd have to apply my local bug fixes and submit the next version.

Kernel side issues:

There is a regression in the kernel related to FIMC-LITE and FIMC-IS-ISP entities. Effectively currently it is only possible to setup pipelines with S5C73M3 sensor to fimc.0.capture and fimc.1.capture entities.

I would also have to rebase the patches for exynos4-is driver for avoiding failure on open when the device being opened has no connected sensor.

Signature · 2 lines
Best Regards,
Jacek Anaszewski