From patchwork Wed Aug 5 10:03:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 27615 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 541C2BDE4C for ; Wed, 5 Aug 2026 10:05:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 63AC7680E1; Wed, 5 Aug 2026 12:05:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="msptuuwu"; dkim-atps=neutral Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 97AA867EC4 for ; Wed, 5 Aug 2026 12:05:07 +0200 (CEST) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-47fe76491b8so53956f8f.0 for ; Wed, 05 Aug 2026 03:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1785924307; x=1786529107; 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=NX+VNryi7ClnES/x00WaTDbiFcyGqPYItJpOJ4S8jqo=; b=msptuuwu05PmqD6cBN/QRU7JoeFKEe89RLPAXymp3jli1RQ71bKr847wXg4o3Ywg9+ 1jdOBgaS2JnS+fJMUA6jzCJPb195RJ1yi8UfNnmC9VkLLjVTW7RsJQv6HaUyzEoT8y+z x7H+s5aFU13VT+vun7VyLzSgL7o4Rsb2u9NTgTUwRjewTUQxhNgw2e2lEERoRpbsP4Zz mINdEaurU0favXUzQtKGKNIy2eFQAWZgqjK6bUzIGCllzs6TmpxsgwdOLYg/mTptg7xJ iFONEnr06tVGkMEU5Gaz3cuws/23pKYLOSbITQOyYiVeEMQtMHT5FDnqqIu6pZaMrqnW DRUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785924307; x=1786529107; 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=NX+VNryi7ClnES/x00WaTDbiFcyGqPYItJpOJ4S8jqo=; b=A7acoz6c3FxIt4JBMtoRGiFcP1r8XOX/2SgNOVlzeTSPNhniSl1tz1uk4T02ZejEfn arA0XBbU0TYA74k9obEq0iFlDszst2jYrFUlRYISH3xAH4Ii6gXzc2LTw4R89NejoxHR +BvLoYL/xDPVXrZyIOdR+UqIa1jn6tRVYbzZJnaEsnmTGgTWg522Ln6EE++QOrWVoJXA SV7IHPIH8Je3zzKHTDEkpy7PPXq0ZpBgu8Y5yOVob2YpyjCAF4K1ODjauXVNia+3/i+R h7OPWL+9VJ8MNDejZDWRY/AXrPYOfHc+hmK4YeIzff67VgkQTc0NLFn32bq8qL9Nb1Vs H9aQ== X-Gm-Message-State: AOJu0Yxoxsac/7Wko0cmkVTQtCa2UBVhsVzuoiKr+SjVzqN8T42R/mam NrtCRYa2rduWIXKpUJKrygElyL1vJflUYRBYyLzm3hN7vcZ6BJb7JbHbjqkUYEkN/AzLbzO/a6B yx7g2VqE= X-Gm-Gg: AR+sD13or1Q7a3s2sxTnrBbM3zfgr4mXiJaKw/xnaWUebp0KJ7MIYkKxF4I/p0yBxnW X+OUU8cdD9veCZOe1iEnDgX6yQZQRHJi1OIGlIPZCu4OIWCLk8GNN7n+KArqJXRt+7UHeZWrUyd Bcg58gqwGuzI/J1jHWCgNnd/LYQndOXeMtYu8kL0lJ6zn4ZNAUquzgmiTKecfKdvQHGene2JziM 9rz7MQKIRUvbjlbQeJgA9K7HJUFRnZ1j/4l/s1N5DD7XGQudRfqcJ0lpr5IE0EY3JKvMJrI5RYs iWmp8KUcEFFGr1mCLeLNlnvUdW4WDcl6Mt110Gq8k/nbWj9FifbjOiEm6gHtU68XgcxYp3nOmav WDDjWJJYnGv8NFpwM7lx9rndsxg2VgXKA27LZRgvW8q/Lxa4VIXLuKmVspOJdi1i9C+MzLr08d1 /m9nyaKDuAnlSeiGAJKQAPlvpzkKkJbTAN9nkTHHNzM2Je3F0hjgeYFyyZ7yHHVpGxQ/be6PqW8 IM7rasYOqDlEKoOpJxQRaBQ0iT3QNW0cUr7V785epGSr0qKYtbN+0ua1sKvJE8sP5UD8scAKlet 4GrKcDAvFE3sTld1pIQOPuptri/b0YQDsm4vcxtL3xm50fQ3NWZ3KO7Z9Uasg1jklitcLGD5Pmx +Qs8vwqJKUS1bvwzbwXR6bsLv X-Received: by 2002:a05:600c:4f8b:b0:493:ec89:db4a with SMTP id 5b1f17b1804b1-4994e70afd6mr30338845e9.0.1785924306998; Wed, 05 Aug 2026 03:05:06 -0700 (PDT) Received: from naush-dell.pitowers.org ([2a00:1098:3142:1f:7130:ff97:e57d:5cf8]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4994e04c2a1sm79185785e9.14.2026.08.05.03.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 03:05:06 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: david.plowman@raspberrypi.com, Naushir Patuck Subject: [PATCH v1 2/2] ipa: rpi: Gate CamHelper::prepare() by the mistrust count Date: Wed, 5 Aug 2026 11:03:54 +0100 Message-ID: <20260805100502.1947139-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260805100502.1947139-1-naush@raspberrypi.com> References: <20260805100502.1947139-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 somwhat incorrect, as the image data is ineed 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 74517503ebc2..46f35470be99 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -354,26 +354,17 @@ void IpaBase::start(const ControlList &controls, StartResult *result) mistrustCount_ = helper_->mistrustMetadataStartup(); /* * 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_->mistrustFramesModeSwitch(); @@ -469,8 +460,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); @@ -526,7 +520,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!";