[libcamera-devel] [PATCH v2 3/4] libcamera: controls: Construct Span with size for array controls

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Oct 7 01:07:46 CEST 2022


The ControlList::set() function overload used for array controls
constructs a Span from an initializer list. It doesn't specify the Span
size explicitly, which results in a dynamic extent Span being
constructed. That causes a compilation failure for fixed-size array
controls, as they are defined as Control<T> with T being a fixed-extent
Span, and conversion from a dynamic-extent to fixed-extent Span when
calling ControlValue::set() can't be implicit.

Fix this by constructing the Span using the size of the control, which
resolves to a fixed-extent and dynamic-extent Span for fixed-size and
dynamic-size array controls respectively. The ControlList::set()
function that takes an initializer list can then be used for fixed-size
array controls.

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

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 38d0a3e8360a..cf94205577a5 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -393,14 +393,14 @@ public:
 		val->set<T>(value);
 	}
 
-	template<typename T, typename V>
-	void set(const Control<T> &ctrl, const std::initializer_list<V> &value)
+	template<typename T, typename V, size_t Size>
+	void set(const Control<Span<T, Size>> &ctrl, const std::initializer_list<V> &value)
 	{
 		ControlValue *val = find(ctrl.id());
 		if (!val)
 			return;
 
-		val->set<T>(Span<const typename std::remove_cv_t<V>>{ value.begin(), value.size() });
+		val->set(Span<const typename std::remove_cv_t<V>, Size>{ value.begin(), value.size() });
 	}
 
 	const ControlValue &get(unsigned int id) const;
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index bc3db4f69388..6dbf9b348709 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -970,7 +970,7 @@ bool ControlList::contains(unsigned int id) const
  */
 
 /**
- * \fn ControlList::set(const Control<T> &ctrl, const std::initializer_list<V> &value)
+ * \fn ControlList::set(const Control<Span<T, Size>> &ctrl, const std::initializer_list<V> &value)
  * \copydoc ControlList::set(const Control<T> &ctrl, const V &value)
  */
 
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list