[libcamera-devel] [PATCH 1/2] libcamera: controls: Return ControlValue reference from ControlList::set()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sun Apr 26 01:16:22 CEST 2020


It is useful for the caller of ControlList::set() to get a reference to
the ControlValue that stores the control in the control list, in order
to then modify that value directly. This allows creating an entry in
the ControlList and then reserving memory for the control when getting
V4L2 controls from a device. This is already possible by calling the
get() function right after set(), but results in two lookups. Extend the
id-based set() function to return the reference to the inserted
ControlValue to avoid the second lookup.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 include/libcamera/controls.h | 2 +-
 src/libcamera/controls.cpp   | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 80944efc133a..5a5cfc3e52ca 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -394,7 +394,7 @@ public:
 	}
 
 	const ControlValue &get(unsigned int id) const;
-	void set(unsigned int id, const ControlValue &value);
+	ControlValue &set(unsigned int id, const ControlValue &value);
 
 	const ControlInfoMap *infoMap() const { return infoMap_; }
 
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 08df7f29e938..12822e87a4d7 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -930,14 +930,17 @@ const ControlValue &ControlList::get(unsigned int id) const
  *
  * The behaviour is undefined if the control \a id is not supported by the
  * object that the list refers to.
+ *
+ * \return A reference to the ControlValue stored in the control list
  */
-void ControlList::set(unsigned int id, const ControlValue &value)
+ControlValue &ControlList::set(unsigned int id, const ControlValue &value)
 {
 	ControlValue *val = find(id);
 	if (!val)
-		return;
+		return *val;
 
 	*val = value;
+	return *val;
 }
 
 /**
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list