Re: [PATCH v2 2/7] media: verisilicon: Enforce a minimum CAPTURE sizeimage for the encoder
From: Nicolas Dufresne
Date: Mon Nov 23 2026 - 21:45:53 EST
Le jeudi 12 novembre 2026 à 08:31 +0000, Arun Iyengar via B4 Relay a écrit :
> From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
>
> 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@xxxxxxxxx>
> ---
> 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:
signature.asc
Description: This is a digitally signed message part