summaryrefslogtreecommitdiff
path: root/src/libcamera/pipeline
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-09-27 23:59:43 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-10-04 19:33:08 +0300
commita8c40942b99e7e50d43a40c4b0a601c7428b30fd (patch)
tree66bbc5156bd5fbafe05743005ac88e41079daadd /src/libcamera/pipeline
parentdd37ef784e7b4a8125225177bf74eef04b8efd83 (diff)
libcamera: controls: Improve the API towards applications
Rework the control-related classes to improve the API towards applications. The goal is to enable writing code similar to Request *req = ...; ControlList &controls = req->controls(); controls->set(controls::AwbEnable, false); controls->set(controls::ManualExposure, 1000); ... int32_t exposure = controls->get(controls::ManualExposure); with the get and set operations ensuring type safety for the control values. This is achieved by creating the following classes: - Control defines controls and is the main way to reference a control. It is a template class to allow methods using it to refer to the control type. - ControlId is the base class of Control. It stores the control ID, name and type, and can be used in contexts where a control needs to be referenced regardless of its type (for instance in lists of controls). This class replaces ControlIdentifier. - ControlValue is kept as-is. The ControlList class now exposes two template get() and set() methods that replace the operator[]. They ensure type safety by infering the value type from the Control reference that they receive. The main way to refer to a control is now through the Control class, and optionally through its base ControlId class. The ControlId enumeration is removed, replaced by a list of global Control instances. Numerical control IDs are turned into macros, and are still exposed as they are required to communicate with IPAs (especially to deserialise control lists). They should however not be used by applications. Auto-generation of header and source files is removed for now to keep the change simple. It will be added back in the future in a more elaborate form. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/pipeline')
-rw-r--r--src/libcamera/pipeline/uvcvideo.cpp40
-rw-r--r--src/libcamera/pipeline/vimc.cpp28
2 files changed, 24 insertions, 44 deletions
diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index 0d56758e..d5d30932 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -10,6 +10,7 @@
#include <tuple>
#include <libcamera/camera.h>
+#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include <libcamera/request.h>
#include <libcamera/stream.h>
@@ -230,33 +231,20 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)
V4L2ControlList controls;
for (auto it : request->controls()) {
- const ControlInfo *ci = it.first;
+ const ControlId &id = *it.first;
ControlValue &value = it.second;
- switch (ci->id()) {
- case Brightness:
+ if (id == controls::Brightness) {
controls.add(V4L2_CID_BRIGHTNESS, value.get<int32_t>());
- break;
-
- case Contrast:
+ } else if (id == controls::Contrast) {
controls.add(V4L2_CID_CONTRAST, value.get<int32_t>());
- break;
-
- case Saturation:
+ } else if (id == controls::Saturation) {
controls.add(V4L2_CID_SATURATION, value.get<int32_t>());
- break;
-
- case ManualExposure:
+ } else if (id == controls::ManualExposure) {
controls.add(V4L2_CID_EXPOSURE_AUTO, 1);
controls.add(V4L2_CID_EXPOSURE_ABSOLUTE, value.get<int32_t>());
- break;
-
- case ManualGain:
+ } else if (id == controls::ManualGain) {
controls.add(V4L2_CID_GAIN, value.get<int32_t>());
- break;
-
- default:
- break;
}
}
@@ -352,23 +340,23 @@ int UVCCameraData::init(MediaEntity *entity)
for (const auto &ctrl : controls) {
unsigned int v4l2Id = ctrl.first;
const V4L2ControlInfo &info = ctrl.second;
- ControlId id;
+ const ControlId *id;
switch (v4l2Id) {
case V4L2_CID_BRIGHTNESS:
- id = Brightness;
+ id = &controls::Brightness;
break;
case V4L2_CID_CONTRAST:
- id = Contrast;
+ id = &controls::Contrast;
break;
case V4L2_CID_SATURATION:
- id = Saturation;
+ id = &controls::Saturation;
break;
case V4L2_CID_EXPOSURE_ABSOLUTE:
- id = ManualExposure;
+ id = &controls::ManualExposure;
break;
case V4L2_CID_GAIN:
- id = ManualGain;
+ id = &controls::ManualGain;
break;
default:
continue;
@@ -376,7 +364,7 @@ int UVCCameraData::init(MediaEntity *entity)
controlInfo_.emplace(std::piecewise_construct,
std::forward_as_tuple(id),
- std::forward_as_tuple(id, info.min(), info.max()));
+ std::forward_as_tuple(*id, info.min(), info.max()));
}
return 0;
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index e549dc64..608a47ae 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -15,6 +15,7 @@
#include <ipa/ipa_interface.h>
#include <ipa/ipa_module_info.h>
#include <libcamera/camera.h>
+#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include <libcamera/request.h>
#include <libcamera/stream.h>
@@ -283,24 +284,15 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)
V4L2ControlList controls;
for (auto it : request->controls()) {
- const ControlInfo *ci = it.first;
+ const ControlId &id = *it.first;
ControlValue &value = it.second;
- switch (ci->id()) {
- case Brightness:
+ if (id == controls::Brightness) {
controls.add(V4L2_CID_BRIGHTNESS, value.get<int32_t>());
- break;
-
- case Contrast:
+ } else if (id == controls::Contrast) {
controls.add(V4L2_CID_CONTRAST, value.get<int32_t>());
- break;
-
- case Saturation:
+ } else if (id == controls::Saturation) {
controls.add(V4L2_CID_SATURATION, value.get<int32_t>());
- break;
-
- default:
- break;
}
}
@@ -427,17 +419,17 @@ int VimcCameraData::init(MediaDevice *media)
for (const auto &ctrl : controls) {
unsigned int v4l2Id = ctrl.first;
const V4L2ControlInfo &info = ctrl.second;
- ControlId id;
+ const ControlId *id;
switch (v4l2Id) {
case V4L2_CID_BRIGHTNESS:
- id = Brightness;
+ id = &controls::Brightness;
break;
case V4L2_CID_CONTRAST:
- id = Contrast;
+ id = &controls::Contrast;
break;
case V4L2_CID_SATURATION:
- id = Saturation;
+ id = &controls::Saturation;
break;
default:
continue;
@@ -445,7 +437,7 @@ int VimcCameraData::init(MediaDevice *media)
controlInfo_.emplace(std::piecewise_construct,
std::forward_as_tuple(id),
- std::forward_as_tuple(id, info.min(), info.max()));
+ std::forward_as_tuple(*id, info.min(), info.max()));
}
return 0;