libcamera: v4l2_controls: Replace V4L2ControlInfo with V4L2ControlRange

The V4L2ControlInfo class only stores a ControlRange. Make it inherit
from ControlRange to provide a convenience constructor from a struct
v4l2_query_ext_ctrl and rename it to V4L2ControlRange.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Laurent Pinchart 2019-10-14 00:41:47 +03:00
parent 7bb4d7144c
commit 207d57c8b4
7 changed files with 54 additions and 73 deletions

View file

@ -83,12 +83,12 @@ void IPARkISP1::configure(const std::map<unsigned int, IPAStream> &streamConfig,
autoExposure_ = true; autoExposure_ = true;
minExposure_ = std::max<uint32_t>(itExp->second.range().min().get<int32_t>(), 1); minExposure_ = std::max<uint32_t>(itExp->second.min().get<int32_t>(), 1);
maxExposure_ = itExp->second.range().max().get<int32_t>(); maxExposure_ = itExp->second.max().get<int32_t>();
exposure_ = minExposure_; exposure_ = minExposure_;
minGain_ = std::max<uint32_t>(itGain->second.range().min().get<int32_t>(), 1); minGain_ = std::max<uint32_t>(itGain->second.min().get<int32_t>(), 1);
maxGain_ = itGain->second.range().max().get<int32_t>(); maxGain_ = itGain->second.max().get<int32_t>();
gain_ = minGain_; gain_ = minGain_;
LOG(IPARkISP1, Info) LOG(IPARkISP1, Info)

View file

@ -25,38 +25,33 @@ public:
V4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl); V4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl);
}; };
class V4L2ControlInfo class V4L2ControlRange : public ControlRange
{ {
public: public:
V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl); V4L2ControlRange(const struct v4l2_query_ext_ctrl &ctrl);
const ControlRange &range() const { return range_; }
private:
ControlRange range_;
}; };
class V4L2ControlInfoMap : private std::map<const ControlId *, V4L2ControlInfo> class V4L2ControlInfoMap : private std::map<const ControlId *, V4L2ControlRange>
{ {
public: public:
V4L2ControlInfoMap &operator=(std::map<const ControlId *, V4L2ControlInfo> &&info); V4L2ControlInfoMap &operator=(std::map<const ControlId *, V4L2ControlRange> &&info);
using std::map<const ControlId *, V4L2ControlInfo>::key_type; using std::map<const ControlId *, V4L2ControlRange>::key_type;
using std::map<const ControlId *, V4L2ControlInfo>::mapped_type; using std::map<const ControlId *, V4L2ControlRange>::mapped_type;
using std::map<const ControlId *, V4L2ControlInfo>::value_type; using std::map<const ControlId *, V4L2ControlRange>::value_type;
using std::map<const ControlId *, V4L2ControlInfo>::size_type; using std::map<const ControlId *, V4L2ControlRange>::size_type;
using std::map<const ControlId *, V4L2ControlInfo>::iterator; using std::map<const ControlId *, V4L2ControlRange>::iterator;
using std::map<const ControlId *, V4L2ControlInfo>::const_iterator; using std::map<const ControlId *, V4L2ControlRange>::const_iterator;
using std::map<const ControlId *, V4L2ControlInfo>::begin; using std::map<const ControlId *, V4L2ControlRange>::begin;
using std::map<const ControlId *, V4L2ControlInfo>::cbegin; using std::map<const ControlId *, V4L2ControlRange>::cbegin;
using std::map<const ControlId *, V4L2ControlInfo>::end; using std::map<const ControlId *, V4L2ControlRange>::end;
using std::map<const ControlId *, V4L2ControlInfo>::cend; using std::map<const ControlId *, V4L2ControlRange>::cend;
using std::map<const ControlId *, V4L2ControlInfo>::at; using std::map<const ControlId *, V4L2ControlRange>::at;
using std::map<const ControlId *, V4L2ControlInfo>::empty; using std::map<const ControlId *, V4L2ControlRange>::empty;
using std::map<const ControlId *, V4L2ControlInfo>::size; using std::map<const ControlId *, V4L2ControlRange>::size;
using std::map<const ControlId *, V4L2ControlInfo>::count; using std::map<const ControlId *, V4L2ControlRange>::count;
using std::map<const ControlId *, V4L2ControlInfo>::find; using std::map<const ControlId *, V4L2ControlRange>::find;
mapped_type &at(unsigned int key); mapped_type &at(unsigned int key);
const mapped_type &at(unsigned int key) const; const mapped_type &at(unsigned int key) const;

View file

@ -337,7 +337,7 @@ int UVCCameraData::init(MediaEntity *entity)
/* Initialise the supported controls. */ /* Initialise the supported controls. */
const V4L2ControlInfoMap &controls = video_->controls(); const V4L2ControlInfoMap &controls = video_->controls();
for (const auto &ctrl : controls) { for (const auto &ctrl : controls) {
const V4L2ControlInfo &info = ctrl.second; const V4L2ControlRange &range = ctrl.second;
const ControlId *id; const ControlId *id;
switch (ctrl.first->id()) { switch (ctrl.first->id()) {
@ -362,7 +362,7 @@ int UVCCameraData::init(MediaEntity *entity)
controlInfo_.emplace(std::piecewise_construct, controlInfo_.emplace(std::piecewise_construct,
std::forward_as_tuple(id), std::forward_as_tuple(id),
std::forward_as_tuple(info.range())); std::forward_as_tuple(range));
} }
return 0; return 0;

View file

@ -413,7 +413,7 @@ int VimcCameraData::init(MediaDevice *media)
/* Initialise the supported controls. */ /* Initialise the supported controls. */
const V4L2ControlInfoMap &controls = sensor_->controls(); const V4L2ControlInfoMap &controls = sensor_->controls();
for (const auto &ctrl : controls) { for (const auto &ctrl : controls) {
const V4L2ControlInfo &info = ctrl.second; const V4L2ControlRange &range = ctrl.second;
const ControlId *id; const ControlId *id;
switch (ctrl.first->id()) { switch (ctrl.first->id()) {
@ -432,7 +432,7 @@ int VimcCameraData::init(MediaDevice *media)
controlInfo_.emplace(std::piecewise_construct, controlInfo_.emplace(std::piecewise_construct,
std::forward_as_tuple(id), std::forward_as_tuple(id),
std::forward_as_tuple(info.range())); std::forward_as_tuple(range));
} }
return 0; return 0;

View file

@ -104,45 +104,31 @@ V4L2ControlId::V4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl)
} }
/** /**
* \class V4L2ControlInfo * \class V4L2ControlRange
* \brief Information on a V4L2 control * \brief Convenience specialisation of ControlRange for V4L2 controls
* *
* The V4L2ControlInfo class represents all the information related to a V4L2 * The V4L2ControlRange class is a specialisation of the ControlRange for V4L2
* control, such as its ID, its type, its user-readable name and the expected * controls. It offers a convenience constructor from a struct
* size of its value data. * v4l2_query_ext_ctrl, and is otherwise equivalent to the ControlRange class.
*
* V4L2ControlInfo instances are created by inspecting the fieldS of a struct
* v4l2_query_ext_ctrl structure, after it has been filled by the device driver
* as a consequence of a VIDIOC_QUERY_EXT_CTRL ioctl call.
*
* This class does not contain the control value, but only static information on
* the control, which shall be cached by the caller at initialisation time or
* the first time the control information is accessed.
*/ */
/** /**
* \brief Construct a V4L2ControlInfo from a struct v4l2_query_ext_ctrl * \brief Construct a V4L2ControlRange from a struct v4l2_query_ext_ctrl
* \param[in] ctrl The struct v4l2_query_ext_ctrl as returned by the kernel * \param[in] ctrl The struct v4l2_query_ext_ctrl as returned by the kernel
*/ */
V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) V4L2ControlRange::V4L2ControlRange(const struct v4l2_query_ext_ctrl &ctrl)
{ {
if (ctrl.type == V4L2_CTRL_TYPE_INTEGER64) if (ctrl.type == V4L2_CTRL_TYPE_INTEGER64)
range_ = ControlRange(static_cast<int64_t>(ctrl.minimum), ControlRange::operator=(ControlRange(static_cast<int64_t>(ctrl.minimum),
static_cast<int64_t>(ctrl.maximum)); static_cast<int64_t>(ctrl.maximum)));
else else
range_ = ControlRange(static_cast<int32_t>(ctrl.minimum), ControlRange::operator=(ControlRange(static_cast<int32_t>(ctrl.minimum),
static_cast<int32_t>(ctrl.maximum)); static_cast<int32_t>(ctrl.maximum)));
} }
/**
* \fn V4L2ControlInfo::range()
* \brief Retrieve the control value range
* \return The V4L2 control value range
*/
/** /**
* \class V4L2ControlInfoMap * \class V4L2ControlInfoMap
* \brief A map of controlID to V4L2ControlInfo * \brief A map of controlID to V4L2ControlRange
*/ */
/** /**
@ -156,9 +142,9 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)
* *
* \return The populated V4L2ControlInfoMap * \return The populated V4L2ControlInfoMap
*/ */
V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<const ControlId *, V4L2ControlInfo> &&info) V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<const ControlId *, V4L2ControlRange> &&info)
{ {
std::map<const ControlId *, V4L2ControlInfo>::operator=(std::move(info)); std::map<const ControlId *, V4L2ControlRange>::operator=(std::move(info));
idmap_.clear(); idmap_.clear();
for (const auto &ctrl : *this) for (const auto &ctrl : *this)

View file

@ -342,7 +342,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)
*/ */
void V4L2Device::listControls() void V4L2Device::listControls()
{ {
std::map<const ControlId *, V4L2ControlInfo> ctrls; std::map<const ControlId *, V4L2ControlRange> ctrls;
struct v4l2_query_ext_ctrl ctrl = {}; struct v4l2_query_ext_ctrl ctrl = {};
/* \todo Add support for menu and compound controls. */ /* \todo Add support for menu and compound controls. */

View file

@ -41,9 +41,9 @@ protected:
return TestFail; return TestFail;
} }
const V4L2ControlInfo &brightness = info.find(V4L2_CID_BRIGHTNESS)->second; const V4L2ControlRange &brightness = info.find(V4L2_CID_BRIGHTNESS)->second;
const V4L2ControlInfo &contrast = info.find(V4L2_CID_CONTRAST)->second; const V4L2ControlRange &contrast = info.find(V4L2_CID_CONTRAST)->second;
const V4L2ControlInfo &saturation = info.find(V4L2_CID_SATURATION)->second; const V4L2ControlRange &saturation = info.find(V4L2_CID_SATURATION)->second;
/* Test getting controls. */ /* Test getting controls. */
V4L2ControlList ctrls(info); V4L2ControlList ctrls(info);
@ -65,9 +65,9 @@ protected:
} }
/* Test setting controls. */ /* Test setting controls. */
ctrls.set(V4L2_CID_BRIGHTNESS, brightness.range().min()); ctrls.set(V4L2_CID_BRIGHTNESS, brightness.min());
ctrls.set(V4L2_CID_CONTRAST, contrast.range().max()); ctrls.set(V4L2_CID_CONTRAST, contrast.max());
ctrls.set(V4L2_CID_SATURATION, saturation.range().min()); ctrls.set(V4L2_CID_SATURATION, saturation.min());
ret = capture_->setControls(&ctrls); ret = capture_->setControls(&ctrls);
if (ret) { if (ret) {
@ -76,9 +76,9 @@ protected:
} }
/* Test setting controls outside of range. */ /* Test setting controls outside of range. */
ctrls.set(V4L2_CID_BRIGHTNESS, brightness.range().min().get<int32_t>() - 1); ctrls.set(V4L2_CID_BRIGHTNESS, brightness.min().get<int32_t>() - 1);
ctrls.set(V4L2_CID_CONTRAST, contrast.range().max().get<int32_t>() + 1); ctrls.set(V4L2_CID_CONTRAST, contrast.max().get<int32_t>() + 1);
ctrls.set(V4L2_CID_SATURATION, saturation.range().min().get<int32_t>() + 1); ctrls.set(V4L2_CID_SATURATION, saturation.min().get<int32_t>() + 1);
ret = capture_->setControls(&ctrls); ret = capture_->setControls(&ctrls);
if (ret) { if (ret) {
@ -86,9 +86,9 @@ protected:
return TestFail; return TestFail;
} }
if (ctrls.get(V4L2_CID_BRIGHTNESS) != brightness.range().min() || if (ctrls.get(V4L2_CID_BRIGHTNESS) != brightness.min() ||
ctrls.get(V4L2_CID_CONTRAST) != contrast.range().max() || ctrls.get(V4L2_CID_CONTRAST) != contrast.max() ||
ctrls.get(V4L2_CID_SATURATION) != saturation.range().min().get<int32_t>() + 1) { ctrls.get(V4L2_CID_SATURATION) != saturation.min().get<int32_t>() + 1) {
cerr << "Controls not updated when set" << endl; cerr << "Controls not updated when set" << endl;
return TestFail; return TestFail;
} }