From patchwork Wed Mar 26 13:47:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23055 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 155B3C323E for ; Wed, 26 Mar 2025 13:48:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C52336896E; Wed, 26 Mar 2025 14:48:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rCin/vsD"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5280A68964 for ; Wed, 26 Mar 2025 14:48:04 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b21a:42f4:9f3:1df6]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F03843A4; Wed, 26 Mar 2025 14:46:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1742996776; bh=BBIXwgL7wCZ3yqDdcm03SAcC3tWc9l5qtdDfFPoqbGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rCin/vsD9OWHjNjXBXakrIYNB4QMrjtOMkAdcUwBz+CsX5qnFhBjHiD5kBLa3uAqF cZIp/UstPtbBjSkE5rSkEoKXYHaQnMHle3csm74cxqA3v1zhehLiGLlh3tBeCCRSU/ e5R78XMOsFVsOfDhCmoXMMWu/IzxUBkkEMRsBwt4= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham , Laurent Pinchart Subject: [PATCH v2 1/3] ipa: rkisp1: Add debug log for the sensor controls being set Date: Wed, 26 Mar 2025 14:47:20 +0100 Message-ID: <20250326134727.279393-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250326134727.279393-1-stefan.klug@ideasonboard.com> References: <20250326134727.279393-1-stefan.klug@ideasonboard.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" In the algorithm code a lot of information is logged in debug log level, but there is no place where the values sent to the sensor get logged. Add such a log message. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- Changes in v2: - Improved commit message - Improved log message and formatting - Collected tags --- src/ipa/rkisp1/rkisp1.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 7547d2f274f4..cb487ae53aef 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -455,6 +455,10 @@ void IPARkISP1::setControls(unsigned int frame) uint32_t gain = context_.camHelper->gainCode(frameContext.agc.gain); uint32_t vblank = frameContext.agc.vblank; + LOG(IPARkISP1, Debug) + << "Set controls for frame " << frame << ": exposure " << exposure + << ", gain " << frameContext.agc.gain << ", vblank " << vblank; + ControlList ctrls(sensorControls_); ctrls.set(V4L2_CID_EXPOSURE, static_cast(exposure)); ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain)); From patchwork Wed Mar 26 13:47:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23056 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 41EADC323E for ; Wed, 26 Mar 2025 13:48:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F2B4E68970; Wed, 26 Mar 2025 14:48:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tnsDth5l"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A66468967 for ; Wed, 26 Mar 2025 14:48:06 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b21a:42f4:9f3:1df6]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 95BF699F; Wed, 26 Mar 2025 14:46:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1742996778; bh=6luTqO35Q4YvGzgS3ENS17inTWGD0bIMd/vgI/zWHBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tnsDth5lpBrhdxYgbFHR8lpiLMoOldlzpdElwzH0qLEXjNJBxqn6FQ+lFB2fTpZug qlrMVfnv9nHMtHHjKrhdAsHFbJZSsOUvlS8EePDLnWpGPAdo6ntf+lLSdE8R9hkrlI 14O4Md+wFIXAN3glrBZEoyfzicHZuOhzuArAFa3s= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Daniel Scally Subject: [PATCH v2 2/3] ipa: libipa: agc_mean_luminance: Error out when effectiveExposureValue is zero Date: Wed, 26 Mar 2025 14:47:21 +0100 Message-ID: <20250326134727.279393-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250326134727.279393-1-stefan.klug@ideasonboard.com> References: <20250326134727.279393-1-stefan.klug@ideasonboard.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" In a proper system it never happens that the effectiveExposureValue drops to zero. If that still happens due to a bug outside of agc_mean_luminance, the calculated gain goes towards infinity but the newExposureValue is still 0 because it is the result of multiplying the effectiveExposureTime with the gain, leading to wild oscillations. Catch that condition, print an error message and set the new effective exposure value to an arbitrary 10ms. Note that in any case the underlying problem must be fixed. The important change is the added error message to be able to detect such a situation. Signed-off-by: Stefan Klug Reviewed-by: Daniel Scally Reviewed-by: Laurent Pinchart --- Changes in v2: - Collected tags - Improved log message wording - Added comment on the arbitrary exposure time --- src/ipa/libipa/agc_mean_luminance.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index 02555a44d271..f617fde81101 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -541,6 +541,18 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex, std::shared_ptr exposureModeHelper = exposureModeHelpers_.at(exposureModeIndex); + if (effectiveExposureValue == 0s) { + LOG(AgcMeanLuminance, Error) + << "Effective exposure value is 0. This is a bug in AGC " + "and must be fixed for proper operation."; + /* + * Return an arbitrary exposure time > 0 to ensure regulation + * doesn't get stuck with 0 in case the sensor driver allows a + * min exposure of 0. + */ + return exposureModeHelper->splitExposure(10ms); + } + double gain = estimateInitialGain(); gain = constraintClampGain(constraintModeIndex, yHist, gain); From patchwork Wed Mar 26 13:47:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23057 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 ABBC9C323E for ; Wed, 26 Mar 2025 13:48:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 20ED86896D; Wed, 26 Mar 2025 14:48:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DDpBNUoo"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7D49468964 for ; Wed, 26 Mar 2025 14:48:09 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b21a:42f4:9f3:1df6]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9462799F; Wed, 26 Mar 2025 14:46:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1742996781; bh=vI0X0RDILVuDMCMVsAD/8Clca34G1KZ9jz1acYNE5jw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DDpBNUoo7rD7RHbc6Bgr8/TaeJ3p2LWKpz2ut+ndzKZHeO83GWx7q1ipCUqI/hx15 ravWxcuPTPOvTA251GBg7cDjxI3IPNEXT44o+mw1hOBt9pyb9tYuzJ13cip5bmiYj6 BoGFIxdF8Z+gGzDYqsxMQgrsUoqXfGJMtnQYw1wo= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham , Laurent Pinchart Subject: [PATCH v2 3/3] ipa: rksip1: Remove setControls(0) to reduce startup oscillations Date: Wed, 26 Mar 2025 14:47:22 +0100 Message-ID: <20250326134727.279393-4-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250326134727.279393-1-stefan.klug@ideasonboard.com> References: <20250326134727.279393-1-stefan.klug@ideasonboard.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 call to setControls(0) is counter productive. At start() time, no requests were queued and no stats were received. So setControls(0) accesses a zeroed frame context and in turn sends 0 as gain, exposure and vblank to the pipeline handler and DelayedControls. This leads to strong oscillations on every start of the camera. A proper fix for handling the startup controls still needs to be done and was already started in [1] and [2]. From a DelayedControls point of view the call to setControls(0) is also unnecessary as DelayedControls treat frame 0 as already being queued in after initialization. So it is safe to just remove it and the removal fixes the zero effectiveExposureValue discussed in the previous patch for rkisp1. [1]: https://patchwork.libcamera.org/patch/21708/ [2]: https://patchwork.libcamera.org/patch/22445/ Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- Changes in v2: - Collected tags - Added \todo regarding startup controls --- src/ipa/rkisp1/rkisp1.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index cb487ae53aef..70ce0cba22df 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -211,8 +211,7 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision, int IPARkISP1::start() { - setControls(0); - + /* \todo Properly handle startup controls. */ return 0; }