From 756fcbaaf2df0e563e066090f1d3e529f74ebe84 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Thu, 28 Jan 2021 15:26:20 +0100 Subject: android: camera_device: Calculate MAX_JPEG_SIZE 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 implementations in ChromeOS. Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- 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 ad7e31cf..1e2a5b5f 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 &camer { camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); - /* - * \todo Determine a more accurate value for this during - * streamConfiguration. - */ - maxJpegBufferSize_ = 13 << 20; /* 13631488 from USB HAL */ - maker_ = "libcamera"; model_ = "cameraModel"; @@ -550,6 +544,7 @@ int CameraDevice::initializeStreamConfigurations() * build the stream configuration map reported through the camera static * metadata. */ + Size maxJpegSize; for (const auto &format : camera3FormatsMap) { int androidFormat = format.first; const Camera3Format &camera3Format = format.second; @@ -643,10 +638,18 @@ 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 }); + maxJpegSize = std::max(maxJpegSize, res); + } } + + /* + * \todo Calculate the maximum JPEG buffer size by asking the + * encoder giving the maximum frame size required. + */ + maxJpegBufferSize_ = maxJpegSize.width * maxJpegSize.height * 1.5; } LOG(HAL, Debug) << "Collected stream configuration map: "; @@ -923,10 +926,6 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() staticMetadata_->addEntry(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, thumbnailEntries.data(), thumbnailEntries.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. */ -- cgit v1.2.1