[libcamera-devel] [PATCH] android: camera_device: Calculate MAX_JPEG_SIZE

Umang Jain email at uajain.com
Fri Feb 5 17:01:52 CET 2021


Hi Jacopo

On 2/2/21 6:06 PM, Jacopo Mondi wrote:
> Calculate the JPEG maximum size using the maximum preview format size
> multiplied by a 1.5 factor.
>
> The same multiplication factor is used in the existing HAL
> implementation in ChromeOS.
>
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
> ---
>   src/android/camera_device.cpp | 21 ++++++++++-----------
>   1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index a50b0ebfe60e..cb87d97888ed 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -347,12 +347,6 @@ CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camer
>   {
>   	camera_->requestCompleted.connect(this, &CameraDevice::requestComplete);
>   
> -	/*
> -	 * \todo Determine a more accurate value for this during
> -	 *  streamConfiguration.
> -	 */
> -	maxJpegBufferSize_ = 13 << 20; /* 13631488 from USB HAL */
> -
Since we are removing from constructor, I would add a initialize value 
to 0, in constructor initializer list above, since this is (now) used 
inside a conditional block in initializeStreamConfigurations()

Other than that;

Reviewed-by: Umang Jain <email at uajain.com>
>   	maker_ = "libcamera";
>   	model_ = "cameraModel";
>   
> @@ -629,6 +623,7 @@ int CameraDevice::initializeStreamConfigurations()
>   							mappedFormat,
>   							cameraResolutions);
>   
> +		Size maxJpegSize;
>   		for (const Size &res : resolutions) {
>   			streamConfigurations_.push_back({ res, androidFormat });
>   
> @@ -643,9 +638,17 @@ int CameraDevice::initializeStreamConfigurations()
>   			 * \todo Support JPEG streams produced by the Camera
>   			 * natively.
>   			 */
> -			if (androidFormat == HAL_PIXEL_FORMAT_YCbCr_420_888)
> +			if (androidFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) {
>   				streamConfigurations_.push_back(
>   					{ res, HAL_PIXEL_FORMAT_BLOB });
> +
> +				if (res > maxJpegSize) {
> +					maxJpegSize = res;
> +					maxJpegBufferSize_ = maxJpegSize.width
> +							   * maxJpegSize.height
> +							   * 1.5;
> +				}
> +			}
>   		}
>   	}
>   
> @@ -878,10 +881,6 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
>   				  availableThumbnailSizes.data(),
>   				  availableThumbnailSizes.size());
>   
> -	/*
> -	 * \todo Calculate the maximum JPEG buffer size by asking the encoder
> -	 * giving the maximum frame size required.
> -	 */
>   	staticMetadata_->addEntry(ANDROID_JPEG_MAX_SIZE, &maxJpegBufferSize_, 1);
>   
>   	/* Sensor static metadata. */



More information about the libcamera-devel mailing list