From patchwork Mon Jul 1 20:14:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1564 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0EFD461F5D for ; Mon, 1 Jul 2019 22:15:30 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A72F3524 for ; Mon, 1 Jul 2019 22:15:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562012129; bh=gzY+WTMrt6THi+MJDLwq3yf0fYjtI98VzNuphVal/Oo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kNFvimjHJMy/fVE+PI0u6vXHKhO6bgVSmc+3wn4NuMe8b5eUXIB5bwSiQh1UggjeQ ohmtIsRI3jG1GlFl+Aec1pKj1WBkbrj8UR5419gbMIz2s2kX0XzhmzHEzPf76u+wYy 03AspPhc3R0kgAG8IHrCrI6sBGfjo8kFhD6Wo1Pw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Jul 2019 23:14:56 +0300 Message-Id: <20190701201504.28487-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190701201504.28487-1-laurent.pinchart@ideasonboard.com> References: <20190701201504.28487-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 05/13] libcamera: controls: Extend ControlList to access controls by ID X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jul 2019 20:15:31 -0000 The ControlList class implements a map from control specifier to control ID. To avoid constant lookups of ControlInfo when using the class in the libcamera core or in pipeline handlers, the map uses ControlInfo pointers instead of ControlId values. This is however not very convenient for applications or pipeline handlers, as they would be forced to first look up the ControlInfo pointers for the controls they want to access. Facilitate ease of use of ControlLists by implementing an internal lookup of the ControlInfo from the controls provided by the Camera. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- Changes since v3: - Typo fixes --- include/libcamera/controls.h | 2 ++ src/libcamera/controls.cpp | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 18293c9462cf..fbb3a62274c6 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -117,11 +117,13 @@ public: const_iterator begin() const { return controls_.begin(); } const_iterator end() const { return controls_.end(); } + bool contains(ControlId id) const; bool contains(const ControlInfo *info) const; bool empty() const { return controls_.empty(); } std::size_t size() const { return controls_.size(); } void clear() { controls_.clear(); } + ControlValue &operator[](ControlId id); ControlValue &operator[](const ControlInfo *info) { return controls_[info]; } void update(const ControlList &list); diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index cd2cf337b379..42a2f8990bf6 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -10,6 +10,8 @@ #include #include +#include + #include "log.h" #include "utils.h" @@ -387,6 +389,30 @@ ControlList::ControlList(Camera *camera) * list */ +/** + * \brief Check if the list contains a control with the specified \a id + * \param[in] id The control ID + * + * The behaviour is undefined if the control \a id is not supported by the + * camera that the ControlList refers to. + * + * \return True if the list contains a matching control, false otherwise + */ +bool ControlList::contains(ControlId id) const +{ + const ControlInfoMap &controls = camera_->controls(); + const auto iter = controls.find(id); + if (iter == controls.end()) { + LOG(Controls, Error) + << "Camera " << camera_->name() + << " does not support control " << id; + + return false; + } + + return controls_.find(&iter->second) != controls_.end(); +} + /** * \brief Check if the list contains a control with the specified \a info * \param[in] info The control info @@ -414,6 +440,34 @@ bool ControlList::contains(const ControlInfo *info) const * \brief Removes all controls from the list */ +/** + * \brief Access or insert the control specified by \a id + * \param[in] id The control ID + * + * This method returns a reference to the control identified by \a id, inserting + * it in the list if the ID is not already present. + * + * The behaviour is undefined if the control \a id is not supported by the + * camera that the ControlList refers to. + * + * \return A reference to the value of the control identified by \a id + */ +ControlValue &ControlList::operator[](ControlId id) +{ + const ControlInfoMap &controls = camera_->controls(); + const auto iter = controls.find(id); + if (iter == controls.end()) { + LOG(Controls, Error) + << "Camera " << camera_->name() + << " does not support control " << id; + + static ControlValue empty; + return empty; + } + + return controls_[&iter->second]; +} + /** * \fn ControlList::operator[](const ControlInfo *info) * \brief Access or insert the control specified by \a info