[libcamera-devel,v2,4/7] libcamera: v4l2_device: Support reading U8 array controls

Message ID 20200321003640.2156-5-laurent.pinchart@ideasonboard.com
State Accepted
Commit 3786b6c84bbfa91864bfbd16fa8cad575e4247e7
Headers show
Series
  • Add support for V4L2 array controls
Related show

Commit Message

Laurent Pinchart March 21, 2020, 12:36 a.m. UTC
From: Jacopo Mondi <jacopo@jmondi.org>

Add support to retrieve the value of array controls of type
V4L2_CTRL_TYPE_U8.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v1:

- Use writable ControlValue storage directly for arrays in getControls()
- Handle the control type more generically
- Improve error message for unsupported types
- Rename ctrlsInfo_ to controlInfo_
---
 src/libcamera/v4l2_device.cpp | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

Patch

diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 2139e98bc9b8..3c91eb3f9f97 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -176,7 +176,7 @@  int V4L2Device::getControls(ControlList *ctrls)
 	memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));
 
 	unsigned int i = 0;
-	for (const auto &ctrl : *ctrls) {
+	for (auto &ctrl : *ctrls) {
 		unsigned int id = ctrl.first;
 		const auto iter = controls_.find(id);
 		if (iter == controls_.end()) {
@@ -185,6 +185,31 @@  int V4L2Device::getControls(ControlList *ctrls)
 			return -EINVAL;
 		}
 
+		const struct v4l2_query_ext_ctrl &info = controlInfo_[id];
+		ControlValue &value = ctrl.second;
+
+		if (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {
+			ControlType type;
+
+			switch (info.type) {
+			case V4L2_CTRL_TYPE_U8:
+				type = ControlTypeByte;
+				break;
+
+			default:
+				LOG(V4L2, Error)
+					<< "Unsupported payload control type "
+					<< info.type;
+				return -EINVAL;
+			}
+
+			value.reserve(type, true, info.elems);
+			Span<uint8_t> data = value.data();
+
+			v4l2Ctrls[i].p_u8 = data.data();
+			v4l2Ctrls[i].size = data.size();
+		}
+
 		v4l2Ctrls[i].id = id;
 		i++;
 	}