[{"id":5082,"web_url":"https://patchwork.libcamera.org/comment/5082/","msgid":"<20200606000344.GV26752@pendragon.ideasonboard.com>","date":"2020-06-06T00:03:44","subject":"Re: [libcamera-devel] [PATCH v3 2/8] android: camera_device:\n\tCalculate metadata size","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Fri, Jun 05, 2020 at 04:09:56PM +0200, Jacopo Mondi wrote:\n> As we move to have more and more dynamically generated static metadata\n> entries, the size of the metadata buffer has to be calculated\n> dynamically inspecting the information collected from the camera.\n> \n> Provide a method to perform metadata buffers size calculation and\n> use it when generating camera static metadata.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/android/camera_device.cpp | 34 ++++++++++++++++++++++++++++------\n>  src/android/camera_device.h   |  2 ++\n>  2 files changed, 30 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index cb9e4a6bc15b..c65295a32f3f 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -8,6 +8,7 @@\n>  #include \"camera_device.h\"\n>  #include \"camera_ops.h\"\n>  \n> +#include <tuple>\n>  #include <vector>\n>  \n>  #include <libcamera/controls.h>\n> @@ -368,6 +369,29 @@ void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks)\n>  \tcallbacks_ = callbacks;\n>  }\n>  \n> +std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize()\n> +{\n> +\t/*\n> +\t * \\todo Keep this in sync with the actual number of entries.\n> +\t * Currently: 50 entries, 647 bytes of static metadata\n> +\t */\n> +\tuint32_t numEntries = 50;\n> +\tuint32_t byteSize = 647;\n> +\n> +\t/*\n> +\t * Calculate space occupation in bytes for dynamically built metadata\n> +\t * entries.\n> +\t *\n> +\t * Each stream configuration entry requires 52 bytes:\n> +\t * 4 32bits integers for ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS\n> +\t * 1 32bits integer for ANDROID_SCALER_AVAILABLE_FORMATS\n> +\t * 4 64bits integers for ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS\n> +\t */\n> +\tbyteSize += streamConfigurations_.size() * 52;\n> +\n> +\treturn { numEntries, byteSize };\n> +}\n> +\n>  /*\n>   * Return static information for the camera.\n>   */\n> @@ -381,12 +405,10 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n>  \t * example application, but a real camera implementation will require\n>  \t * more.\n>  \t */\n> -\n> -\t/*\n> -\t * \\todo Keep this in sync with the actual number of entries.\n> -\t * Currently: 50 entries, 666 bytes\n> -\t */\n> -\tstaticMetadata_ = new CameraMetadata(50, 700);\n> +\tuint32_t numEntries;\n> +\tuint32_t byteSize;\n> +\tstd::tie(numEntries, byteSize) = calculateStaticMetadataSize();\n> +\tstaticMetadata_ = new CameraMetadata(numEntries, byteSize);\n>  \tif (!staticMetadata_->isValid()) {\n>  \t\tLOG(HAL, Error) << \"Failed to allocate static metadata\";\n>  \t\tdelete staticMetadata_;\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index 4e8911da5770..ed11410a5577 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -9,6 +9,7 @@\n>  \n>  #include <map>\n>  #include <memory>\n> +#include <tuple>\n>  #include <vector>\n>  \n>  #include <hardware/camera3.h>\n> @@ -68,6 +69,7 @@ private:\n>  \t};\n>  \n>  \tint initializeStreamConfigurations();\n> +\tstd::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();\n>  \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);\n>  \tvoid notifyError(uint32_t frameNumber, camera3_stream_t *stream);\n>  \tstd::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 01FAF600F7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  6 Jun 2020 02:04:04 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0D0C427C;\n\tSat,  6 Jun 2020 02:04:03 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"LMmDlO/K\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1591401844;\n\tbh=/i9Dg7wcA/WjqamyJ6zOMyblOExyhddWnq9m932rT0A=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=LMmDlO/K0wgXu59dyJDGQquRayBthyeevb9G0oZjcGCYRS07/7V4qT/YA0TtjLsZF\n\tKE75FJo8TV4fHTT27xvjf+sqCrta2e8FTIFy9MS6cc/kAf61rnyCHaiFxOdT9+h8sG\n\tI6YCI4l9VsBnhjC8kp0AIUgaPvzHMU6R4KjWPUFA=","Date":"Sat, 6 Jun 2020 03:03:44 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200606000344.GV26752@pendragon.ideasonboard.com>","References":"<20200605141002.49119-1-jacopo@jmondi.org>\n\t<20200605141002.49119-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200605141002.49119-3-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v3 2/8] android: camera_device:\n\tCalculate metadata size","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 06 Jun 2020 00:04:05 -0000"}}]