[libcamera-devel] [PATCH v2 3/7] libcamera: v4l2_device: Support writing array U8 controls
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Sat Mar 21 01:36:36 CET 2020
From: Jacopo Mondi <jacopo at jmondi.org>
Add support to write array controls of type V4L2_CTRL_TYPE_U8.
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
Changes since v1:
- Avoid copy of data in updateControls()
- Use writable ControlValue storage directly for arrays in setControls()
- Return an error when setting a control with a non-array value
---
src/libcamera/v4l2_device.cpp | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 7eded67cb47e..2139e98bc9b8 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -250,7 +250,7 @@ int V4L2Device::setControls(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()) {
@@ -262,16 +262,29 @@ int V4L2Device::setControls(ControlList *ctrls)
v4l2Ctrls[i].id = id;
/* Set the v4l2_ext_control value for the write operation. */
- const ControlValue &value = ctrl.second;
+ ControlValue &value = ctrl.second;
switch (iter->first->type()) {
case ControlTypeInteger64:
v4l2Ctrls[i].value64 = value.get<int64_t>();
break;
+
+ case ControlTypeByte: {
+ if (!value.isArray()) {
+ LOG(V4L2, Error)
+ << "Control " << utils::hex(id)
+ << " requires an array value";
+ return -EINVAL;
+ }
+
+ Span<uint8_t> data = value.data();
+ v4l2Ctrls[i].p_u8 = data.data();
+ v4l2Ctrls[i].size = data.size();
+
+ break;
+ }
+
default:
- /*
- * \todo To be changed when support for string and
- * compound controls will be added.
- */
+ /* \todo To be changed to support strings. */
v4l2Ctrls[i].value = value.get<int32_t>();
break;
}
@@ -414,6 +427,14 @@ void V4L2Device::updateControls(ControlList *ctrls,
case ControlTypeInteger64:
value.set<int64_t>(v4l2Ctrl->value64);
break;
+
+ case ControlTypeByte:
+ /*
+ * No action required, the VIDIOC_[GS]_EXT_CTRLS ioctl
+ * accessed the ControlValue storage directly.
+ */
+ break;
+
default:
/*
* \todo To be changed when support for string and
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list