From patchwork Mon Feb 22 13:21:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11364 X-Patchwork-Delegate: laurent.pinchart@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 1347FBD1F6 for ; Mon, 22 Feb 2021 13:21:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 97D6F68A15; Mon, 22 Feb 2021 14:21:53 +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="XgjcMlgo"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 17BBD68A07 for ; Mon, 22 Feb 2021 14:21:52 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7EA7E66; Mon, 22 Feb 2021 14:21:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1614000111; bh=WLY3uitlxZTUZJm9SbfUU+M646ZtUwuvzi6pM5/86AU=; h=From:To:Cc:Subject:Date:From; b=XgjcMlgoTaPzcuZhedquEtYklTECdT5BL57IqyNWrPU47p69OKPqNwnA5s1hqcdrT LmNj4YG+hWEVLoXnEqYfcCfVDympDbU8EkHOlDn1GFEwk6hOfKMw697om9td6tTtqt +ddaTFYqY/OAbwZGXx+vtKeXwOlEpNNqHZMUSIbI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 22 Feb 2021 15:21:21 +0200 Message-Id: <20210222132121.6728-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH/WIP] libcamera: controls: Add a function to merge two control lists 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 a new ControlList::merge() function to merge two control lists. The semantics is identical to std::unordered_map::merge(). This can be used by pipeline handlers to merge metadata they populate with metadata received from an IPA. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/controls.h | 2 ++ src/libcamera/controls.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) Hello, This may come handy for the IPU3 IPA. The patch hasn't been tested yet, I'm in particular not entirely sure of the idmap_ check. I've opted for an ASSERT() to be restrictive and catch potential issues, we may decide to relax the requirement (or handle it differently) if the assertion is triggered and the analysis of the problem shows that a different approach is required. diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 1a5690a5ccbe..16726ce9b1ed 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -363,7 +363,9 @@ public: bool empty() const { return controls_.empty(); } std::size_t size() const { return controls_.size(); } + void clear() { controls_.clear(); } + void merge(ControlList &source); bool contains(const ControlId &id) const; bool contains(unsigned int id) const; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index c58ed3946f3b..58555ea64c95 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -874,6 +874,26 @@ ControlList::ControlList(const ControlInfoMap &infoMap, ControlValidator *valida * \brief Removes all controls from the list */ +/** + * \brief Merge the \a source into the ControlList + * \param[in] source The ControlList to merge into this object + * + * Merging two control lists extracts elements from the \a source and insert + * them in *this. If the \a source contains elements whose key is already + * present in *this, then those elements are not extracted. The semantics is + * identical to std::unordered_map::merge() in that only internal pointers to + * nodes are updated, without copying or moving the elements. + * + * Only control lists created from the same ControlIdMap or ControlInfoMap may + * be merged. Attempting to do otherwise results in undefined behaviour. + */ +void ControlList::merge(ControlList &source) +{ + ASSERT(idmap_ == source.idmap_); + + controls_.merge(source.controls_); +} + /** * \brief Check if the list contains a control with the specified \a id * \param[in] id The control ID