summaryrefslogtreecommitdiff
path: root/src/libcamera/v4l2_device.cpp
diff options
context:
space:
mode:
authorHirokazu Honda <hiroh@chromium.org>2021-05-10 14:42:42 +0900
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-05-24 07:21:02 +0300
commita5f8ab82dfa3bb6531df0f9d7a4c3b4c8126a8a9 (patch)
tree891db90179470c2799a700d5a1df83c15af90790 /src/libcamera/v4l2_device.cpp
parentafb503fa34d5f537bac106fe94fbf68ad2a6cddf (diff)
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 <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/v4l2_device.cpp')
-rw-r--r--src/libcamera/v4l2_device.cpp74
1 files changed, 70 insertions, 4 deletions
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<ControlId> v4l2ControlId(const v4l2_query_ext_ctrl &ctrl)
+{
+ const size_t len = strnlen(ctrl.name, sizeof(ctrl.name));
+ const std::string name(static_cast<const char *>(ctrl.name), len);
+ const ControlType type = v4l2CtrlType(ctrl.type);
+
+ return std::make_unique<ControlId>(ctrl.id, name, type);
+}
+
+ControlInfo v4l2ControlInfo(const v4l2_query_ext_ctrl &ctrl)
+{
+ switch (ctrl.type) {
+ case V4L2_CTRL_TYPE_U8:
+ return ControlInfo(static_cast<uint8_t>(ctrl.minimum),
+ static_cast<uint8_t>(ctrl.maximum),
+ static_cast<uint8_t>(ctrl.default_value));
+
+ case V4L2_CTRL_TYPE_BOOLEAN:
+ return ControlInfo(static_cast<bool>(ctrl.minimum),
+ static_cast<bool>(ctrl.maximum),
+ static_cast<bool>(ctrl.default_value));
+
+ case V4L2_CTRL_TYPE_INTEGER64:
+ return ControlInfo(static_cast<int64_t>(ctrl.minimum),
+ static_cast<int64_t>(ctrl.maximum),
+ static_cast<int64_t>(ctrl.default_value));
+
+ default:
+ return ControlInfo(static_cast<int32_t>(ctrl.minimum),
+ static_cast<int32_t>(ctrl.maximum),
+ static_cast<int32_t>(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<V4L2ControlId>(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);
}
}