From patchwork Fri Jul 2 10:37:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 12768 X-Patchwork-Delegate: paul.elder@ideasonboard.com 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 1CAEAC3222 for ; Fri, 2 Jul 2021 10:38:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CDCFF684F4; Fri, 2 Jul 2021 12:38:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="L/3gy9Ex"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 66CFB684F4 for ; Fri, 2 Jul 2021 12:38:18 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E2B854AB; Fri, 2 Jul 2021 12:38:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1625222298; bh=M/XyidS39Eq3xrd8+tOjw8pyKGsMgn/xbrW83OXSV4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/3gy9ExTypbgjgvqS0N1C4/M3TPVSjZNTCZ35stPDrlkhoiuoocLt3rDZMAuo23o ohWh8XdAmSg9Mqzo7p5hcFKWnlFvctAR0FIhWnuStHm7H+kN83H9sjkdIALBAezYs0 3X9dyAZsmWbstXrz56d6TgQ3/q6KlS/jwGCA+XHk= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Fri, 2 Jul 2021 19:37:47 +0900 Message-Id: <20210702103800.41291-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210702103800.41291-1-paul.elder@ideasonboard.com> References: <20210702103800.41291-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v3 03/16] android: Add helpers for setting android metadata from libcamera controls 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" Add helpers for setting android metadata from libcamera controls. There are two versions, for scalars and collections, both of which take a default value to fill in the android control if the libcamera control is not found. A version for scalars exists for no default, to not set the android control at all if it is not found in libcamera. The functions take two template parameters, the first for the android type, and the second for the libcamera type of the control. They can be different, for example, if the former is an enum and the latter is a boolean, or if the former is an enum (uint8_t) and the latter is an enum (int32_t). The versions that take a default value return the value that was set in the android metadata. Signed-off-by: Paul Elder --- Changes in v3: - setMetadata for collection only works with vectors - change enum to enum class - add two template parameters for android type and libcamera type - add docs New in v2 TODO: make ControlList versions so that we can use them in result metadata --- src/android/camera_capabilities.cpp | 137 ++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp index 54bd71da..1d4c44ce 100644 --- a/src/android/camera_capabilities.cpp +++ b/src/android/camera_capabilities.cpp @@ -124,6 +124,143 @@ hwLevelStrings = { { ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL, "EXTERNAL" }, }; +enum class ControlRange { + Min, + Def, + Max, +}; + +/** + * \brief Set android metadata from libcamera ControlInfo + * \tparam T Type of the control in android + * \tparam V Type of the control in libcamera + * \param[in] metadata Android metadata to add the control value to + * \param[in] tag Android metadata tag to add + * \param[in] controlsInfo libcamera ControlInfoMap from which to find the control info + * \param[in] control libcamera ControlId to find from \a controlsInfo + * \param[in] controlRange Whether to use the min, def, or max value from the control info + * + * Set the android metadata entry in \a metadata with tag \a tag based on the + * control info found for the libcamera control \a control in the libcamera + * ControlInfoMap \a controlsInfo. If no libcamera ControlInfo is found, then + * the function returns without modifying anything. + * + * This function is for scalar values. + */ +template> * = nullptr, + typename V> +void setMetadata(CameraMetadata *metadata, uint32_t tag, + const ControlInfoMap &controlsInfo, const ControlId *control, + enum ControlRange controlRange) +{ + const auto &info = controlsInfo.find(control); + if (info == controlsInfo.end()) + return; + + T ret; + switch (controlRange) { + case ControlRange::Min: + ret = info->second.min().get(); + break; + case ControlRange::Def: + ret = info->second.def().get(); + break; + case ControlRange::Max: + ret = info->second.max().get(); + break; + } + + metadata->addEntry(tag, ret); + return; +} + +/** + * \brief Set android metadata from libcamera ControlInfo or a default value + * \tparam T Type of the control in android + * \tparam U Type of the control in libcamera + * \param[in] metadata Android metadata to add the control value to + * \param[in] tag Android metadata tag to add + * \param[in] controlsInfo libcamera ControlInfoMap from which to find the control info + * \param[in] control libcamera ControlId to find from \a controlsInfo + * \param[in] controlRange Whether to use the min, def, or max value from the control info + * \param[in] defaultValue The value to set in \a metadata if \a control is not found + * + * Set the android metadata entry in \a metadata with tag \a tag based on the + * control info found for the libcamera control \a control in the libcamera + * ControlInfoMap \a controlsInfo. If no libcamera ControlInfo is found, then + * the android metadata entry is set to \a defaultValue. + * + * This function is for scalar values. + */ +template> * = nullptr> +T setMetadata(CameraMetadata *metadata, uint32_t tag, + const ControlInfoMap &controlsInfo, const ControlId *control, + enum ControlRange controlRange, const V defaultValue) +{ + T ret = defaultValue; + + const auto &info = controlsInfo.find(control); + if (info != controlsInfo.end()) { + switch (controlRange) { + case ControlRange::Min: + ret = info->second.min().get(); + break; + case ControlRange::Def: + ret = info->second.def().get(); + break; + case ControlRange::Max: + ret = info->second.max().get(); + break; + } + } + + metadata->addEntry(tag, ret); + return ret; +} + +/** + * \brief Set android metadata from libcamera ControlInfo or a default value + * \tparam T Type of the control in android + * \tparam V Type of the control in libcamera + * \param[in] metadata Android metadata to add the control value to + * \param[in] tag Android metadata tag to add + * \param[in] controlsInfo libcamera ControlInfoMap from which to find the control info + * \param[in] control libcamera ControlId to find from \a controlsInfo + * \param[in] defaultVector The value to set in \a metadata if \a control is not found + * + * Set the android metadata entry in \a metadata with tag \a tag based on the + * control info found for the libcamera control \a control in the libcamera + * ControlInfoMap \a controlsInfo. If no libcamera ControlInfo is found, then + * the android metadata entry is set to \a defaultVector. + * + * This function is for vector values. + */ +template +std::vector setMetadata(CameraMetadata *metadata, uint32_t tag, + const ControlInfoMap &controlsInfo, + const ControlId *control, + const std::vector &defaultVector) +{ + std::vector ret = {}; + + const auto &info = controlsInfo.find(control); + if (info != controlsInfo.end()) { + ret.reserve(info->second.values().size()); + for (const auto &value : info->second.values()) + ret.push_back(value.get()); + } else { + ret = defaultVector; + } + + metadata->addEntry(tag, ret); + return ret; +} + } /* namespace */ int CameraCapabilities::initialize(std::shared_ptr camera,