diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-10-07 22:31:59 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-10-13 20:37:51 +0300 |
commit | 343978af0b491002dd198b6465d2e3a5fae4e407 (patch) | |
tree | 400703ea4480dec45670150e1a9b9fa47bf77e2e /src/libcamera/v4l2_device.cpp | |
parent | 2fe723440a91ab9e086b90ffae912bf0f877daf2 (diff) |
libcamera: v4l2_device: Replace V4L2ControlList with ControlList
The V4L2Device class uses V4L2ControlList as a controls container for
the getControls() and setControls() operations. Having a distinct
container from ControlList will makes the IPA API more complex, as it
needs to explicitly transport both types of lists. This will become even
more painful when implementing serialisation and deserialisation.
To simplify the IPA API and ease the implementation of serialisation and
deserialisation, replace usage of V4L2ControlList with ControlList in
the V4L2Device (and thus CameraSensor) API. The V4L2ControlList class
becomes a thin wrapper around ControlList that slightly simplifies the
creation of control lists for V4L2 controls, and may be removed in the
future.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Tested-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/v4l2_device.cpp')
-rw-r--r-- | src/libcamera/v4l2_device.cpp | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 1f755f0f..b47ba448 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -163,7 +163,7 @@ void V4L2Device::close() * \retval -EINVAL One of the control is not supported or not accessible * \retval i The index of the control that failed */ -int V4L2Device::getControls(V4L2ControlList *ctrls) +int V4L2Device::getControls(ControlList *ctrls) { unsigned int count = ctrls->size(); if (count == 0) @@ -173,18 +173,21 @@ int V4L2Device::getControls(V4L2ControlList *ctrls) struct v4l2_ext_control v4l2Ctrls[count]; memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); - for (unsigned int i = 0; i < count; ++i) { - const V4L2Control *ctrl = ctrls->getByIndex(i); - const auto iter = controls_.find(ctrl->id()); + unsigned int i = 0; + for (const auto &ctrl : *ctrls) { + const ControlId *id = ctrl.first; + const auto iter = controls_.find(id->id()); if (iter == controls_.end()) { LOG(V4L2, Error) - << "Control '" << ctrl->id() << "' not found"; + << "Control '" << id->name() << "' not found"; return -EINVAL; } const V4L2ControlInfo *info = &iter->second; controlInfo[i] = info; - v4l2Ctrls[i].id = ctrl->id(); + v4l2Ctrls[i].id = id->id(); + + i++; } struct v4l2_ext_controls v4l2ExtCtrls = {}; @@ -238,7 +241,7 @@ int V4L2Device::getControls(V4L2ControlList *ctrls) * \retval -EINVAL One of the control is not supported or not accessible * \retval i The index of the control that failed */ -int V4L2Device::setControls(V4L2ControlList *ctrls) +int V4L2Device::setControls(ControlList *ctrls) { unsigned int count = ctrls->size(); if (count == 0) @@ -248,32 +251,36 @@ int V4L2Device::setControls(V4L2ControlList *ctrls) struct v4l2_ext_control v4l2Ctrls[count]; memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); - for (unsigned int i = 0; i < count; ++i) { - const V4L2Control *ctrl = ctrls->getByIndex(i); - const auto iter = controls_.find(ctrl->id()); + unsigned int i = 0; + for (const auto &ctrl : *ctrls) { + const ControlId *id = ctrl.first; + const auto iter = controls_.find(id->id()); if (iter == controls_.end()) { LOG(V4L2, Error) - << "Control '" << ctrl->id() << "' not found"; + << "Control '" << id->name() << "' not found"; return -EINVAL; } const V4L2ControlInfo *info = &iter->second; controlInfo[i] = info; - v4l2Ctrls[i].id = ctrl->id(); + v4l2Ctrls[i].id = id->id(); /* Set the v4l2_ext_control value for the write operation. */ + const ControlValue &value = ctrl.second; switch (info->id().type()) { case ControlTypeInteger64: - v4l2Ctrls[i].value64 = ctrl->value().get<int64_t>(); + v4l2Ctrls[i].value64 = value.get<int64_t>(); break; default: /* * \todo To be changed when support for string and * compound controls will be added. */ - v4l2Ctrls[i].value = ctrl->value().get<int32_t>(); + v4l2Ctrls[i].value = value.get<int32_t>(); break; } + + i++; } struct v4l2_ext_controls v4l2ExtCtrls = {}; @@ -385,28 +392,34 @@ void V4L2Device::listControls() * \param[in] v4l2Ctrls List of V4L2 extended controls as returned by the driver * \param[in] count The number of controls to update */ -void V4L2Device::updateControls(V4L2ControlList *ctrls, +void V4L2Device::updateControls(ControlList *ctrls, const V4L2ControlInfo **controlInfo, const struct v4l2_ext_control *v4l2Ctrls, unsigned int count) { - for (unsigned int i = 0; i < count; ++i) { + unsigned int i = 0; + for (auto &ctrl : *ctrls) { + if (i == count) + break; + const struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i]; const V4L2ControlInfo *info = controlInfo[i]; - V4L2Control *ctrl = ctrls->getByIndex(i); + ControlValue &value = ctrl.second; switch (info->id().type()) { case ControlTypeInteger64: - ctrl->value().set<int64_t>(v4l2Ctrl->value64); + value.set<int64_t>(v4l2Ctrl->value64); break; default: /* * \todo To be changed when support for string and * compound controls will be added. */ - ctrl->value().set<int32_t>(v4l2Ctrl->value); + value.set<int32_t>(v4l2Ctrl->value); break; } + + i++; } } |