From patchwork Fri Jun 21 16:13:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1498 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C9D41615BC for ; Fri, 21 Jun 2019 18:14:07 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6BB3AF81; Fri, 21 Jun 2019 18:14:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1561133647; bh=0Bt6+LQA9Hoznez1ludzlC5gnVMhR5h+d8cIS0UFoSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YhTuT8EKbAlExdV440W74GYea345X+5G/S8hULdfLYGfu39iDzSIMPtc2Zl11Luao xVeU5J0XQbd6YVC8/adguRmaoW9mYKX5dvlp3+bJID0HiKJy1aMqrMBMPGfMhOweMj WAcgWiPa/NCmvTj5VBOWVShwmVH9qVRpkA7j+HVg= From: Kieran Bingham To: LibCamera Devel Date: Fri, 21 Jun 2019 17:13:57 +0100 Message-Id: <20190621161401.28337-6-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621161401.28337-1-kieran.bingham@ideasonboard.com> References: <20190621161401.28337-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 5/9] libcamera: Implement a ControlList 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: Fri, 21 Jun 2019 16:14:08 -0000 Define a ControlList which wraps the STL std::unordered_map to contain a list of associative pairs of ControlInfo and Value items. A ControlInfo (or represented by its ControlId) together with a Value provide a control item which can be interpreted by the internal IPA and PipelineHandler components. To pass a set of controls around, a ControlList can be added to a Request or stored locally to establish a set of default values for later reuse. Signed-off-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- include/libcamera/controls.h | 41 +++++++++++ src/libcamera/controls.cpp | 128 +++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 95198d41c4cf..5835b840a31b 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -4,6 +4,9 @@ * * controls.h - Control handling */ + +#include + #ifndef __LIBCAMERA_CONTROLS_H__ #define __LIBCAMERA_CONTROLS_H__ @@ -53,6 +56,44 @@ private: std::ostream &operator<<(std::ostream &stream, const ControlInfo &value); +class ControlList +{ +private: + struct ControlInfoHasher { + std::size_t operator()(const ControlInfo &ci) const + { + return std::hash()(ci.id()); + } + }; + + typedef std::unordered_map ControlListMap; + +public: + ControlList(); + + using iterator = ControlListMap::iterator; + using const_iterator = ControlListMap::const_iterator; + + iterator begin() { return controls_.begin(); } + iterator end() { return controls_.end(); } + const_iterator begin() const { return controls_.begin(); } + const_iterator end() const { return controls_.end(); } + + bool contains(ControlId id) const { return controls_.count(id); }; + bool empty() const { return controls_.empty(); } + size_t size() const { return controls_.size(); } + void reset() { controls_.clear(); } + + Value &operator[](ControlId id) { return controls_[id]; } + + void update(const ControlList &list); + void update(enum ControlId id, const Value &value); + void update(const ControlInfo &info, const Value &value); + +private: + ControlListMap controls_; +}; + } /* namespace libcamera */ #endif /* __LIBCAMERA_CONTROLS_H__ */ diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index b1be46ddb55e..7c55afffe4ca 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -157,4 +157,132 @@ std::ostream &operator<<(std::ostream &stream, const ControlInfo &info) return stream << info.toString(); } +/** + * \class ControlList + * \brief Associates a list of ControlIds with their values. + * + * The ControlList stores a pair of ControlInfo and Value classes as an + * unordered map. Entries can be updated using array syntax such as + * myControlList[MyControlId] = myValue; + * or + * myNewValue = myControlList[MyControlId]; + */ + +/** + * \brief Construct a ControlList + */ +ControlList::ControlList() +{ +} + +/** + * \typedef ControlList::iterator + * \brief Iterator for the controls contained within the list. + */ + +/** + * \typedef ControlList::const_iterator + * \brief Const iterator for the controls contained within the list. + */ + +/** + * \fn iterator ControlList::begin() + * \brief Retrieve an iterator to the first Control in the list + * \return An iterator to the first Control in the list + */ + +/** + * \fn iterator ControlList::end() + * \brief Retrieve an iterator to the next element after the last controls in + * the instance. + * \return An iterator to the element following the last control in the instance + */ + +/** + * \fn const_iterator ControlList::begin() const + * \brief Retrieve a const_iterator to the first Control in the list + * \return A const_iterator to the first Control in the list + */ + +/** + * \fn const_iterator ControlList::end() const + * \brief Retrieve a constant iterator pointing to an empty element after the + * \return A const iterator to the element following the last control in the + * instance + */ + +/** + * \fn ControlList::contains() + * \brief Identify if the List contains a control with the specified ControlId + * \return True if the list contains a matching control, false otherwise + */ + +/** + * \fn ControlList::empty() + * \brief Identify if the list is empty + * \return True if the list does not contain any control, false otherwise + */ + +/** + * \fn ControlList::size() + * \brief Retrieve the number of controls in the list + * \return The number of Control entries stored in the list + */ + +/** + * \fn ControlList::reset() + * \brief Removes all controls from the list + */ + +/** + * \fn ControlList::operator[]() + * \brief Access the control with the given Id + * \param id The id of the control to access + * \return The Value of the control with a ControlId of \a Id + */ + +/** + * \brief Update all Control values with the value from the given \a list + * \param list The list of controls to update or append to this list + * + * Update all controls in the ControlList, by the values given by \a list + * If the list already contains a control of this ID then it will be overwritten + */ +void ControlList::update(const ControlList &list) +{ + for (auto it : list) { + const ControlInfo &info = it.first; + const Value &value = it.second; + + controls_[info] = value; + } +} + +/** + * \brief Update a control value in the list + * \param id The ControlId of the control to update + * \param value The new value for the updated control + * + * Set the Control value in the list to the appropriate value + * If the list already contains a control of this ID then it will be overwritten + */ +void ControlList::update(enum ControlId id, const Value &value) +{ + controls_[id] = value; +} + +/** + * \brief Update a control value in the list. + * \param info The ControlInfo of the control to update + * \param value The new value for the updated control + * + * Set the Control value in the list to the appropriate value. + * If the list already contains a control of the Id matching the ControlInfo + * then it will be overwritten. + */ +void ControlList::update(const ControlInfo &info, const Value &value) +{ + controls_[info] = value; +} + } /* namespace libcamera */