Re: [PATCH v7 2/4] media: rockchip: Add JPEG decoder driver
From: Sascha Hauer
Date: Wed Nov 18 2026 - 09:27:48 EST
Hi Sergei,
On 2026-11-07 15:38, Sergei Khomenkov wrote:
> Hi Sascha,
>
> > +/* Bytes per pixel used to size a coded buffer for a given resolution. */
> > +#define RKJPEGD_CODED_MAX_DEPTH 2
>
> A valid JPEG can be larger than 2 bytes per pixel. libjpeg-turbo sizes
> its worst case in tj3JPEGBufSize() at 3 bytes per pixel for 4:2:0, 4
> for 4:2:2 and 6 for 4:4:4, plus 2 KiB. Quality 100 noise comes close:
> 2.75 bytes per pixel at 4:2:0, both from libjpeg and from the Hantro H1
> encoder on an RK3026. Such a frame does not fit the default buffer; by
> your commit message a truncated one fails through BUF_EMPTY, so the
> client gets an ERROR buffer for a valid picture. I can't run the VDPU720
> to confirm.
>
> The default only matters to clients that pass sizeimage 0. GStreamer
> 1.26 asks for max_width * max_height / 2 of the enumerated range; at
> 65528x65528 that wraps in its 32-bit calculate_max_sizeimage() to about
> 255 MiB, which the driver keeps, so 1.26 is not affected. Its main
> branch (08ea5bc9fab9) asks for width * height bytes of the stream,
> which the driver keeps too, so these frames would not fit. Both are
> from reading the code; I did not run them on this driver.
>
> Would 3 bytes per pixel be acceptable as the default, and as a floor
> for smaller requests, like the 2 bytes per pixel floor in 6/7 of your
> hantro-based v1? 4:4:4 at quality 100 would still not fit, but the
> subsampling is not known before the header is parsed.
I haven't been affected by this issue lately, but saw it when the series
was still based on the hantro driver. Yes, I'll change to 3 bytes per
pixel next round and make that the floor of sizeimage. Would be nice to
have a proper solution for this rather than either wasting tons of
memory or risk having too small buffers.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |