libcamera: camera_sensor: getControls(): Use span

The function takes a const std::vector reference, but it does
not actually need an `std::vector`. So use a `libcamera::Span`
instead to avoid forcing the caller to construct a vector.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze
2024-08-04 01:37:18 +02:00
parent 01a9b83f38
commit 39d37fce12
6 changed files with 31 additions and 18 deletions

View File

@@ -14,6 +14,7 @@
#include <vector>
#include <libcamera/base/class.h>
#include <libcamera/base/span.h>
#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
@@ -74,7 +75,7 @@ public:
virtual BayerFormat::Order bayerOrder(Transform t) const = 0;
virtual const ControlInfoMap &controls() const = 0;
virtual ControlList getControls(const std::vector<uint32_t> &ids) = 0;
virtual ControlList getControls(Span<const uint32_t> ids) = 0;
virtual int setControls(ControlList *ctrls) = 0;
virtual const std::vector<controls::draft::TestPatternModeEnum> &

View File

@@ -37,7 +37,7 @@ public:
const ControlInfoMap &controls() const { return controls_; }
ControlList getControls(const std::vector<uint32_t> &ids);
ControlList getControls(Span<const uint32_t> ids);
int setControls(ControlList *ctrls);
const struct v4l2_query_ext_ctrl *controlInfo(uint32_t id) const;

View File

@@ -90,7 +90,7 @@ public:
BayerFormat::Order bayerOrder(Transform t) const override;
const ControlInfoMap &controls() const override;
ControlList getControls(const std::vector<uint32_t> &ids) override;
ControlList getControls(Span<const uint32_t> ids) override;
int setControls(ControlList *ctrls) override;
const std::vector<controls::draft::TestPatternModeEnum> &
@@ -907,9 +907,13 @@ int CameraSensorLegacy::sensorInfo(IPACameraSensorInfo *info) const
* duration through V4L2 controls. Support for the V4L2_CID_PIXEL_RATE,
* V4L2_CID_HBLANK and V4L2_CID_VBLANK controls is mandatory.
*/
ControlList ctrls = subdev_->getControls({ V4L2_CID_PIXEL_RATE,
V4L2_CID_HBLANK,
V4L2_CID_VBLANK });
static constexpr uint32_t cids[] = {
V4L2_CID_PIXEL_RATE,
V4L2_CID_HBLANK,
V4L2_CID_VBLANK,
};
ControlList ctrls = subdev_->getControls(cids);
if (ctrls.empty()) {
LOG(CameraSensor, Error)
<< "Failed to retrieve camera info controls";
@@ -983,7 +987,7 @@ const ControlInfoMap &CameraSensorLegacy::controls() const
return subdev_->controls();
}
ControlList CameraSensorLegacy::getControls(const std::vector<uint32_t> &ids)
ControlList CameraSensorLegacy::getControls(Span<const uint32_t> ids)
{
return subdev_->getControls(ids);
}

View File

@@ -96,7 +96,7 @@ public:
BayerFormat::Order bayerOrder(Transform t) const override;
const ControlInfoMap &controls() const override;
ControlList getControls(const std::vector<uint32_t> &ids) override;
ControlList getControls(Span<const uint32_t> ids) override;
int setControls(ControlList *ctrls) override;
const std::vector<controls::draft::TestPatternModeEnum> &
@@ -1022,9 +1022,13 @@ int CameraSensorRaw::sensorInfo(IPACameraSensorInfo *info) const
* duration through V4L2 controls. Support for the V4L2_CID_PIXEL_RATE,
* V4L2_CID_HBLANK and V4L2_CID_VBLANK controls is mandatory.
*/
ControlList ctrls = subdev_->getControls({ V4L2_CID_PIXEL_RATE,
V4L2_CID_HBLANK,
V4L2_CID_VBLANK });
static constexpr uint32_t cids[] = {
V4L2_CID_PIXEL_RATE,
V4L2_CID_HBLANK,
V4L2_CID_VBLANK,
};
ControlList ctrls = subdev_->getControls(cids);
if (ctrls.empty()) {
LOG(CameraSensor, Error)
<< "Failed to retrieve camera info controls";
@@ -1095,7 +1099,7 @@ const ControlInfoMap &CameraSensorRaw::controls() const
return subdev_->controls();
}
ControlList CameraSensorRaw::getControls(const std::vector<uint32_t> &ids)
ControlList CameraSensorRaw::getControls(Span<const uint32_t> ids)
{
return subdev_->getControls(ids);
}

View File

@@ -174,7 +174,7 @@ void V4L2Device::close()
* \return The control values in a ControlList on success, or an empty list on
* error
*/
ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)
ControlList V4L2Device::getControls(Span<const uint32_t> ids)
{
if (ids.empty())
return {};

View File

@@ -60,11 +60,15 @@ protected:
const ControlInfo &u8 = infoMap.find(VIVID_CID_U8_4D_ARRAY)->second;
/* Test getting controls. */
ControlList ctrls = capture_->getControls({ V4L2_CID_BRIGHTNESS,
V4L2_CID_CONTRAST,
V4L2_CID_SATURATION,
VIVID_CID_INTEGER64,
VIVID_CID_U8_4D_ARRAY });
static constexpr uint32_t cids[] = {
V4L2_CID_BRIGHTNESS,
V4L2_CID_CONTRAST,
V4L2_CID_SATURATION,
VIVID_CID_INTEGER64,
VIVID_CID_U8_4D_ARRAY,
};
ControlList ctrls = capture_->getControls(cids);
if (ctrls.empty()) {
cerr << "Failed to get controls" << endl;
return TestFail;