All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonas Karlman <jonas@kwiboo.se>
To: Ezequiel Garcia <ezequiel@collabora.com>,
	linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Hans Verkuil <hans.verkuil@cisco.com>,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	Tomasz Figa <tfiga@chromium.org>,
	Alexandre Courbot <acourbot@chromium.org>
Subject: Re: [PATCH 8/9] media: rkvdec: Add validate_fmt ops for pixelformat validation
Date: Fri, 03 Jul 2020 19:17:56 +0000 (UTC)	[thread overview]
Message-ID: <0353b993-907d-2dfe-993f-94b82aa27e00@kwiboo.se> (raw)
In-Reply-To: <7abec9992460dcd84a2c951fce55bc8e46f2a0ed.camel@collabora.com>

On 2020-07-03 16:58, Ezequiel Garcia wrote:
> On Fri, 2020-07-03 at 06:55 +0000, Jonas Karlman wrote:
>> On 2020-07-03 05:14, Ezequiel Garcia wrote:
>>> Hi Jonas,
>>>
>>> Thanks for working on this.
>>>
>>> On Wed, 2020-07-01 at 21:56 +0000, Jonas Karlman wrote:
>>>> Add an optional validate_fmt operation that is used to validate the
>>>> pixelformat of CAPTURE buffers.
>>>>
>>>> This is used in next patch to ensure correct pixelformat is used for 10-bit
>>>> and 4:2:2 content.
>>>>
>>>> Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
>>>> ---
>>>>  drivers/staging/media/rkvdec/rkvdec.c | 8 ++++++++
>>>>  drivers/staging/media/rkvdec/rkvdec.h | 1 +
>>>>  2 files changed, 9 insertions(+)
>>>>
>>>> diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
>>>> index b1de55aa6535..465444c58f13 100644
>>>> --- a/drivers/staging/media/rkvdec/rkvdec.c
>>>> +++ b/drivers/staging/media/rkvdec/rkvdec.c
>>>> @@ -239,6 +239,14 @@ static int rkvdec_try_capture_fmt(struct file *file, void *priv,
>>>>  	if (WARN_ON(!coded_desc))
>>>>  		return -EINVAL;
>>>>  
>>>> +	if (coded_desc->ops->validate_fmt) {
>>>> +		int ret;
>>>> +
>>>> +		ret = coded_desc->ops->validate_fmt(ctx, pix_mp->pixelformat);
>>>> +		if (ret)
>>>> +			return ret;
>>>> +	}
>>>> + 
>>>
>>> I don't think this approach will be enough. Unless I'm mistaken,
>>> it's perfectly legal as per the stateless spec to first
>>> call S_FMT on the OUTPUT queue (which is propagated to the CAPTURE side),
>>> and then set the SPS and other controls.
>>
>> I agree that this will not be enough to cover all use cases stated in the spec.
>>
>>> The application is not required to do a TRY_FMT after S_EXT_CTRLS.
>>
>> If I remember correctly we were required to implement a TRY_FMT loop in
>> ffmpeg due to cedrus defaulting to SUNXI_TILED_NV12 instead of linear NV12
>> on platforms where display controller did not support the tiled modifier.
>>
>> So having TRY_FMT as part of the init sequence has been my only test-case.
>>
>>> What I believe is needed is for the S_EXT_CTRLS to modify
>>> and restrict the CAPTURE format accordingly, so the application
>>> gets the correct format on G_FMT (and restrict future TRY_FMT).
>>
>> This sounds like a proper solution, I do belive we may have a chicken or
>> the egg problem depending on if application call S_EXT_CTRLS or S_FMT first.
>>
> 
> IIUC, the order is specified in the stateless spec [1].
> 
> 1) S_FMT on OUTPUT (to set the coded pixelformat). CAPTURE format
> format is propagated here and a default format is set.
> 
> 2) S_EXT_CTRLS, parameters are set. We don't do anything here,
> but here we'd validate the SPS and restrict the CAPTURE pixelformat
> (and perhaps reset the default CAPTURE pixelformat).
> 
> 3) G_FMT on CAPTURE.
> 
> 4) (optional) ENUM_FMT / S_FMT on CAPTURE, to negotiate
> something different from default.

There is also the following scenario that we may need to support:

1) S_FMT on OUTPUT, default CAPTURE format is set.

2) skip S_EXT_CTRLS, mandatory controls is only validated in req_validate.

3) G_FMT on CAPTURE, returns default CAPTURE format.

4) S_FMT on CAPTURE, CAPTURE format is changed from default to selected format.

5) STREAMON

From this point on I would expect S_EXT_CTRLS with a V4L2_CTRL_WHICH_REQUEST_VAL
flag to reject any SPS not matching the selected CAPTURE format. Effectively
allowing S_FMT to lock down a format instead of an initial S_EXT_CTRLS during init.

This means that we have to both allow and reject a SPS depending on the state.

Regards,
Jonas

> 
> Regards,
> Ezequiel 
> 
> [1] Documentation/userspace-api/media/v4l/dev-stateless-decoder.rst
> 
>> I guess we may need to lock down on a format at whatever comes first,
>> S_FMT on CAPTURE or S_EXT_CTRLS with SPS ctrl.
>>
>> I have an idea on how this could be addressed, will explore and see
>> if I can come up with something new.
>>
>> Regards,
>> Jonas
>>
>>> Also, V4L2 spec asks drivers not to fail on S_FMT
>>> format mismatch, but instead to adjust and return a legal format
>>> back to the application [1].
>>>
>>> Let me know what you think and thanks again.
>>>
>>> Ezequiel
>>>
>>> [1] Documentation/userspace-api/media/v4l/vidioc-g-fmt.rst
>>>
>>>>  	for (i = 0; i < coded_desc->num_decoded_fmts; i++) {
>>>>  		if (coded_desc->decoded_fmts[i] == pix_mp->pixelformat)
>>>>  			break;
>>>> diff --git a/drivers/staging/media/rkvdec/rkvdec.h b/drivers/staging/media/rkvdec/rkvdec.h
>>>> index 2fc9f46b6910..be4fc3645cde 100644
>>>> --- a/drivers/staging/media/rkvdec/rkvdec.h
>>>> +++ b/drivers/staging/media/rkvdec/rkvdec.h
>>>> @@ -64,6 +64,7 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)
>>>>  struct rkvdec_coded_fmt_ops {
>>>>  	int (*adjust_fmt)(struct rkvdec_ctx *ctx,
>>>>  			  struct v4l2_format *f);
>>>> +	int (*validate_fmt)(struct rkvdec_ctx *ctx, u32 pixelformat);
>>>>  	int (*start)(struct rkvdec_ctx *ctx);
>>>>  	void (*stop)(struct rkvdec_ctx *ctx);
>>>>  	int (*run)(struct rkvdec_ctx *ctx);
> 
> 

  reply	other threads:[~2020-07-03 19:18 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01 21:56 [PATCH 0/9] media: rkvdec: Add H.264 High 10 and 4:2:2 profile support Jonas Karlman
2020-07-01 21:56 ` [PATCH 1/9] media: rkvdec: h264: Support profile and level controls Jonas Karlman
2020-07-03  2:54   ` Ezequiel Garcia
2020-07-03  5:30     ` Jonas Karlman
2020-07-01 21:56 ` [PATCH 3/9] media: rkvdec: h264: Fix pic width and height in mbs Jonas Karlman
2020-07-03  2:48   ` Ezequiel Garcia
2020-07-03 11:28     ` Jonas Karlman
2020-07-01 21:56 ` [PATCH 2/9] media: rkvdec: h264: Fix reference frame_num wrap for second field Jonas Karlman
2020-07-03  2:55   ` Ezequiel Garcia
2020-07-03  3:01   ` Ezequiel Garcia
2020-07-01 21:56 ` [PATCH 5/9] media: v4l2-common: Add helpers to calculate bytesperline and sizeimage Jonas Karlman
2020-07-01 21:56 ` [PATCH 4/9] media: rkvdec: h264: Fix bit depth wrap in pps packet Jonas Karlman
2020-07-03  2:58   ` Ezequiel Garcia
2020-07-01 21:56 ` [PATCH 6/9] media: v4l2: Add NV15 and NV20 pixel formats Jonas Karlman
2020-07-01 21:56 ` [PATCH 7/9] media: rkvdec: h264: Use bytesperline and buffer height to calculate stride Jonas Karlman
2020-07-03  3:21   ` Ezequiel Garcia
2020-07-03 11:40     ` Jonas Karlman
2020-07-01 21:56 ` [PATCH 8/9] media: rkvdec: Add validate_fmt ops for pixelformat validation Jonas Karlman
2020-07-03  3:14   ` Ezequiel Garcia
2020-07-03  6:55     ` Jonas Karlman
2020-07-03 14:58       ` Ezequiel Garcia
2020-07-03 19:17         ` Jonas Karlman [this message]
2020-07-03 19:33           ` Ezequiel Garcia
2020-07-03 19:34           ` Tomasz Figa
2020-07-01 21:56 ` [PATCH 9/9] media: rkvdec: h264: Support High 10 and 4:2:2 profiles Jonas Karlman
2020-07-06 21:54 ` [PATCH v2 00/12] media: rkvdec: Add H.264 High 10 and 4:2:2 profile support Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 01/12] media: rkvdec: h264: Fix reference frame_num wrap for second field Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 03/12] media: rkvdec: h264: Validate and use pic width and height in mbs Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 02/12] media: rkvdec: Ensure decoded resolution fit coded resolution Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 06/12] media: v4l2-common: Add helpers to calculate bytesperline and sizeimage Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 05/12] media: rkvdec: h264: Do not override output buffer sizeimage Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 04/12] media: rkvdec: h264: Fix bit depth wrap in pps packet Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 08/12] media: rkvdec: h264: Use bytesperline and buffer height to calculate stride Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 07/12] media: v4l2: Add NV15 and NV20 pixel formats Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 10/12] media: rkvdec: Lock capture pixel format in s_ctrl and s_fmt Jonas Karlman
2020-07-08  3:16     ` Ezequiel Garcia
2020-07-08 12:42       ` Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 11/12] media: rkvdec: h264: Support High 10 and 4:2:2 profiles Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 09/12] media: rkvdec: Extract rkvdec_fill_decoded_pixfmt helper method Jonas Karlman
2020-07-06 21:54   ` [PATCH v2 12/12] media: rkvdec: h264: Support profile and level controls Jonas Karlman
2020-07-08  3:19     ` Ezequiel Garcia
2020-07-08  9:34       ` Jonas Karlman

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=0353b993-907d-2dfe-993f-94b82aa27e00@kwiboo.se \
    --to=jonas@kwiboo.se \
    --cc=acourbot@chromium.org \
    --cc=ezequiel@collabora.com \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=tfiga@chromium.org \
    /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.