summaryrefslogtreecommitdiff
path: root/src/libcamera/delayed_controls.cpp
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2021-03-04 08:17:22 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2021-03-12 14:12:32 +0000
commit96c0eb338e5e9168147538736b688601c00b87f9 (patch)
treec14b4bbb4865f6c77e36c77195fad5d54f92d750 /src/libcamera/delayed_controls.cpp
parent6795ffe67f3318e474ee14141e5b394b0e5d2d85 (diff)
libcamera: delayed_controls: Add notion of priority write
If an exposure time change adjusts the vblanking limits, and we set both VBLANK and EXPOSURE controls through the VIDIOC_S_EXT_CTRLS ioctl, the latter may fail if the value is outside of the limits calculated by the old VBLANK value. This is a limitation in V4L2 and cannot be fixed by setting VBLANK before EXPOSURE in a single VIDIOC_S_EXT_CTRLS ioctl. The workaround here is to have the DelayedControls object mark the VBLANK control as "priority write", which then write VBLANK separately from (and ahead of) any other controls. This way, the sensor driver will update the EXPOSURE control with new limits before the new values is presented, and will thus be seen as valid. To support this, a new struct DelayedControls::ControlParams is used in the constructor to provide the control delay value as well as the priority write flag. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Tested-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Tested-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> [Kieran: Fix up trivial comments, merge conflicts] Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/libcamera/delayed_controls.cpp')
-rw-r--r--src/libcamera/delayed_controls.cpp54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp
index ab1d4005..fb9e6c42 100644
--- a/src/libcamera/delayed_controls.cpp
+++ b/src/libcamera/delayed_controls.cpp
@@ -40,15 +40,19 @@ LOG_DEFINE_CATEGORY(DelayedControls)
/**
* \brief Construct a DelayedControls instance
* \param[in] device The V4L2 device the controls have to be applied to
- * \param[in] delays Map of the numerical V4L2 control ids to their associated
- * delays (in frames)
+ * \param[in] controlParams Map of the numerical V4L2 control ids to their
+ * associated control parameters.
*
- * Only controls specified in \a delays are handled. If it's desired to mix
- * delayed controls and controls that take effect immediately the immediate
- * controls must be listed in the \a delays map with a delay value of 0.
+ * The control parameters comprise of delays (in frames) and a priority write
+ * flag. If this flag is set, the relevant control is written separately from,
+ * and ahead of the rest of the batched controls.
+ *
+ * Only controls specified in \a controlParams are handled. If it's desired to
+ * mix delayed controls and controls that take effect immediately the immediate
+ * controls must be listed in the \a controlParams map with a delay value of 0.
*/
DelayedControls::DelayedControls(V4L2Device *device,
- const std::unordered_map<uint32_t, unsigned int> &delays)
+ const std::unordered_map<uint32_t, ControlParams> &controlParams)
: device_(device), maxDelay_(0)
{
const ControlInfoMap &controls = device_->controls();
@@ -57,12 +61,12 @@ DelayedControls::DelayedControls(V4L2Device *device,
* Create a map of control ids to delays for controls exposed by the
* device.
*/
- for (auto const &delay : delays) {
- auto it = controls.find(delay.first);
+ for (auto const &param : controlParams) {
+ auto it = controls.find(param.first);
if (it == controls.end()) {
LOG(DelayedControls, Error)
<< "Delay request for control id "
- << utils::hex(delay.first)
+ << utils::hex(param.first)
<< " but control is not exposed by device "
<< device_->deviceNode();
continue;
@@ -70,13 +74,14 @@ DelayedControls::DelayedControls(V4L2Device *device,
const ControlId *id = it->first;
- delays_[id] = delay.second;
+ controlParams_[id] = param.second;
LOG(DelayedControls, Debug)
- << "Set a delay of " << delays_[id]
+ << "Set a delay of " << controlParams_[id].delay
+ << " and priority write flag " << controlParams_[id].priorityWrite
<< " for " << id->name();
- maxDelay_ = std::max(maxDelay_, delays_[id]);
+ maxDelay_ = std::max(maxDelay_, controlParams_[id].delay);
}
reset();
@@ -97,8 +102,8 @@ void DelayedControls::reset()
/* Retrieve control as reported by the device. */
std::vector<uint32_t> ids;
- for (auto const &delay : delays_)
- ids.push_back(delay.first->id());
+ for (auto const &param : controlParams_)
+ ids.push_back(param.first->id());
ControlList controls = device_->getControls(ids);
@@ -140,7 +145,7 @@ bool DelayedControls::push(const ControlList &controls)
const ControlId *id = it->second;
- if (delays_.find(id) == delays_.end())
+ if (controlParams_.find(id) == controlParams_.end())
return false;
Info &info = values_[id][queueCount_];
@@ -220,12 +225,27 @@ void DelayedControls::applyControls(uint32_t sequence)
ControlList out(device_->controls());
for (const auto &ctrl : values_) {
const ControlId *id = ctrl.first;
- unsigned int delayDiff = maxDelay_ - delays_[id];
+ unsigned int delayDiff = maxDelay_ - controlParams_[id].delay;
unsigned int index = std::max<int>(0, writeCount_ - delayDiff);
const Info &info = ctrl.second[index];
if (info.updated) {
- out.set(id->id(), info);
+ if (controlParams_[id].priorityWrite) {
+ /*
+ * This control must be written now, it could
+ * affect validity of the other controls.
+ */
+ ControlList priority(device_->controls());
+ priority.set(id->id(), info);
+ device_->setControls(&priority);
+ } else {
+ /*
+ * Batch up the list of controls and write them
+ * at the end of the function.
+ */
+ out.set(id->id(), info);
+ }
+
LOG(DelayedControls, Debug)
<< "Setting " << id->name()
<< " to " << info.toString()