pipeline: raspberrypi: delayed_controls: Add user cookie to DelayedControls

Allow the caller to provide a cookie value to DelayedControls::reset and
DelayedControls::push. This cookie value is returned from DelayedControls::get
for the frame that has the control values applied to it.

The cookie value is useful in tracking when a set of controls has been applied
to a frame. In a subsequent commit, it will be used by the Raspberry Pi IPA to
track the IPA context used when setting the control values.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Naushir Patuck
2022-11-15 09:07:51 +00:00
committed by Laurent Pinchart
parent c7524b10e0
commit 33abc2b31e
3 changed files with 16 additions and 12 deletions

View File

@@ -108,7 +108,7 @@ DelayedControls::DelayedControls(V4L2Device *device,
maxDelay_ = std::max(maxDelay_, controlParams_[id].delay);
}
reset();
reset(0);
}
/**
@@ -117,10 +117,11 @@ DelayedControls::DelayedControls(V4L2Device *device,
* Resets the state machine to a starting position based on control values
* retrieved from the device.
*/
void DelayedControls::reset()
void DelayedControls::reset(unsigned int cookie)
{
queueCount_ = 1;
writeCount_ = 0;
cookies_[0] = cookie;
/* Retrieve control as reported by the device. */
std::vector<uint32_t> ids;
@@ -150,7 +151,7 @@ void DelayedControls::reset()
*
* \returns true if \a controls are accepted, or false otherwise
*/
bool DelayedControls::push(const ControlList &controls)
bool DelayedControls::push(const ControlList &controls, const unsigned int cookie)
{
/* Copy state from previous frame. */
for (auto &ctrl : values_) {
@@ -184,6 +185,7 @@ bool DelayedControls::push(const ControlList &controls)
<< " at index " << queueCount_;
}
cookies_[queueCount_] = cookie;
queueCount_++;
return true;
@@ -204,7 +206,7 @@ bool DelayedControls::push(const ControlList &controls)
*
* \return The controls at \a sequence number
*/
ControlList DelayedControls::get(uint32_t sequence)
std::pair<ControlList, unsigned int> DelayedControls::get(uint32_t sequence)
{
unsigned int index = std::max<int>(0, sequence - maxDelay_);
@@ -221,7 +223,7 @@ ControlList DelayedControls::get(uint32_t sequence)
<< " at index " << index;
}
return out;
return { out, cookies_[index] };
}
/**
@@ -280,7 +282,7 @@ void DelayedControls::applyControls(uint32_t sequence)
while (writeCount_ > queueCount_) {
LOG(RPiDelayedControls, Debug)
<< "Queue is empty, auto queue no-op.";
push({});
push({}, cookies_[queueCount_ - 1]);
}
device_->setControls(&out);

View File

@@ -11,6 +11,7 @@
#include <stdint.h>
#include <unordered_map>
#include <utility>
#include <libcamera/controls.h>
@@ -31,10 +32,10 @@ public:
DelayedControls(V4L2Device *device,
const std::unordered_map<uint32_t, ControlParams> &controlParams);
void reset();
void reset(unsigned int cookie);
bool push(const ControlList &controls);
ControlList get(uint32_t sequence);
bool push(const ControlList &controls, unsigned int cookie);
std::pair<ControlList, unsigned int> get(uint32_t sequence);
void applyControls(uint32_t sequence);
@@ -78,6 +79,7 @@ private:
uint32_t queueCount_;
uint32_t writeCount_;
std::unordered_map<const ControlId *, RingBuffer<Info>> values_;
RingBuffer<unsigned int> cookies_;
};
} /* namespace RPi */

View File

@@ -1066,7 +1066,7 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls)
* Reset the delayed controls with the gain and exposure values set by
* the IPA.
*/
data->delayedCtrls_->reset();
data->delayedCtrls_->reset(0);
data->state_ = RPiCameraData::State::Idle;
@@ -1802,7 +1802,7 @@ void RPiCameraData::setIspControls(const ControlList &controls)
void RPiCameraData::setDelayedControls(const ControlList &controls)
{
if (!delayedCtrls_->push(controls))
if (!delayedCtrls_->push(controls, 0))
LOG(RPI, Error) << "V4L2 DelayedControl set failed";
handleState();
}
@@ -1875,7 +1875,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)
* Lookup the sensor controls used for this frame sequence from
* DelayedControl and queue them along with the frame buffer.
*/
ControlList ctrl = delayedCtrls_->get(buffer->metadata().sequence);
auto [ctrl, cookie] = delayedCtrls_->get(buffer->metadata().sequence);
/*
* Add the frame timestamp to the ControlList for the IPA to use
* as it does not receive the FrameBuffer object.