From patchwork Thu Jun 4 13:35:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3916 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 828F5611AB for ; Thu, 4 Jun 2020 15:31:47 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.localdomain (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 10E3E1C0005; Thu, 4 Jun 2020 13:31:46 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Jun 2020 15:35:01 +0200 Message-Id: <20200604133503.14689-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604133503.14689-1-jacopo@jmondi.org> References: <20200604133503.14689-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/4] 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: Thu, 04 Jun 2020 13:31:48 -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 | 34 ++++++++++++++++++++++++++++------ src/android/camera_device.h | 2 ++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 0c462f53c9cc..1f438f0e265d 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -8,6 +8,7 @@ #include "camera_device.h" #include "camera_ops.h" +#include #include #include @@ -362,6 +363,29 @@ void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) callbacks_ = callbacks; } +std::tuple CameraDevice::calculateStaticMetadataSize() +{ + /* + * \todo Keep this in sync with the actual number of entries. + * Currently: 50 entries, 647 bytes of static metadata + */ + uint32_t numEntries = 50; + uint32_t byteSize = 647; + + /* + * Calculate space occupation in bytes for dynamically built metadata + * entries. + * + * Each stream configuration entry requires 52 bytes: + * 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 + */ + byteSize += streamConfigurations_.size() * 52; + + return { numEntries, byteSize }; +} + /* * Return static information for the camera. */ @@ -375,12 +399,10 @@ 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); + uint32_t numEntries; + uint32_t byteSize; + std::tie(numEntries, byteSize) = calculateStaticMetadataSize(); + staticMetadata_ = new CameraMetadata(numEntries, byteSize); 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 d31b7233e795..18a5f77f9ce5 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -68,6 +69,7 @@ private: }; int initializeFormats(); + std::tuple 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,