Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: aiyengar1990@gmail.com,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>,
	 Philipp Zabel <p.zabel@pengutronix.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Heiko Stuebner	 <heiko@sntech.de>,
	Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	Hans Verkuil <hverkuil@kernel.org>,
	Boris Brezillon <boris.brezillon@collabora.com>,
	Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
	 linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Sergei Khomenkov <shomenkow@gmail.com>
Subject: Re: [PATCH v2 2/7] media: verisilicon: Enforce a minimum CAPTURE sizeimage for the encoder
Date: Mon, 23 Nov 2026 21:45:44 -0500	[thread overview]
Message-ID: <74db7a7fa49abac0a91fb8585703b90244428b02.camel@collabora.com> (raw)
In-Reply-To: <20261112-hantro-jpeg-enc-fixes-v2-2-de03e643c75d@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3063 bytes --]

Le jeudi 12 novembre 2026 à 08:31 +0000, Arun Iyengar via B4 Relay a écrit :
> From: Arun Iyengar <aiyengar1990@gmail.com>
> 
> For coded formats hantro_try_fmt() only computes sizeimage when the
> application passes 0, and otherwise accepts any value. On the encoder
> that lets the CAPTURE buffers be far too small for the selected
> resolution.
> 
> This is easy to hit: "v4l2-ctl --set-fmt-video=width=1920,height=1080,
> pixelformat=JPEG" does G_FMT, modifies the size and calls S_FMT, so it
> passes back the 6768 byte sizeimage of the 96x32 default format. The
> driver accepts it for 1920x1088, the hardware runs out of stream buffer
> on every frame and the encoder only produces empty buffers.
> 
> The stateful encoder specification lets the encoder adjust sizeimage to
> match hardware requirements. For the encoder, clamp the requested
> sizeimage up to the size already used as the default, while still
> allowing applications to ask for larger buffers. The decoder behaviour
> is unchanged.
> 
> Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
> ---
>  drivers/media/platform/verisilicon/hantro_v4l2.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c
> index d033fe0ecef6..c4e36a79eecc 100644
> --- a/drivers/media/platform/verisilicon/hantro_v4l2.c
> +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
> @@ -386,14 +386,25 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
>  			pix_mp->plane_fmt[0].sizeimage +=
>  				hantro_av1_mv_size(pix_mp->width,
>  						   pix_mp->height);
> -	} else if (!pix_mp->plane_fmt[0].sizeimage) {
> +	} else {
> +		u32 max_size = fmt->header_size +
> +			pix_mp->width * pix_mp->height * fmt->max_depth;
> +		u32 *sizeimage = &pix_mp->plane_fmt[0].sizeimage;
> +
>  		/*
>  		 * For coded formats the application can specify
>  		 * sizeimage. If the application passes a zero sizeimage,
>  		 * let's default to the maximum frame size.
> +		 *
> +		 * On the encoder, a buffer that is too small for the
> +		 * current resolution only gives failed frames, so never
> +		 * let the application go below that default. Larger
> +		 * values are kept.
>  		 */
> -		pix_mp->plane_fmt[0].sizeimage = fmt->header_size +
> -			pix_mp->width * pix_mp->height * fmt->max_depth;
> +		if (ctx->is_encoder)
> +			*sizeimage = max(*sizeimage, max_size);
> +		else if (!*sizeimage)
> +			*sizeimage = max_size;

I find this part a bit loaded, maye you could add a helper and do something such
as:

	} else if (ctx->is_encoder) {
		u32 sizeimage = pix_mp->plane_fmt[0].sizeimage;
		u32 max_size = coded_max_size(pix_mp, fmt);
		pix_mp->plane_fmt[0].sizeimage = max(sizeimage, max_size);
	} else if (!pix_mp->plane_fmt[0].sizeimage) {
		pix_mp->plane_fmt[0].sizeimage = coded_max_size(pix_mp, fmt);
	}

>  
>  	return 0;

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-11-24  2:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  8:31 [PATCH v2 0/7] media: verisilicon: Fix the JPEG encoder format handling Arun Iyengar via B4 Relay
2026-11-12  8:31 ` [PATCH v2 1/7] media: verisilicon: Keep the encoder CAPTURE format while buffers exist Arun Iyengar via B4 Relay
2026-11-12  8:31 ` [PATCH v2 2/7] media: verisilicon: Enforce a minimum CAPTURE sizeimage for the encoder Arun Iyengar via B4 Relay
2026-11-24  2:45   ` Nicolas Dufresne [this message]
2026-11-12  8:31 ` [PATCH v2 3/7] media: verisilicon: Keep the encoder coded size in sync with OUTPUT Arun Iyengar via B4 Relay
2026-11-24  2:57   ` Nicolas Dufresne
2026-11-12  8:31 ` [PATCH v2 4/7] media: verisilicon: Refuse JPEG encode jobs with inconsistent geometry Arun Iyengar via B4 Relay
2026-11-12  8:31 ` [PATCH v2 5/7] media: verisilicon: Report fixed JPEG colorimetry on the encoder Arun Iyengar via B4 Relay
2026-11-12  8:31 ` [PATCH v2 6/7] media: verisilicon: Don't reset the encoder raw format while OUTPUT buffers exist Arun Iyengar via B4 Relay
2026-11-12  8:31 ` [PATCH v2 7/7] media: verisilicon: rockchip: Limit the JPEG encoder to 8176x8176 Arun Iyengar via B4 Relay

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=74db7a7fa49abac0a91fb8585703b90244428b02.camel@collabora.com \
    --to=nicolas.dufresne@collabora.com \
    --cc=aiyengar1990@gmail.com \
    --cc=andrzej.p@collabora.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=boris.brezillon@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=heiko@sntech.de \
    --cc=hverkuil@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=shomenkow@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox