@@ -217,6 +217,7 @@ public:
private:
void generateIdmap();
+ bool validateRange(const ControlId *control, const ControlRange range);
ControlIdMap idmap_;
};
@@ -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";
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@jmondi.org> --- include/libcamera/controls.h | 1 + src/libcamera/controls.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-)