From patchwork Wed Aug 5 14:09:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 27619 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 ACF8FC3334 for ; Wed, 5 Aug 2026 14:12:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ADD5868116; Wed, 5 Aug 2026 16:12:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="EMSYUl+G"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5EC9C68103 for ; Wed, 5 Aug 2026 16:12:01 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-4731f5ffa74so69627f8f.1 for ; Wed, 05 Aug 2026 07:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1785939121; x=1786543921; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+QaiyA6Di1yFBuTZ62W2vJ2BamTuFqMtU/6Mg7atVXU=; b=EMSYUl+GW0v9BbjaEnt1ZvJ24NZ4lW9gb3H+OSl+xdDV6IPVODiwEYUvpuZyvXRQeY eUASqieURsuZuJYDpd82eXl5Icv1TU7LTc/l/XvlL4+wYKq/T4+jFJDcespytrwEKPhJ A99oQB1z2JsL1p7l+xTHcx0HFrMJjNP/h+R82+66FNMIAPIvWEGKEYoCimfRXCSSrdHq ACSj7IgFyKC5DXoR5lpd9HwsbGzq1A3iML21rGj6YgO+8cEW9f+BxZRQC3414P9Kc+85 WKLI3YNf+C9uYV3jBdKzhldm3cRL/a1cKQTLgs5QRpouWAQi2BONyjlVieFSwDtKQYin ZIkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785939121; x=1786543921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+QaiyA6Di1yFBuTZ62W2vJ2BamTuFqMtU/6Mg7atVXU=; b=lgy6yW//EmI52wbMZLcyBFiIv/dv0YVjGL2QRAYci7HyfJ16RPTnYhvpbv/3V1XSsC qsQhZkb8GKCdOeQlQHCYEazH/S1g5g56tk3Z+QEqocaTaskeAFp/MFmtouhAWupQ//Go qXQK84W0tUu3Pv5gfRb/A0uZeAMERQkc6Y926Pvfl+GbJLeo9zORv9fZVG+zbds4IQWL D7DSfzsDLyWtC4eEZfr0EfESZLR4Eqn50+jqvKanWfkCU+65HLK2/bKpXuez8nwZ2oOo nJqNaBqCj/wLLOJP4gTQNLIzoPIClD0LKImHM3MtjLrvCsRrPGw/L97dxUbbMqj6EPoN e4ZQ== X-Gm-Message-State: AOJu0Yy6yfdZTmiFfGSndYM3rzYLeZC1IcLD8a2FN/a/niJuF4emJyRr ka7ZuERoxAmilprd7zDafZ+6VhVg4SEoNraXMegQsejQON9OjkvwadSdTi9v03w4A2LZtrkzYt8 nMfVhmtY= X-Gm-Gg: AR+sD13D2ms05b7XGcpPV1urxT6gVpeJ78DZGUOnQjoiCYPDj3moI8YFFKSLBrs7I79 SuctL1dtjb5HEzNyiLuomCqLqZdEBTKLrdVo8pVTjX1hH3pvQUSwUM53BvS+mjNn6dPVKs9L1gZ DPKajUCT71sWrIhKMXLWJ22lh1Zv7PyqmuDiYuANn+VirxzG/G/3wfULp/6qQ0GHM/iQKctp9f1 72nkCNR7eb3TopheVwjsAzLYrbeFqGYr2gcW+DYWNwTF9mOj/DMerwHftqUuBuFZjFXUNKxVN2G dibYfDyeC1k4k+WNnk4ezU+v/6TAqDaI5jpPsBKXmVNKDR1x8l+HzUZ5aXq4Xh2DgCboeUQyDAu kZw9gw9G95Ce5igaUtDJ8VEe0WTmcQVcbtRouXju4uApKHCFBaIpUhDTflzuwHeQI+JaOqYVvif Y1n73S/CbL6S7vhJw+6YEWuQELcE8yfaGKYPBnUMePm0dGGdd7UzP2JHrunHv7nHHgfhOw/z6bc ZSIEBWFaAmrZjHeM3Sz5Krg5bgHzvxtM+hKN+WYQZZ5RkdpK/qT0U9eVj0p9jP3W3qJFbfQ4m5c kkki4pUwp6///qGo5xayUv6jfamN2/YUPnoZooY/aMzuN1XJ/2+6qcwJikGs9OxWhD9qWGdHIav ngm2WaBvD5XF38RQfbkecq6YV X-Received: by 2002:a05:6000:290a:b0:47f:7526:5a0 with SMTP id ffacd0b85a97d-47fec47628bmr6070546f8f.0.1785939120736; Wed, 05 Aug 2026 07:12:00 -0700 (PDT) Received: from naush-dell.pitowers.org ([2a00:1098:3142:1f:7130:ff97:e57d:5cf8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47febfda0d7sm8807952f8f.2.2026.08.05.07.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 07:12:00 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Kieran Bingham , David Plowman Subject: [PATCH v2 2/2] ipa: rpi: Gate CamHelper::prepare() by the mistrust count Date: Wed, 5 Aug 2026 15:09:22 +0100 Message-ID: <20260805141156.2092208-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260805141156.2092208-1-naush@raspberrypi.com> References: <20260805141156.2092208-1-naush@raspberrypi.com> 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" The current logic in the IPA gates the controller/algorithms from running on a the frame if mistrustCount_ > 0. This logic is somewhat incorrect, as the image data is indeed valid, just the embedded data and other bits of metadata are possibly invalid. This commit changes the gating so that the controller/algorithms do run on frames where mistrustCount_ > 0, and CamHelper::prepare() gets gated. CamHelper::prepare() is where the embedded data parsing occurs, and if it does not run, we simply use the DelayedControls values provided by the pipeline handler. Bug: https://github.com/raspberrypi/libcamera/issues/345 Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: David Plowman --- src/ipa/rpi/common/ipa_base.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index aa17d39fea7b..7e00c2799b4e 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -355,26 +355,17 @@ void IpaBase::start(const ControlList &controls, StartResult *result) /* * Query the AGC/AWB for how many frames they may take to - * converge sufficiently. Where these numbers are non-zero - * we must allow for the frames with bad metadata - * (mistrustCount_) that they won't see. But if zero (i.e. - * no convergence necessary), no frames need to be dropped. + * converge sufficiently. */ RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.getAlgorithm("agc")); - if (agc) { + if (agc) agcConvergenceFrames = agc->getConvergenceFrames(); - if (agcConvergenceFrames) - agcConvergenceFrames += mistrustCount_; - } RPiController::AwbAlgorithm *awb = dynamic_cast( controller_.getAlgorithm("awb")); - if (awb) { + if (awb) awbConvergenceFrames = awb->getConvergenceFrames(); - if (awbConvergenceFrames) - awbConvergenceFrames += mistrustCount_; - } } else { invalidCount_ = helper_->hideFramesModeSwitch(); mistrustCount_ = helper_->mistrustMetadataModeSwitch(); @@ -470,8 +461,11 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms) /* * This may overwrite the DeviceStatus using values from the sensor * metadata, and may also do additional custom processing. + * + * Only call CamHelper::prepare() when we know the metadata can be trusted. */ - helper_->prepare(embeddedBuffer, rpiMetadata); + if (frameCount_ >= mistrustCount_) + helper_->prepare(embeddedBuffer, rpiMetadata); bool delayedRequestControls = false; delayedMetadata.get("ipa.request_controls", delayedRequestControls); @@ -527,7 +521,7 @@ void IpaBase::processStats(const ProcessParams ¶ms) unsigned int ipaContext = params.ipaContext % rpiMetadata_.size(); RPiController::Metadata &rpiMetadata = rpiMetadata_[ipaContext]; - if (processPending_ && frameCount_ >= mistrustCount_) { + if (processPending_) { auto it = buffers_.find(params.buffers.stats); if (it == buffers_.end()) { LOG(IPARPI, Error) << "Could not find stats buffer!";