[{"id":33729,"web_url":"https://patchwork.libcamera.org/comment/33729/","msgid":"<20250326150504.GJ8303@pendragon.ideasonboard.com>","date":"2025-03-26T15:05:04","subject":"Re: [PATCH v2 2/3] ipa: libipa: agc_mean_luminance: Error out when\n\teffectiveExposureValue is zero","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Stefan,\n\nThank you for the patch.\n\nOn Wed, Mar 26, 2025 at 02:47:21PM +0100, Stefan Klug wrote:\n> In a proper system it never happens that the effectiveExposureValue\n> drops to zero. If that still happens due to a bug outside of\n> agc_mean_luminance, the calculated gain goes towards infinity but the\n> newExposureValue is still 0 because it is the result of multiplying the\n> effectiveExposureTime with the gain, leading to wild oscillations.\n> \n> Catch that condition, print an error message and set the new effective\n> exposure value to an arbitrary 10ms.\n> \n> Note that in any case the underlying problem must be fixed. The\n> important change is the added error message to be able to detect such a\n> situation.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> \n> Changes in v2:\n> - Collected tags\n> - Improved log message wording\n> - Added comment on the arbitrary exposure time\n> ---\n>  src/ipa/libipa/agc_mean_luminance.cpp | 12 ++++++++++++\n>  1 file changed, 12 insertions(+)\n> \n> diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\n> index 02555a44d271..f617fde81101 100644\n> --- a/src/ipa/libipa/agc_mean_luminance.cpp\n> +++ b/src/ipa/libipa/agc_mean_luminance.cpp\n> @@ -541,6 +541,18 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex,\n>  \tstd::shared_ptr<ExposureModeHelper> exposureModeHelper =\n>  \t\texposureModeHelpers_.at(exposureModeIndex);\n>  \n> +\tif (effectiveExposureValue == 0s) {\n> +\t\tLOG(AgcMeanLuminance, Error)\n> +\t\t\t<< \"Effective exposure value is 0. This is a bug in AGC \"\n> +\t\t\t   \"and must be fixed for proper operation.\";\n> +\t\t/*\n> +\t\t * Return an arbitrary exposure time > 0 to ensure regulation\n> +\t\t * doesn't get stuck with 0 in case the sensor driver allows a\n> +\t\t * min exposure of 0.\n> +\t\t */\n> +\t\treturn exposureModeHelper->splitExposure(10ms);\n> +\t}\n> +\n>  \tdouble gain = estimateInitialGain();\n>  \tgain = constraintClampGain(constraintModeIndex, yHist, gain);\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id EBE88C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Mar 2025 15:05:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A0B246896A;\n\tWed, 26 Mar 2025 16:05:27 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BB4668950\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Mar 2025 16:05:26 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 969E23A4;\n\tWed, 26 Mar 2025 16:03:38 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"KSQTaHN4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743001418;\n\tbh=RtB2jUtW25Eohx41a9TIkdn0ehCVTHHj/qDGspmFny4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=KSQTaHN44MQuYRAGcWgAsNZH18HmB+FGPxJj7BpHWAZGitn4x/342R8hyj4cPkEoM\n\tplPFaBKqhDyIfR8NSvMmvVl+c3ECHkzeaqJ4noy5Me6LD76tBLxJJdufEDfjh4vORu\n\t6P8iehiDsThNA2sG5GcmVq3ck5bezP+Ksc99lgOs=","Date":"Wed, 26 Mar 2025 17:05:04 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tDaniel Scally <dan.scally@ideasonboard.com>","Subject":"Re: [PATCH v2 2/3] ipa: libipa: agc_mean_luminance: Error out when\n\teffectiveExposureValue is zero","Message-ID":"<20250326150504.GJ8303@pendragon.ideasonboard.com>","References":"<20250326134727.279393-1-stefan.klug@ideasonboard.com>\n\t<20250326134727.279393-3-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250326134727.279393-3-stefan.klug@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]