From patchwork Fri Nov 20 06:47:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danius Kalvaitis X-Patchwork-Id: 29058 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 71D41C3355 for ; Fri, 20 Nov 2026 06:48:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 78E316A932; Fri, 20 Nov 2026 07:48:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=kurokesu.com header.i=@kurokesu.com header.b="JjQt6VtD"; dkim-atps=neutral Received: from srv2.kurokesu.com (srv2.kurokesu.com [89.47.166.45]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E3726A8C7 for ; Fri, 20 Nov 2026 07:48:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by srv2.kurokesu.com (Postfix) with ESMTP id 598387BAD; Fri, 20 Nov 2026 08:48:49 +0200 (EET) Authentication-Results: srv2.kurokesu.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=kurokesu.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurokesu.com; h= content-transfer-encoding:mime-version:x-mailer:message-id:date :date:subject:subject:from:from; s=default; t=1795157328; x= 1796971729; bh=XijLfMozMXb97DHwDuQnLpNdOX1ltkjqRM+PS8HdOUM=; b=J jQt6VtDYvTcBoYDll/qQUa7BNq9A0+butfrhLTI4n78RvANW2SImZCninZgxrHVS ADfXe9a8hy5b8sLDYcfu7j79LuqhH/sVNmMBcAcNq+4W8Nz0YiRtUJu4G/RMQQpD 3GP7BvS155gPtHbQrj7BkCNs+RuEtihOSlAXgkZl48= X-Virus-Scanned: Debian amavisd-new at srv2.kurokesu.com Received: from srv2.kurokesu.com ([127.0.0.1]) by localhost (srv2.kurokesu.com [127.0.0.1]) (amavisd-new, port 10026) with LMTP id AMZkUQYpRiGL; Fri, 20 Nov 2026 08:48:48 +0200 (EET) Received: from shelfpi.vpn2.kurokesu.com (unknown [84.15.183.117]) (Authenticated sender: danius@kurokesu.com) by srv2.kurokesu.com (Postfix) with ESMTPSA id 6BCCA7BA8; Fri, 20 Nov 2026 08:48:48 +0200 (EET) From: Danius Kalvaitis To: libcamera-devel@lists.libcamera.org Cc: naush@raspberrypi.com, david.plowman@raspberrypi.com, Danius Kalvaitis Subject: [PATCH] ipa: rpi: Ignore hidden frame statistics Date: Fri, 20 Nov 2026 08:47:51 +0200 Message-ID: <20261120064751.20056-1-danius@kurokesu.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 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" Control algorithms currently run on frames with mistrusted metadata, so AGC reacts to statistics of hidden start-up frames. Those hidden after a mode switch have also not been accounted for. Fixes: 93bed4da915c ("ipa: rpi: Gate CamHelper::prepare() by the mistrust count") Signed-off-by: Danius Kalvaitis --- Tested on a Raspberry Pi CM5 with imx462 in a bright scene. Without this patch, AGC acts on hidden frame statistics after a mode switch and applications receive one dark frame. At start-up the dip lands only on frames flagged FrameStartup, but settled exposure reaches applications 2 frames later. With this patch, both dips are gone. A mode switch takes 2 frames longer to settle, as AGC no longer makes an oversized step toward its target. src/ipa/rpi/cam_helper/cam_helper.h | 4 ++-- src/ipa/rpi/common/ipa_base.cpp | 10 +++++++++- src/ipa/rpi/common/ipa_base.h | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ipa/rpi/cam_helper/cam_helper.h b/src/ipa/rpi/cam_helper/cam_helper.h index bbaf57a1f..2ed36b641 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.h +++ b/src/ipa/rpi/cam_helper/cam_helper.h @@ -51,8 +51,8 @@ namespace RPiController { * modules may produce one or more frames that are not yet correctly exposed, * or where the metadata may be suspect. We have the following functions: * HideFramesStartup(): Tell the pipeline handler not to return this many - * frames at start-up. This can also be used to hide initial frames - * while the AGC and other algorithms are sorting themselves out. + * frames at start-up. Statistics from frames hidden at start-up or + * after a mode switch are not passed to the control algorithms. * HideFramesModeSwitch(): Tell the pipeline handler not to return this * many frames after a mode switch (other than start-up). Some sensors * may produce innvalid frames after a mode switch; others may not. diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index c28483444..ae3077cd1 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -373,6 +373,7 @@ void IpaBase::start(const ControlList &controls, StartResult *result) result->startupFrameCount = std::max({ agcConvergenceFrames, awbConvergenceFrames }); result->invalidFrameCount = invalidCount_; + hiddenFrameCount_ = invalidCount_; invalidCount_ = std::max({ invalidCount_, agcConvergenceFrames, awbConvergenceFrames }); @@ -467,6 +468,12 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms) if (frameCount_ >= mistrustCount_) helper_->prepare(embeddedBuffer, rpiMetadata); + /* + * Without inline statistics, processStats() runs after frameCount_ has + * been incremented, so record here whether this frame is hidden. + */ + hiddenFrame_ = frameCount_ < hiddenFrameCount_; + bool delayedRequestControls = false; delayedMetadata.get("ipa.request_controls", delayedRequestControls); @@ -534,7 +541,8 @@ void IpaBase::processStats(const ProcessParams ¶ms) rpiMetadata.set("focus.status", statistics->focusRegions); helper_->process(statistics, rpiMetadata); - controller_.process(statistics, &rpiMetadata); + if (!hiddenFrame_) + controller_.process(statistics, &rpiMetadata); } struct AgcStatus agcStatus; diff --git a/src/ipa/rpi/common/ipa_base.h b/src/ipa/rpi/common/ipa_base.h index 0d7842f1f..6dc049ca2 100644 --- a/src/ipa/rpi/common/ipa_base.h +++ b/src/ipa/rpi/common/ipa_base.h @@ -122,12 +122,18 @@ private: /* Number of frames that need to be marked as dropped on startup. */ unsigned int invalidCount_; + /* Frames hidden by the camera helper, a subset of invalidCount_. */ + unsigned int hiddenFrameCount_; + /* Frame timestamp for the last run of the controller. */ uint64_t lastRunTimestamp_; /* Do we run a Controller::process() for this frame? */ bool processPending_; + /* Is this frame hidden by the camera helper? */ + bool hiddenFrame_; + /* Distinguish the first camera start from others. */ bool firstStart_;