android: camera_buffer: Add method to get the JPEG blob size

To maintain compatibility with platforms that do not provide a memory
backend implementation add a method to be return the size of the buffer
used for JPEG encoding capped to a maximum size.

Platforms that implement a memory backend will always calculate the
correct buffer size.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Jacopo Mondi 2021-02-25 17:51:54 +01:00
parent eba862b0e3
commit 1223da76a2
2 changed files with 16 additions and 0 deletions

View file

@ -27,6 +27,8 @@ public:
unsigned int numPlanes() const;
Span<uint8_t> plane(unsigned int plane);
size_t jpegBufferSize(size_t maxJpegBufferSize) const;
};
CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,
@ -77,6 +79,12 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
return maps_[plane];
}
size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const
{
return std::min<unsigned int>(maps_[0].size(),
maxJpegBufferSize);
}
CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags)
: Extensible(new Private(this, camera3Buffer, flags))
{
@ -109,3 +117,9 @@ Span<uint8_t> CameraBuffer::plane(unsigned int plane)
Private *const d = LIBCAMERA_D_PTR();
return d->plane(plane);
}
size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const
{
const Private *const d = LIBCAMERA_D_PTR();
return d->jpegBufferSize(maxJpegBufferSize);
}