[libcamera-devel] [PATCH 19/23] libcamera: controls: Validate compound controls range

Jacopo Mondi jacopo at jmondi.org
Mon Jan 13 17:42:41 CET 2020


The type of a ControlRnge associated with a Control<> is different
from the type of the Control<> itself if the control is a compound.

Add a function to help validation of the two types during ControlInfoMap
idmap generation.

Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 include/libcamera/controls.h |  1 +
 src/libcamera/controls.cpp   | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 9343a947764b..a3ac2b8c5447 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -217,6 +217,7 @@ public:
 
 private:
 	void generateIdmap();
+	bool validateRange(const ControlId *control, const ControlRange range);
 
 	ControlIdMap idmap_;
 };
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 750c36bd011e..71075ade4577 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -940,6 +940,36 @@ ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const
 	return find(iter->second);
 }
 
+bool ControlInfoMap::validateRange(const ControlId *control,
+				   const ControlRange range)
+{
+	ControlType controlType = control->type();
+	ControlType rangeType = range.min().type();
+
+	/*
+	 * Validate the control type against its associated range type,
+	 * regardless it being a compound control or not.
+	 */
+	switch (controlType) {
+	case ControlTypeBool:
+	case ControlTypeCompoundBool:
+		return rangeType == ControlTypeBool;
+	case ControlTypeInteger32:
+	case ControlTypeCompoundInt32:
+		return (rangeType == ControlTypeInteger32 ||
+			rangeType == ControlTypeInteger64);
+	case ControlTypeInteger64:
+	case ControlTypeCompoundInt64:
+		return (rangeType == ControlTypeInteger64 ||
+			rangeType == ControlTypeInteger32);
+	case ControlTypeFloat:
+	case ControlTypeCompoundFloat:
+		return rangeType == ControlTypeFloat;
+	default:
+		return false;
+	}
+}
+
 /**
  * \fn const ControlIdMap &ControlInfoMap::idmap() const
  * \brief Retrieve the ControlId map
@@ -956,7 +986,7 @@ void ControlInfoMap::generateIdmap()
 	idmap_.clear();
 
 	for (const auto &ctrl : *this) {
-		if (ctrl.first->type() != ctrl.second.min().type()) {
+		if (!validateRange(ctrl.first, ctrl.second)) {
 			LOG(Controls, Error)
 				<< "Control " << utils::hex(ctrl.first->id())
 				<< " type and range type mismatch";
-- 
2.24.0



More information about the libcamera-devel mailing list