From patchwork Fri Jul 30 10:35:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 13164 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 DE83BC322E for ; Fri, 30 Jul 2021 10:36:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A050E687BF; Fri, 30 Jul 2021 12:36:00 +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="WqH/O4DA"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9ECB4687BE for ; Fri, 30 Jul 2021 12:35:58 +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 4012989B; Fri, 30 Jul 2021 12:35:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627641358; bh=fFlmXdrPy8LXhMxW4a6aVXc1WwUaqzU53k/LeTpNzJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WqH/O4DAdxy2DwTJyPPxZ3EaAynUaQX8K/VednOqmgTcYeP9iI3dhEFUYvTF3SczR iZ7UDes6BUENneLvPi7R/abt5/zWeJXuFCNG/+6STvfYgB7hcgf3XdW9AH2kxQsHEe eBiEilshlezyAo3Nhkz5Sceni+Sx0XrFuJVZS4Vo= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Fri, 30 Jul 2021 19:35:33 +0900 Message-Id: <20210730103536.81117-7-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210730103536.81117-1-paul.elder@ideasonboard.com> References: <20210730103536.81117-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 6/9] 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. They both return the value that was set. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v6: - remove unused scalar-no-default version - remove explicit template parameters - infer the template parameters from the Control type Changes in v4: - remove vector copy from the vector setter 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 | 88 +++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp index b59a854f..fa701843 100644 --- a/src/android/camera_capabilities.cpp +++ b/src/android/camera_capabilities.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -125,6 +126,93 @@ hwLevelStrings = { { ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL, "EXTERNAL" }, }; +enum class ControlRange { + Min, + Def, + Max, +}; + +/** + * \brief Set android metadata from libcamera ControlInfo or a default value + * \tparam T Type of the control in libcamera + * \tparam U Type of the control in android + * \param[in] metadata Android metadata pack to add the control value to + * \param[in] tag Android metadata tag + * \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 +U setMetadata(CameraMetadata *metadata, uint32_t tag, + const ControlInfoMap &controlsInfo, const Control *control, + enum ControlRange controlRange, const U defaultValue) +{ + U ret = defaultValue; + + const auto &info = controlsInfo.find(reinterpret_cast(control)); + if (info != controlsInfo.end()) { + switch (controlRange) { + case ControlRange::Min: + ret = static_cast(info->second.min().get()); + break; + case ControlRange::Def: + ret = static_cast(info->second.def().get()); + break; + case ControlRange::Max: + ret = static_cast(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 libcamera + * \tparam U Type of the control in android + * \param[in] metadata Android metadata pack to add the control value to + * \param[in] tag Android metadata tag + * \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 Control *control, + const std::vector &defaultVector) +{ + const auto &info = controlsInfo.find(reinterpret_cast(control)); + if (info == controlsInfo.end()) { + metadata->addEntry(tag, defaultVector); + return defaultVector; + } + + std::vector ret(info->second.values().size()); + for (const auto &value : info->second.values()) + ret.push_back(static_cast(value.get())); + metadata->addEntry(tag, ret); + + return ret; +} + } /* namespace */ bool CameraCapabilities::validateManualSensorCapability()