From c286b00aa1eb9331c3bab2b35905dcf2e4ccde66 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Tue, 24 Nov 2020 17:59:34 +0000 Subject: pipeline: raspberrypi: Fix erroneous bayer buffer requeue on buffer matching With the recent change in the bayer/embedded buffer matching code, a condition would make the bayer buffer be requeued back to the device, even though it could potentially be queued for matching. This would cause unnecessary frame drops as sync would be lost. The fix is to ensure the bayer buffer only gets requeued if the embedded data buffer queue is not empty, i.e. the buffer truly is orphaned. Additionally, we do this test before deciding to flush any of the two queues of all their buffers. Fixes: 909882b (pipeline: raspberrypi: Rework bayer/embedded data buffer matching) Signed-off-by: Naushir Patuck Tested-by: Kieran Bingham Tested-by: David Plowman Reviewed-by: Kieran Bingham Signed-off-by: Kieran Bingham --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/libcamera/pipeline/raspberrypi/raspberrypi.cpp') diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 66b483f7..6fcdf557 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1696,8 +1696,23 @@ bool RPiCameraData::findMatchingBuffers(FrameBuffer *&bayerBuffer, FrameBuffer * } if (!embeddedBuffer) { + bool flushedBuffers = false; + LOG(RPI, Debug) << "Could not find matching embedded buffer"; + if (!embeddedQueue_.empty()) { + /* + * Not found a matching embedded buffer for the bayer buffer in + * the front of the queue. This buffer is now orphaned, so requeue + * it back to the device. + */ + unicam_[Unicam::Image].queueBuffer(bayerQueue_.front()); + bayerQueue_.pop(); + bayerRequeueCount++; + LOG(RPI, Warning) << "Dropping unmatched input frame in stream " + << unicam_[Unicam::Image].name(); + } + /* * If we have requeued all available embedded data buffers in this loop, * then we are fully out of sync, so might as well requeue all the pending @@ -1712,20 +1727,9 @@ bool RPiCameraData::findMatchingBuffers(FrameBuffer *&bayerBuffer, FrameBuffer * unicam_[Unicam::Image].queueBuffer(bayerQueue_.front()); bayerQueue_.pop(); } - return false; + flushedBuffers = true; } - /* - * Not found a matching embedded buffer for the bayer buffer in - * the front of the queue. This buffer is now orphaned, so requeue - * it back to the device. - */ - unicam_[Unicam::Image].queueBuffer(bayerQueue_.front()); - bayerQueue_.pop(); - bayerRequeueCount++; - LOG(RPI, Warning) << "Dropping unmatched input frame in stream " - << unicam_[Unicam::Image].name(); - /* * Similar to the above, if we have requeued all available bayer buffers in * the loop, then we are fully out of sync, so might as well requeue all the @@ -1740,11 +1744,15 @@ bool RPiCameraData::findMatchingBuffers(FrameBuffer *&bayerBuffer, FrameBuffer * unicam_[Unicam::Embedded].queueBuffer(embeddedQueue_.front()); embeddedQueue_.pop(); } - return false; + flushedBuffers = true; } - /* If the embedded queue has become empty, we cannot do any more. */ - if (embeddedQueue_.empty()) + /* + * If the embedded queue has become empty, we cannot do any more. + * Similarly, if we have flushed any one of our queues, we cannot do + * any more. Return from here without a buffer pair. + */ + if (embeddedQueue_.empty() || flushedBuffers) return false; } else { /* -- cgit v1.2.1