From d711a4c015e74c7a77cfeba17b621909385f4494 Mon Sep 17 00:00:00 2001 From: Yudhistira Erlandinata Date: Tue, 29 Oct 2024 16:07:13 +0000 Subject: libcamera: Extend u16 control type V4L2 Controls support a wide variety of types not yet supported by the ControlValue type system. Extend the libcamera ControlValue types to support an explicit 16 bit unsigned integer type, and map that to the corresponding V4L2_CTRL_TYPE_U16 type within the v4l2_device support class. It's used on some camera metadata that is of length 16-bits, for example JPEG metadata headers. Signed-off-by: Yudhistira Erlandinata Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham Signed-off-by: Kieran Bingham --- src/libcamera/controls.cpp | 8 ++++++++ src/libcamera/v4l2_device.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'src') diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index b28a5f46..65eeef2d 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -54,6 +54,7 @@ static constexpr size_t ControlValueSize[] = { [ControlTypeNone] = 0, [ControlTypeBool] = sizeof(bool), [ControlTypeByte] = sizeof(uint8_t), + [ControlTypeUnsigned16] = sizeof(uint16_t), [ControlTypeUnsigned32] = sizeof(uint32_t), [ControlTypeInteger32] = sizeof(int32_t), [ControlTypeInteger64] = sizeof(int64_t), @@ -75,6 +76,8 @@ static constexpr size_t ControlValueSize[] = { * The control stores a boolean value * \var ControlTypeByte * The control stores a byte value as an unsigned 8-bit integer + * \var ControlTypeUnsigned16 + * The control stores an unsigned 16-bit integer value * \var ControlTypeUnsigned32 * The control stores an unsigned 32-bit integer value * \var ControlTypeInteger32 @@ -233,6 +236,11 @@ std::string ControlValue::toString() const str += std::to_string(*value); break; } + case ControlTypeUnsigned16: { + const uint16_t *value = reinterpret_cast(data); + str += std::to_string(*value); + break; + } case ControlTypeUnsigned32: { const uint32_t *value = reinterpret_cast(data); str += std::to_string(*value); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 8276d118..664b74af 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -216,6 +216,13 @@ ControlList V4L2Device::getControls(const std::vector &ids) v4l2Ctrl.p_u8 = data.data(); break; + case V4L2_CTRL_TYPE_U16: + type = ControlTypeUnsigned16; + value.reserve(type, true, info.elems); + data = value.data(); + v4l2Ctrl.p_u16 = reinterpret_cast(data.data()); + break; + case V4L2_CTRL_TYPE_U32: type = ControlTypeUnsigned32; value.reserve(type, true, info.elems); @@ -307,6 +314,18 @@ int V4L2Device::setControls(ControlList *ctrls) /* Set the v4l2_ext_control value for the write operation. */ ControlValue &value = ctrl->second; switch (iter->first->type()) { + case ControlTypeUnsigned16: { + if (value.isArray()) { + Span data = value.data(); + v4l2Ctrl.p_u16 = reinterpret_cast(data.data()); + v4l2Ctrl.size = data.size(); + } else { + v4l2Ctrl.value = value.get(); + } + + break; + } + case ControlTypeUnsigned32: { if (value.isArray()) { Span data = value.data(); @@ -508,6 +527,9 @@ ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType) case V4L2_CTRL_TYPE_BOOLEAN: return ControlTypeBool; + case V4L2_CTRL_TYPE_U16: + return ControlTypeUnsigned16; + case V4L2_CTRL_TYPE_U32: return ControlTypeUnsigned32; @@ -559,6 +581,11 @@ std::optional V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl static_cast(ctrl.maximum), static_cast(ctrl.default_value)); + case V4L2_CTRL_TYPE_U16: + return ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value)); + case V4L2_CTRL_TYPE_U32: return ControlInfo(static_cast(ctrl.minimum), static_cast(ctrl.maximum), @@ -650,6 +677,7 @@ void V4L2Device::listControls() case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_U8: + case V4L2_CTRL_TYPE_U16: case V4L2_CTRL_TYPE_U32: break; /* \todo Support other control types. */ -- cgit v1.2.1