[RFC] delayed_controls: avoid reading undefined control value
Stanislaw Gruszka
stanislaw.gruszka at linux.intel.com
Fri Dec 6 12:27:43 CET 2024
Limit ControlRingBuffer index by number of queued entries in order do
avoid reading undefined control value with type ControlTypeNone .
It can happen at the begging of streaming when ControlRingBuffer is
not yet filled and there are errors on CSI-2 bus resulting dropping
frames. Then we can call to DelayedControls::get() with frame number
that exceed number of saved entries and get below assertion failure:
../src/libcamera/delayed_controls.cpp:227:
libcamera::ControlList libcamera::DelayedControls::get(uint32_t):
Assertion `info.type() != ControlTypeNone' failed
Bug: https://bugs.libcamera.org/show_bug.cgi?id=241
Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka at linux.intel.com>
---
Notes: When debugging this I notice that the push() and get() are
done in different threads. Maybe mutex should be
used? Not sure how synchronization works for mojom signals
handlers.
Also I'm not sure if similar change like in this patch
is not needed for rpi DelayedControls
Alternative fix would be to pre-fill ControlRingBuffer with
valid control values. Should we care about possibility
of queueCount_ overflowing ?
src/libcamera/delayed_controls.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp
index 94d0a575..78b0b8f7 100644
--- a/src/libcamera/delayed_controls.cpp
+++ b/src/libcamera/delayed_controls.cpp
@@ -202,7 +202,7 @@ bool DelayedControls::push(const ControlList &controls)
*/
ControlList DelayedControls::get(uint32_t sequence)
{
- unsigned int index = std::max<int>(0, sequence - maxDelay_);
+ unsigned int index = std::clamp<int>(sequence - maxDelay_, 0, queueCount_ - 1);
ControlList out(device_->controls());
for (const auto &ctrl : values_) {
--
2.43.0
More information about the libcamera-devel
mailing list