[v1,1/4] libcamera: v4l2_device: Ensure consistent control types
diff mbox series

Message ID 20260325092659.79453-1-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v1,1/4] libcamera: v4l2_device: Ensure consistent control types
Related show

Commit Message

Barnabás Pőcze March 25, 2026, 9:26 a.m. UTC
While `setControls()` uses the specific types, `updateControls()` converts
everything to 32-bit integers (except 64-bit integers). This causes, for
example, that a 16-bit unsigned integer is retrieved as `int32_t` even
though there is a specific libcamera control type for it. What's even
more surprising is that setting such a control requires a `ControlValue`
with `uint16_t`, but when `setControls()` updates the list to contain
the actually applied values, it will now have type `int32_t`.

So make sure that `updateControls()` uses the appropriate type.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/libcamera/v4l2_device.cpp | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 67bbaa037..e0099cb7a 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -823,19 +823,26 @@  void V4L2Device::updateControls(ControlList *ctrls,
 		ASSERT(iter != controls_.end());
 
 		switch (iter->first->type()) {
+		case ControlTypeByte:
+			value.set<uint8_t>(v4l2Ctrl.value);
+			break;
+		case ControlTypeUnsigned16:
+			value.set<uint16_t>(v4l2Ctrl.value);
+			break;
+		case ControlTypeInteger32:
+			value.set<int32_t>(v4l2Ctrl.value);
+			break;
+		case ControlTypeUnsigned32:
+			value.set<uint32_t>(v4l2Ctrl.value);
+			break;
 		case ControlTypeInteger64:
 			value.set<int64_t>(v4l2Ctrl.value64);
 			break;
-
 		default:
-			/*
-			 * Note: this catches the ControlTypeInteger32 case.
-			 *
-			 * \todo To be changed when support for string controls
-			 * will be added.
-			 */
-			value.set<int32_t>(v4l2Ctrl.value);
-			break;
+			LOG(V4L2, Error)
+				<< "Control " << utils::hex(id)
+				<< " has unsupported type";
+			continue;
 		}
 
 		ctrls->set(id, value);