From a5f8ab82dfa3bb6531df0f9d7a4c3b4c8126a8a9 Mon Sep 17 00:00:00 2001 From: Hirokazu Honda Date: Mon, 10 May 2021 14:42:42 +0900 Subject: libcamera: V4L2Control: remove V4L2Control classes V4L2ControlId and V4L2ControlInfo are just convenience classes to create ControlId and ControlInfo from v4l2_query_ext_control. Therefore, there is no need of being a class. It is used only from V4L2Device. This removes the classes and put the equivalent functions of creating ControlId and ControlInfo in v4l2_device.cpp. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- src/libcamera/v4l2_device.cpp | 74 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) (limited to 'src/libcamera/v4l2_device.cpp') diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 515cbdfe..caafbc2d 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -20,7 +20,6 @@ #include "libcamera/internal/log.h" #include "libcamera/internal/sysfs.h" #include "libcamera/internal/utils.h" -#include "libcamera/internal/v4l2_controls.h" /** * \file v4l2_device.h @@ -31,6 +30,73 @@ namespace libcamera { LOG_DEFINE_CATEGORY(V4L2) +namespace { + +ControlType v4l2CtrlType(uint32_t ctrlType) +{ + switch (ctrlType) { + case V4L2_CTRL_TYPE_U8: + return ControlTypeByte; + + case V4L2_CTRL_TYPE_BOOLEAN: + return ControlTypeBool; + + case V4L2_CTRL_TYPE_INTEGER: + return ControlTypeInteger32; + + case V4L2_CTRL_TYPE_INTEGER64: + return ControlTypeInteger64; + + case V4L2_CTRL_TYPE_MENU: + case V4L2_CTRL_TYPE_BUTTON: + case V4L2_CTRL_TYPE_BITMASK: + case V4L2_CTRL_TYPE_INTEGER_MENU: + /* + * More precise types may be needed, for now use a 32-bit + * integer type. + */ + return ControlTypeInteger32; + + default: + return ControlTypeNone; + } +} + +std::unique_ptr v4l2ControlId(const v4l2_query_ext_ctrl &ctrl) +{ + const size_t len = strnlen(ctrl.name, sizeof(ctrl.name)); + const std::string name(static_cast(ctrl.name), len); + const ControlType type = v4l2CtrlType(ctrl.type); + + return std::make_unique(ctrl.id, name, type); +} + +ControlInfo v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl) +{ + switch (ctrl.type) { + case V4L2_CTRL_TYPE_U8: + return ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value)); + + case V4L2_CTRL_TYPE_BOOLEAN: + return ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value)); + + case V4L2_CTRL_TYPE_INTEGER64: + return ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value)); + + default: + return ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value)); + } +} +} /* namespace */ + /** * \class V4L2Device * \brief Base class for V4L2VideoDevice and V4L2Subdevice @@ -502,10 +568,10 @@ void V4L2Device::listControls() continue; } - controlIds_.emplace_back(std::make_unique(ctrl)); + controlIds_.emplace_back(v4l2ControlId(ctrl)); controlInfo_.emplace(ctrl.id, ctrl); - ctrls.emplace(controlIds_.back().get(), V4L2ControlInfo(ctrl)); + ctrls.emplace(controlIds_.back().get(), v4l2ControlInfo(ctrl)); } controls_ = std::move(ctrls); @@ -544,7 +610,7 @@ void V4L2Device::updateControlInfo() continue; } - info = V4L2ControlInfo(ctrl); + info = v4l2ControlInfo(ctrl); } } -- cgit v1.2.1