All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Dennis Rachui <drachui@de.adit-jv.com>,
	Steve Longerbeam <slongerbeam@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Maxime Ripard <mripard@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: rcar-csi2: do not update format while streaming
Date: Tue, 13 Jul 2021 11:42:17 +0200	[thread overview]
Message-ID: <YO1f+SOTBS44/Wf0@oden.dyn.berto.se> (raw)
In-Reply-To: <YOoiZM+oicZBD4o1@pendragon.ideasonboard.com>

Hi Laurent,

On 2021-07-11 01:42:44 +0300, Laurent Pinchart wrote:
> Hi Niklas,
> 
> On Fri, Jul 09, 2021 at 04:20:40PM +0200, Niklas Söderlund wrote:
> > On 2021-07-08 15:22:58 +0200, Dennis Rachui wrote:
> > > Verify that streaming is not active before setting the pad format.
> > > 
> > > According to the VIDIOC documentation [1] changes to the active
> > > format of a media pad via the VIDIOC_SUBDEV_S_FMT ioctl are
> > > applied to the underlying hardware.
> > > In rcar-csi2 a format change only applies to hardware, when the
> > > pipeline is started. While the device is not in use, it is therefore
> > > okay to update the format.
> > > 
> > > However, when the pipeline is active, this leads to a format
> > > mismatch between driver and device.
> > > Other applications can query the format with
> > > VIDIOC_SUBDEV_G_FMT at any time and would be reported
> > > a format that does not fit the current stream.
> > > 
> > > This commit prevents format update while streaming is active
> > > and returns -EBUSY to user space, as suggested by [1].
> > > 
> > > [1] Documentation/userspace-api/media/v4l/vidioc-subdev-g-fmt.rst
> > 
> > I like that this is addressed, but I wonder is this not something that 
> > should be fixed in the V4L2 core and not in drivers?
> 
> Some drivers may support format changes during streaming (that's allowed
> by the V4L2 API, I'm not sure if it's used anywhere though). While I'd
> favour not duplicating the same logic in different (and differently
> buggy) ways in drivers, I'm not sure how this could be implemented in a
> sane way in the V4L2 core in its current state.

I understand it's possible from some devices to support to format 
changes during streaming, but as you point out it's the exception and 
not the rule, if used at all.

So my point is if we start to enforce this in drivers we are headed down 
a road where this will be messier to clean up. Would it not make more 
sens to default the V4L2 core to disallow format changes while streaming 
and add a new flag to V4L2_SUBDEV_CAP_ to signal that the subdevice 
supports format changes while streaming?

We already have V4L2_SUBDEV_CAP_RO_SUBDEV to signal that a subdevice 
only supports read-only operations so I think it would not be too hard 
to move this functionality into the core?

> 
> > > Note: after creation of this commit, it was noticed that Steve
> > > Longerbeam has a very similar solution in his fork.
> > > 
> > > Fixes: 769afd212b16 ("media: rcar-csi2: add Renesas R-Car MIPI CSI-2 receiver driver")
> > > Cc: Steve Longerbeam <slongerbeam@gmail.com>
> > > Signed-off-by: Dennis Rachui <drachui@de.adit-jv.com>
> > > ---
> > >  drivers/media/platform/rcar-vin/rcar-csi2.c | 21 ++++++++++++++++++++-
> > >  1 file changed, 20 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > > index e28eff0..98152e1 100644
> > > --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> > > +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > > @@ -724,18 +724,37 @@ static int rcsi2_set_pad_format(struct v4l2_subdev *sd,
> > >  {
> > >  	struct rcar_csi2 *priv = sd_to_csi2(sd);
> > >  	struct v4l2_mbus_framefmt *framefmt;
> > > +	int ret = 0;
> > > +
> > > +	mutex_lock(&priv->lock);
> > >  
> > >  	if (!rcsi2_code_to_fmt(format->format.code))
> > >  		format->format.code = rcar_csi2_formats[0].code;
> > >  
> > >  	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> > > +
> > > +		/*
> > > +		 * Do not apply changes to active format while streaming.
> > > +		 *
> > > +		 * Since video streams could be forwarded from sink pad to any
> > > +		 * source pad (depending on CSI-2 channel routing), all
> > > +		 * media pads are effected by this rule.
> > > +		 */
> > > +		if (priv->stream_count > 0) {
> > > +			ret = -EBUSY;
> > > +			goto out;
> > > +		}
> > > +
> > >  		priv->mf = format->format;
> > >  	} else {
> > >  		framefmt = v4l2_subdev_get_try_format(sd, sd_state, 0);
> > >  		*framefmt = format->format;
> > >  	}
> > >  
> > > -	return 0;
> > > +out:
> > > +	mutex_unlock(&priv->lock);
> > > +
> > > +	return ret;
> > >  }
> > >  
> > >  static int rcsi2_get_pad_format(struct v4l2_subdev *sd,
> 
> -- 
> Regards,
> 
> Laurent Pinchart

-- 
Regards,
Niklas Söderlund

  reply	other threads:[~2021-07-13  9:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08 13:22 [PATCH] media: rcar-csi2: do not update format while streaming Dennis Rachui
2021-07-09 14:20 ` Niklas Söderlund
2021-07-10 22:42   ` Laurent Pinchart
2021-07-13  9:42     ` Niklas Söderlund [this message]
2021-07-14 18:40       ` Laurent Pinchart
2021-07-15 10:57         ` Niklas Söderlund
2021-07-15 11:39           ` Laurent Pinchart
2021-07-16 14:09             ` Dennis Rachui
2021-07-16 15:02               ` Niklas Söderlund
2021-07-19 10:53                 ` Dennis Rachui
2021-07-16 15:07               ` Laurent Pinchart
2021-07-19 11:17                 ` Dennis Rachui

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=YO1f+SOTBS44/Wf0@oden.dyn.berto.se \
    --to=niklas.soderlund@ragnatech.se \
    --cc=drachui@de.adit-jv.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mripard@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=slongerbeam@gmail.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.