From patchwork Tue Nov 24 17:59:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10493 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 4A988BE08A for ; Tue, 24 Nov 2020 18:00:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BA66F63404; Tue, 24 Nov 2020 19:00:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="H3MbiZGB"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 46C20615AC for ; Tue, 24 Nov 2020 19:00:16 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 1so3799455wme.3 for ; Tue, 24 Nov 2020 10:00:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1KEnbMAGlC/hMLbCIc6/64SDhdPwTO3l32TBGTeXeKo=; b=H3MbiZGB+jFJXlvi1dIM0pnEX6Nnt26HIli+auppZsc4oaEl1+53nQUBv4AgBoshNJ aYypTgHQRyc6q2bYCnxt7wBum8AQrQWUaJB5g4S+lVRCuslHZU+IMJg8dHizRqRTpWx1 +jz0zItAHpohIrjy9vM53PlfA5Kb0yttujZnsnsp4kqvs/1UHPJ+IVa+QNmlmDqvNlS5 QHC/MinQCn4LyT9ZpwNC89L1PbbODKgb9W5z9B3JU7xrMTjZdqGFEDQwGDKFMc+zBKUr +896TGlwkStB7XSmfQ0/q9WwhT38IDbS3pwsahC1U8uak5CPBRZYsRA7WZHBMRFKQScS xsgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1KEnbMAGlC/hMLbCIc6/64SDhdPwTO3l32TBGTeXeKo=; b=Hx7PXIeElr2469GvQJFLXXy1YOAZ8TqgFbEDW4eGqGpEnmYEZuMkNqQTBGT+PTtRrG hscbZvShG3T/fUXwKjSxbIwpW5Dkt7TEdzWDi2/q32YXl6uNGxo2sDWDi2AVyuSVuF19 AbMFv0r/ovzbD3ddn0wbGJAUrxlAoJNkwpbmeblbr/n4RKJNVtzi+PdWsSHEhXFNS031 NCxXKOeuRWpVdoK4P0PEz1E/pxFh3TrUghd9YvJBRwrgCJ5Wr6yGq/FAIpsojFWxhpLC hSZFLJwYTmWPl7xIbZCDSiRT9JdDvUaQjkDa5iekrotqW1y5S6bQjJqzrQrGhxdsE9Fx gkwA== X-Gm-Message-State: AOAM532c9aI8Y7bHNhcyyT20CqcdD9Q+mCIMokMlGsmb08m6qeQiv90W x4/GUFZAef/CR8GeMWekRExT88bn2mbRIw== X-Google-Smtp-Source: ABdhPJxg6EIAXtIs7IlsGnjYE8mYTLG0bB5Q3letmQBKbWKLU1EQS4AaoeE6H45nx8qjqPjmFgsEBw== X-Received: by 2002:a1c:6306:: with SMTP id x6mr6004123wmb.154.1606240815604; Tue, 24 Nov 2020 10:00:15 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id b4sm7837855wmc.1.2020.11.24.10.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 10:00:14 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Tue, 24 Nov 2020 17:59:34 +0000 Message-Id: <20201124175934.238358-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] pipeline: raspberrypi: Fix erroneous bayer buffer requeue on buffer matching X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Kieran Bingham Tested-by: David Plowman Tested-by: David Plowman --- .../pipeline/raspberrypi/raspberrypi.cpp | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 7271573a..fd306066 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1679,8 +1679,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 @@ -1695,20 +1710,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 @@ -1723,11 +1727,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 { /*