From 0aa8e0977591ed0868262ca910ab12c46a46d39c Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Wed, 4 Mar 2020 14:14:36 +0100 Subject: libcamera: v4l2_device: Support writing array U8 controls Add support to write array controls of type V4L2_CTRL_TYPE_U8. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/v4l2_device.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 7eded67c..2139e98b 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(); break; + + case ControlTypeByte: { + if (!value.isArray()) { + LOG(V4L2, Error) + << "Control " << utils::hex(id) + << " requires an array value"; + return -EINVAL; + } + + Span 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(); break; } @@ -414,6 +427,14 @@ void V4L2Device::updateControls(ControlList *ctrls, case ControlTypeInteger64: value.set(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 -- cgit v1.2.1