[libcamera-devel,v3,01/16] libcamera: controls: Add a function to merge two control lists
diff mbox series

Message ID 20210421160319.42251-2-jacopo@jmondi.org
State Superseded
Delegated to: Jacopo Mondi
Headers show
Series
  • Support SensorTimestamp metadata
Related show

Commit Message

Jacopo Mondi April 21, 2021, 4:03 p.m. UTC
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 include/libcamera/controls.h |  2 ++
 src/libcamera/controls.cpp   | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

Comments

Hirokazu Honda April 22, 2021, 3:17 a.m. UTC | #1
Hi Jacopo, thank you for the patch.

On Thu, Apr 22, 2021 at 1:02 AM Jacopo Mondi <jacopo@jmondi.org> wrote:
>
> From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
> 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 <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  include/libcamera/controls.h |  2 ++
>  src/libcamera/controls.cpp   | 20 ++++++++++++++++++++
>  2 files changed, 22 insertions(+)
>
> 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
> --
> 2.31.1

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>

>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch
diff mbox series

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