From patchwork Tue May 26 14:22:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3864 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E43560E08 for ; Tue, 26 May 2020 16:19:27 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from localhost.localdomain (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 1BE114000E; Tue, 26 May 2020 14:19:26 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 26 May 2020 16:22:34 +0200 Message-Id: <20200526142237.407557-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526142237.407557-1-jacopo@jmondi.org> References: <20200526142237.407557-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/8] android: camera_device: Calculate metadata 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: , X-List-Received-Date: Tue, 26 May 2020 14:19:27 -0000 As we move to have more and more dynamically generated static metadata entries, the size of the metadata buffer has to be calculated dynamically inspecting the information collected from the camera. Provide a method to perform metadata buffers size calculation and use it when generating camera static metadata. Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 42 ++++++++++++++++++++++++++++++----- src/android/camera_device.h | 2 ++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 534bfb1df1ef..6cc377820210 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -331,6 +331,40 @@ void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) /* * Return static information for the camera. */ +std::pair CameraDevice::calculateStaticMetadataSize() +{ + /* + * \todo Keep this in sync with the actual number of entries. + * Currently: 50 entries, 647 bytes of static metadata + */ + std::pair metadataSize; + metadataSize.first = 50; + metadataSize.second = 647; + + /* + * Calculate space occupation in bytes for dynamically built metadata + * entries. + */ + + /* std::forward_list does not provide a size() method :( */ + for (const auto &entry : streamConfigurations_) { + /* Just please the compiler, otherwise entry is not used. */ + switch (entry.androidScalerCode) { + default: + break; + } + + /* + * 4 32bits integers for ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS + * 1 32bits integer for ANDROID_SCALER_AVAILABLE_FORMATS + * 4 64bits integers for ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS + */ + metadataSize.second += 52; + } + + return metadataSize; +} + const camera_metadata_t *CameraDevice::getStaticMetadata() { if (staticMetadata_) @@ -341,12 +375,8 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() * example application, but a real camera implementation will require * more. */ - - /* - * \todo Keep this in sync with the actual number of entries. - * Currently: 50 entries, 666 bytes - */ - staticMetadata_ = new CameraMetadata(50, 700); + const std::pair sizes = calculateStaticMetadataSize(); + staticMetadata_ = new CameraMetadata(sizes.first, sizes.second); if (!staticMetadata_->isValid()) { LOG(HAL, Error) << "Failed to allocate static metadata"; delete staticMetadata_; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 95bd39f590ab..f22a6e3e6c28 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -69,6 +70,7 @@ private: }; int initializeFormats(); + std::pair calculateStaticMetadataSize(); void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream); std::unique_ptr getResultMetadata(int frame_number,