From patchwork Wed Aug 5 10:03:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 27614 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 5A409C330A for ; Wed, 5 Aug 2026 10:05:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CF12C680DB; Wed, 5 Aug 2026 12:05:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="WH7T2xDm"; dkim-atps=neutral Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 05D5C6805D for ; Wed, 5 Aug 2026 12:05:07 +0200 (CEST) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-47f706438c3so65754f8f.3 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=1785924306; x=1786529106; 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=j6ulnDyYAT7qfuCOwZquqvKEPXSnAK8zUd75fPrc20M=; b=WH7T2xDmChFKp604Ou9mXqy+CMan3SmRipFyL83OwQzkQzDCV0bN4hlPYSlN5uV+3i OCAijaydEGdhslFnY6mes+JxuDIku6AzOaH6EMef1Q82KbrjZvXvEufoDeBpdHA2VtnX iiaptpJ9ysPyxt3d+hBSe2vVFGuOHexm8EA2v/h6zrA/OdVK8SKXAbWa/RZxpWYAEQ0a 1+OY9zJltiDf0/+kF7D0wcOYeCUqQ8+qtd7uplgKMZCUwxXV0ATOxv1QN7GLnbMb1sqs dKb+NOCKRhP+uRoF/eAcTsQcn51qRH1NKEXl2imhPjMh2YE4OxiK8fYdHgl0MG/NGlsQ 5W/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785924306; x=1786529106; 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=j6ulnDyYAT7qfuCOwZquqvKEPXSnAK8zUd75fPrc20M=; b=m6IBIZdXIhLPvzDoq4lP8avG3R7agLneNhy4SDL2VcqBtYpp+2DYnf0zi1d8dBgJys i0Tn1YVN7C2x16GwNRWX5IksLYjDUPslUL0tvKoV/NQmntxzMA4eMn4jMgDACMh5AtAP 7wUMnJl8PkbIlP7ItYwRh11fJ75ZBrIj06y3XT720lJOfFay1dAjgn/PeBdvWNvDV9DJ IhHpQ+SOn/o3GDfOaSssvIYzwG+hdPG0ZZ9nUmR5zF8kowyNvOfKHwauZIN1uEp6+Dm8 5fbLxhVwXA1MmKzh0E9iWmVq11MeOZDZWlqgZUrFIiyGFh1QPM5t/qs5A7Rw4eXf7Myc 0MeA== X-Gm-Message-State: AOJu0YzdJsZ1xcEAhgNISgCNVppTFk5QT6862xLPGcBh0VOM+bO9KE0Z BIvE9zKbWTYm363L7lgVs8bzZWAHR9B2kVu5M+F4ZmZo9OJ4Buu80aCRVdfWXX7BvUgh3UeeywU ypP0LBQo= X-Gm-Gg: AR+sD13aoPsyXOl50UTQ1H11C56KwqfT6eVB+otYGN0Fcx59HcYfTAC2hFEs+BXxSMd L0DT7gfHv+iVVxW0aPgvBvayxCecDs058/JbsQMc1MaHFitBCmucmQ8Xrk7owpUjqWxsc+2y8Yi pSZo2FTMvKSkaLo66E+chB7gGz4Rz2CdsW6urYNZDGnz7L8LItfznWqtG4y0jYCrC+oJfoZtikW DHqxN3AYiuzFy3RUIJ/6WcNzAlXcEvCsruqz95oFAOxWECrNZtv0/zxXPsM/8Hf97mYROyGxFLx 2pCFu1zpouPpLLW9TQQSPd/U4dJHNt0vFwMjoK1/IR2a5NHYN+9tl1WYqo7gF9FgVKzey454ETo dcQddur6vGWoxCzFW21fLNB3pmXR1fT4X8Fb6smBS9rucjjv07si781SQdf/WFIINu3OKHPBq8k UOi5mKlE+aF7rJfqHvQ97h5tsFPJxq3R06FB6rSgOmfbwz+LAdqPh50++1hDxBtDvH4KEOxU17G VT/lPRdJCB/nGpbgMAAQDm2OAxgyRjc+af8YUIzckSqLuEvnjpyVcpkttGCv/Jh7Xlo4qPsN0Wm P0zecssyem/Tk6jo563fmBkmmdel9pZcpu/NHXx86O7aWXuV7HqRqv+aPG1B/8qwHEHxhQZe151 uJNDMEhQVULgd4Z94t3y9NWSl X-Received: by 2002:a05:600c:1c22:b0:495:71ff:598d with SMTP id 5b1f17b1804b1-4994edf895dmr24833735e9.1.1785924306390; 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.05 (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 1/2] ipa: rpi: Rename mistrustFramesStartup() to mistrustMetadataStartup() Date: Wed, 5 Aug 2026 11:03:53 +0100 Message-ID: <20260805100502.1947139-2-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" This matches what the CamHelper member function actually advertises. Rename this to avoid any confusion when reading the code. Also reword some of the comments for the same reason. No functional changes in this commit. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham --- src/ipa/rpi/cam_helper/cam_helper.cpp | 4 ++-- src/ipa/rpi/cam_helper/cam_helper.h | 4 ++-- src/ipa/rpi/cam_helper/cam_helper_ov5647.cpp | 4 ++-- src/ipa/rpi/common/ipa_base.cpp | 5 ++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ipa/rpi/cam_helper/cam_helper.cpp b/src/ipa/rpi/cam_helper/cam_helper.cpp index dfdcd167839a..9afcf4bb52cf 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.cpp +++ b/src/ipa/rpi/cam_helper/cam_helper.cpp @@ -192,9 +192,9 @@ unsigned int CamHelper::hideFramesModeSwitch() const return 0; } -unsigned int CamHelper::mistrustFramesStartup() const +unsigned int CamHelper::mistrustMetadataStartup() const { - /* Many sensors return a single bad frame on start-up. */ + /* Many sensors return bad metadata on the first frame after start-up. */ return 1; } diff --git a/src/ipa/rpi/cam_helper/cam_helper.h b/src/ipa/rpi/cam_helper/cam_helper.h index bd101895f23e..3bbc74310670 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.h +++ b/src/ipa/rpi/cam_helper/cam_helper.h @@ -56,7 +56,7 @@ namespace RPiController { * 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. - * MistrustFramesStartup(): At start-up a sensor may return frames for + * mistrustMetadataStartup(): At start-up a sensor may return frames for * which we should not run any control algorithms (for example, metadata * may be invalid). * MistrustFramesModeSwitch(): The number of frames, after a mode switch @@ -96,7 +96,7 @@ public: virtual double getModeSensitivity(const CameraMode &mode) const; virtual unsigned int hideFramesStartup() const; virtual unsigned int hideFramesModeSwitch() const; - virtual unsigned int mistrustFramesStartup() const; + virtual unsigned int mistrustMetadataStartup() const; virtual unsigned int mistrustFramesModeSwitch() const; virtual unsigned int getMinDebinFactor() const; diff --git a/src/ipa/rpi/cam_helper/cam_helper_ov5647.cpp b/src/ipa/rpi/cam_helper/cam_helper_ov5647.cpp index 40d6b6d76452..f7d0515c8113 100644 --- a/src/ipa/rpi/cam_helper/cam_helper_ov5647.cpp +++ b/src/ipa/rpi/cam_helper/cam_helper_ov5647.cpp @@ -19,7 +19,7 @@ public: double gain(uint32_t gainCode) const override; unsigned int hideFramesStartup() const override; unsigned int hideFramesModeSwitch() const override; - unsigned int mistrustFramesStartup() const override; + unsigned int mistrustMetadataStartup() const override; unsigned int mistrustFramesModeSwitch() const override; private: @@ -68,7 +68,7 @@ unsigned int CamHelperOv5647::hideFramesModeSwitch() const return 2; } -unsigned int CamHelperOv5647::mistrustFramesStartup() const +unsigned int CamHelperOv5647::mistrustMetadataStartup() const { /* * First couple of frames are under-exposed and are no good for control diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index dacafa578c98..74517503ebc2 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -351,12 +351,11 @@ void IpaBase::start(const ControlList &controls, StartResult *result) frameCount_ = 0; if (firstStart_) { invalidCount_ = helper_->hideFramesStartup(); - mistrustCount_ = helper_->mistrustFramesStartup(); - + 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 statistics + * 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. */ 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!";