From patchwork Tue Feb 2 12:36:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11104 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 69100BD161 for ; Tue, 2 Feb 2021 12:36:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 08B7C68425; Tue, 2 Feb 2021 13:36:05 +0100 (CET) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 748FC60307 for ; Tue, 2 Feb 2021 13:36:03 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 1F46BFF80F for ; Tue, 2 Feb 2021 12:36:02 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Feb 2021 13:36:20 +0100 Message-Id: <20210202123620.45200-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: camera_device: Calculate MAX_JPEG_SIZE X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- 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 &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"; @@ -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. */