[libcamera-devel] [PATCH 09/12] android: jpeg: Use maxJpegBufferSize() for compatibility

Jacopo Mondi jacopo at jmondi.org
Mon Mar 1 08:41:10 CET 2021


Hi Laurent,

On Sun, Feb 28, 2021 at 08:48:32PM +0200, Laurent Pinchart wrote:
> Hi Jacopo,
>
> Thank you for the patch.
>
> On Fri, Feb 26, 2021 at 02:29:29PM +0100, Jacopo Mondi wrote:
> > Platforms that do not provide a memory backend implementation should
> > keep using the maxJpegBufferSize() value to calculate the location where
> > to place the JPEG blob id, as the android_generic backend returns the
> > allocated buffer size as calculated using lseek which is larger than
> > the maximum JPEG frame size, which is where the framework expects the
> > JPEG blob to be placed.
> >
> > Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
> > ---
> >  src/android/jpeg/post_processor_jpeg.cpp | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> >
> > diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp
> > index d6eeb962e81d..e7f66d66698c 100644
> > --- a/src/android/jpeg/post_processor_jpeg.cpp
> > +++ b/src/android/jpeg/post_processor_jpeg.cpp
> > @@ -185,9 +185,17 @@ int PostProcessorJpeg::process(const FrameBuffer &source,
> >  	}
> >
> >  	/* Fill in the JPEG blob header. */
> > -	uint8_t *resultPtr = destination->plane(0) +
> > -			     destination->planeSize(0) -
> > -			     sizeof(struct camera3_jpeg_blob);
> > +	/*
> > +	 * \todo For backward compatibility reasons with the android_generic
> > +	 * memory backend, continue using the maxJpegBufferSize in case the
> > +	 * computed buffer size is larger. This can be dropped once all
> > +	 * supported platforms will have a working memory backend that
> > +	 * returns the correct buffer size.
> > +	 */
> > +	size_t blobSize = std::min<unsigned int>(cameraDevice_->maxJpegBufferSize(),
> > +						 destination->planeSize(0));
>
> Can't Chrome OS allocate buffers larger than maxJpegBufferSize() ? In

I don't think the real buffer size, as calculated through the correct
memory backend could be larger than the maximum reported size. The
purpose of the jpeg.MaxSize is to report the maximum allocation the
camera framework has to perform to support the largest JPEG size,
don't it ?

This (seems) to only happen when the backend mis-calculate the buffer
size and returns a value larger than jpeg.MaxSize

> that case it would expect the JPEG blob to be at the end of the buffer,
> not after maxJpegBufferSize() bytes.
>
> I'm tempted to just drop this patch. If we want to keep it for other
> Android platforms, we'll need an additional function in CameraBuffer to
> report if the implementation has retrieved the size correctly. It's a
> bit of a hack, but this is a hack anyway :-)
>
> Up to you whether you prefer dropping the patch or keeping it with a new
> CameraBuffer function.
>
> > +	uint8_t *resultPtr = destination->plane(0) + blobSize
> > +			   - sizeof(struct camera3_jpeg_blob);
> >  	auto *blob = reinterpret_cast<struct camera3_jpeg_blob *>(resultPtr);
> >  	blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;
> >  	blob->jpeg_size = jpeg_size;
>
> --
> Regards,
>
> Laurent Pinchart


More information about the libcamera-devel mailing list