From patchwork Mon Dec 20 23:26:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 15174 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 9AF7ABE080 for ; Mon, 20 Dec 2021 23:26:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 53BAF608E7; Tue, 21 Dec 2021 00:26:51 +0100 (CET) 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="ZwI9Bu0g"; 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 89482608F9 for ; Tue, 21 Dec 2021 00:26:47 +0100 (CET) Received: from pyrite.mediacom.info (unknown [IPv6:2604:2d80:ad90:fb00:96fd:8874:873:6c16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7640EFD7; Tue, 21 Dec 2021 00:26:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640042807; bh=EWvzbnAHQgmUJOa2+xZog7a/Z1C7NG0LPoqsKdrDNVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZwI9Bu0gJyNaVDn6AeSOq+Itprzb3o/5ZBReXwF44vonsu41c9v1FTdcuYP9s3t6Z nKZt6FBRNXisWjnhX4i8+9f+dweJfp/kkCZ3nAg31Rve49gk9dUHicymkqWymaWkFV i/YJfdEKnNKl+sr0t/EAhrdawphi6sPgOkhPjHW8= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Dec 2021 17:26:26 -0600 Message-Id: <20211220232629.1485890-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211220232629.1485890-1-paul.elder@ideasonboard.com> References: <20211220232629.1485890-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/6] android: camera_metadata: Add appendEntry helper 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 appendEntry() helper, that automatically detects if updateEntry() or addEntry() should be used. Note that updateEntry() will fail if the entry was not yet added, and addEntry() will fail is the entry was already added. They are silent failures that cause unexpected values to find their way into the android metadata instance. Previously this helper was not necessary, as (with respect to the current use case) the preview template generator would always add a key so the other template generators that used the preview template as boilerplate could reliably use updateEntry(). The preview template generator will soon decide based on capabilities whether or not to add keys, so the other template generators need a helper to decide whether to use updateEntry() or addEntry(). For now only implement it for enums and arithmetic values, as they will mainly be used in populating templates. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- Changes in v2: - expand on correctness of updateEntry() vs addEntry(), and the rationale for the patch --- src/android/camera_metadata.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h index e70f60af..f3b7c91e 100644 --- a/src/android/camera_metadata.h +++ b/src/android/camera_metadata.h @@ -33,6 +33,17 @@ public: bool hasEntry(uint32_t tag) const; + template || + std::is_enum_v> * = nullptr> + bool appendEntry(uint32_t tag, const T &data) + { + if (hasEntry(tag)) + return updateEntry(tag, &data, 1, sizeof(T)); + else + return addEntry(tag, &data, 1, sizeof(T)); + } + template || std::is_enum_v> * = nullptr>