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>
This commit is contained in:
parent
dd37ef784e
commit
a8c40942b9
10 changed files with 372 additions and 426 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue