All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
To: linux-media@vger.kernel.org
Cc: "Laurent Pinchart" <laurent.pinchart+renesas@ideasonboard.com>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>,
	"Kieran Bingham" <kieran.bingham+renesas@ideasonboard.com>,
	"Jacopo Mondi" <jacopo+renesas@jmondi.org>,
	"Benoit Parrot" <bparrot@ti.com>,
	linux-renesas-soc@vger.kernel.org,
	"Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Subject: [PATCH 05/20] v4l2-core: verify all streams formats on multiplexed links
Date: Fri, 11 Aug 2017 11:56:48 +0200	[thread overview]
Message-ID: <20170811095703.6170-6-niklas.soderlund+renesas@ragnatech.se> (raw)
In-Reply-To: <20170811095703.6170-1-niklas.soderlund+renesas@ragnatech.se>

Extend the format validation for multiplexed pads to verify all streams
which are part of the multiplexed link. This might take the verification
to an extreme as it could be argued that one should be able to configure
and start just one stream without having to configure other streams
which the user never intends to start.

It could also be argued that the multiplexer and demultiplexer needs to
know about all formats which could be activated before any stream could
be started. In such case the number of streams described in the frame
descriptor should be dynamic and only possible and configured streams
should be reported which would then solve this issue.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/v4l2-core/v4l2-subdev.c | 72 +++++++++++++++++++++++++++++++----
 1 file changed, 64 insertions(+), 8 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index d6c1a3b777dd2fcd..43cd2b5e3d8ea323 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -541,20 +541,76 @@ v4l2_subdev_link_validate_get_format(struct media_pad *pad,
 	return -EINVAL;
 }
 
+static int v4l2_subdev_link_validate_muxed(struct media_link *link)
+{
+	struct v4l2_mbus_frame_desc sink_fd, source_fd;
+	struct v4l2_subdev *sink_sd, *source_sd;
+	unsigned int i;
+	int ret;
+
+	/* Require both pads in a link to be multiplexed */
+	if ((link->source->flags & MEDIA_PAD_FL_MUXED) == 0 ||
+	    (link->sink->flags & MEDIA_PAD_FL_MUXED) == 0)
+		return -EINVAL;
+
+	sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);
+	source_sd = media_entity_to_v4l2_subdev(link->source->entity);
+
+	/* If not both provide frame descs there is not much to be done */
+	ret = v4l2_subdev_call(sink_sd, pad, get_frame_desc,
+			       link->sink->index, &sink_fd);
+	if (ret < 0)
+		return 0;
+	ret = v4l2_subdev_call(source_sd, pad, get_frame_desc,
+			       link->source->index, &source_fd);
+	if (ret < 0)
+		return 0;
+
+	/* Check both side multiplex same number of streams */
+	if (sink_fd.num_entries != source_fd.num_entries)
+		return -EINVAL;
+
+	/* Verify all formats of the multiplexed pads by examining the
+	 * format of the pads which are routed to them. Maybe this is
+	 * a bad idea...
+	 */
+	for (i = 0; i < sink_fd.num_entries; i++) {
+		struct v4l2_subdev_format sink_fmt, source_fmt;
+
+		sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+		sink_fmt.pad = sink_fd.entry[i].csi2.pad;
+		ret = v4l2_subdev_call(sink_sd, pad, get_fmt, NULL, &sink_fmt);
+		if (ret < 0)
+			return 0;
+
+		source_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+		source_fmt.pad = source_fd.entry[i].csi2.pad;
+		ret = v4l2_subdev_call(source_sd, pad, get_fmt, NULL,
+				       &source_fmt);
+		if (ret < 0)
+			return 0;
+
+		ret = v4l2_subdev_call(sink_sd, pad, link_validate, link,
+					&source_fmt, &sink_fmt);
+		if (ret == -ENOIOCTLCMD)
+			ret = v4l2_subdev_link_validate_default(sink_sd, link,
+								&source_fmt,
+								&sink_fmt);
+		if (ret)
+			return -EPIPE;
+	}
+
+	return 0;
+}
+
 int v4l2_subdev_link_validate(struct media_link *link)
 {
 	struct v4l2_subdev *sink;
 	struct v4l2_subdev_format sink_fmt, source_fmt;
 	int rval;
 
-	/* Require both pads in a link to be multiplexed if one is */
-	if ((link->source->flags | link->sink->flags) & MEDIA_PAD_FL_MUXED) {
-		if ((link->source->flags & MEDIA_PAD_FL_MUXED) == 0)
-			return -EINVAL;
-		if ((link->sink->flags & MEDIA_PAD_FL_MUXED) == 0)
-			return -EINVAL;
-		return 0;
-	}
+	if ((link->source->flags | link->sink->flags) & MEDIA_PAD_FL_MUXED)
+		return v4l2_subdev_link_validate_muxed(link);
 
 	rval = v4l2_subdev_link_validate_get_format(
 		link->source, &source_fmt);
-- 
2.13.3

  parent reply	other threads:[~2017-08-11  9:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-11  9:56 [PATCH 00/20] Add multiplexed media pads to support CSI-2 virtual channels Niklas Söderlund
2017-08-11  9:56 ` [PATCH 01/20] media.h: add MEDIA_PAD_FL_MUXED flag Niklas Söderlund
2017-08-11  9:56 ` [PATCH 02/20] v4l2-subdev.h: add pad and stream aware s_stream Niklas Söderlund
2017-08-11  9:56 ` [PATCH 03/20] v4l2-subdev.h: add CSI-2 bus description to struct v4l2_mbus_frame_desc_entry Niklas Söderlund
2017-08-11  9:56 ` [PATCH 04/20] v4l2-core: check that both pads in a link are muxed if one are Niklas Söderlund
2017-08-11  9:56 ` Niklas Söderlund [this message]
2017-08-11  9:56 ` [PATCH 06/20] rcar-vin: use the pad and stream aware s_stream Niklas Söderlund
2017-08-11  9:56 ` [PATCH 07/20] rcar-csi2: declare sink pad as multiplexed Niklas Söderlund
2017-08-11  9:56 ` [PATCH 08/20] rcar-csi2: switch to pad and stream aware s_stream Niklas Söderlund
2017-08-11  9:56 ` [PATCH 09/20] rcar-csi2: figure out remote pad and stream which are starting Niklas Söderlund
2017-08-11  9:56 ` [PATCH 10/20] rcar-csi2: count usage for each source pad Niklas Söderlund
2017-08-11  9:56 ` [PATCH 11/20] rcar-csi2: when starting CSI-2 receiver use frame descriptor information Niklas Söderlund
2017-08-11  9:56 ` [PATCH 12/20] rcar-csi2: only allow formats on source pads Niklas Söderlund
2017-08-11  9:56 ` [PATCH 13/20] rcar-csi2: implement get_frame_desc Niklas Söderlund
2017-08-11  9:56 ` [PATCH 14/20] adv748x: add module param for virtual channel Niklas Söderlund
2017-08-11  9:56 ` [PATCH 15/20] adv748x: declare source pad as multiplexed Niklas Söderlund
2017-08-11  9:56 ` [PATCH 16/20] adv748x: add translation from pixelcode to CSI-2 datatype Niklas Söderlund
2017-08-11  9:57 ` [PATCH 17/20] adv748x: implement get_frame_desc Niklas Söderlund
2017-08-11  9:57 ` [PATCH 18/20] adv748x: switch to pad and stream aware s_stream Niklas Söderlund
2017-08-11  9:57 ` [PATCH 19/20] adv748x: only allow formats on sink pads Niklas Söderlund
2017-08-11  9:57 ` [PATCH 20/20] arm64: dts: renesas: salvator: use VC1 for CVBS Niklas Söderlund
2017-08-30  7:36   ` Simon Horman
2017-08-30  8:08     ` Niklas Söderlund
2017-08-30  8:08       ` Niklas Söderlund
2017-08-30  9:29       ` Simon Horman
2017-08-29 14:39 ` [PATCH 00/20] Add multiplexed media pads to support CSI-2 virtual channels Maxime Ripard
2018-03-15  9:43 ` Todor Tomov
2018-03-15 23:16   ` Niklas Söderlund
2018-03-15 23:16     ` Niklas Söderlund
2018-03-16  8:12     ` Todor Tomov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170811095703.6170-6-niklas.soderlund+renesas@ragnatech.se \
    --to=niklas.soderlund+renesas@ragnatech.se \
    --cc=bparrot@ti.com \
    --cc=jacopo+renesas@jmondi.org \
    --cc=kieran.bingham+renesas@ideasonboard.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.