[{"id":31838,"web_url":"https://patchwork.libcamera.org/comment/31838/","msgid":"<87o73e7ic3.fsf@gmail.com>","date":"2024-10-20T18:13:36","subject":"Re: [PATCH v2 4/4] ipa: rkisp1: use active state in setControls","submitter":{"id":146,"url":"https://patchwork.libcamera.org/api/people/146/","name":"Mikhail Rudenko","email":"mike.rudenko@gmail.com"},"content":"On 2024-10-20 at 18:28 +03, Mikhail Rudenko <mike.rudenko@gmail.com> wrote:\n\n> The results of AGC algorithm currently travel a long way before being\n> actually applied. Let's consider the common case when 4 requests are\n> used and frames 0-3 are queued before start(). AGC is first run when\n> frame 0 stats are ready, and exposure/gain are saved in\n> activeState. Then, when frame 4 is queued, they are stored in\n> corresponding frameContext. Four frames later, frame 4 is captured,\n> and after processing the stats buffer, exposure/gain are extracted\n> from frameContext and queued to delayedControls in setControls(). On\n> frame 5, delayedControls apply them. Assuming a control delay of 2, the\n> settings will become effective for frame 7. So, it takes 7 frames for\n> the AGC algorithm to get feedback. This results in suboptimal\n> convergence rate.\n>\n> If we instead use just computed exposure/gain from the activeState in\n> setControls, the delay is reduced from 7 frames to 3 frames. Tests\n> on OV4689 sensor show faster convergence and no unwanted side effects.\n\nOops - forgot\nSigned-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>\n\n> ---\n>  src/ipa/rkisp1/rkisp1.cpp | 8 +++++---\n>  1 file changed, 5 insertions(+), 3 deletions(-)\n>\n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index 680a7eee..8793d59f 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -458,9 +458,11 @@ void IPARkISP1::setControls(unsigned int frame)\n>  \t * internal sensor delays and other timing parameters into account.\n>  \t */\n>\n> -\tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n> -\tuint32_t exposure = frameContext.agc.exposure;\n> -\tuint32_t gain = context_.camHelper->gainCode(frameContext.agc.gain);\n> +\tconst auto &agc = context_.activeState.agc;\n> +\tuint32_t exposure = agc.autoEnabled ?\n> +\t\t\t    agc.automatic.exposure : agc.manual.exposure;\n> +\tuint32_t gain = context_.camHelper->gainCode(agc.autoEnabled ?\n> +\t\t\t\t\t\t     agc.automatic.gain : agc.manual.gain);\n>\n>  \tControlList ctrls(sensorControls_);\n>  \tctrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure));\n\n\n--\nBest regards,\nMikhail Rudenko","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 F3367C3304\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 20 Oct 2024 18:14:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DE7FD65391;\n\tSun, 20 Oct 2024 20:14:08 +0200 (CEST)","from mail-lf1-x134.google.com (mail-lf1-x134.google.com\n\t[IPv6:2a00:1450:4864:20::134])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B07D765379\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 20 Oct 2024 20:14:07 +0200 (CEST)","by mail-lf1-x134.google.com with SMTP id\n\t2adb3069b0e04-539983beb19so3992922e87.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 20 Oct 2024 11:14:07 -0700 (PDT)","from razdolb (static.40.223.216.95.clients.your-server.de.\n\t[95.216.223.40]) by smtp.gmail.com with ESMTPSA id\n\t2adb3069b0e04-53a223efe8esm278635e87.71.2024.10.20.11.14.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 20 Oct 2024 11:14:06 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"iJSgl8lV\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20230601; t=1729448047; x=1730052847;\n\tdarn=lists.libcamera.org; \n\th=mime-version:message-id:in-reply-to:date:subject:cc:to:from\n\t:user-agent:references:from:to:cc:subject:date:message-id:reply-to;\n\tbh=dx9/efCFtdv+rJQUucTjiZgmoaGjuk6NoOvzSaFgQoM=;\n\tb=iJSgl8lVVRvgw1tcqbL5h8wMPCYB+pYuCSHSiQeGa5vSWcuaNu5rEboc8Im39Q/a3i\n\tcJrJvS/iJhMgYxKaUFYZZImUkh9Fet2hsQKuNlyVRUfeYA4CTUzILulQAlEVqTGDWxGW\n\tXjJp4W21Qvqj4nlV/nPjWZRwHmqlgSpUYYGgzZnnd+6WxLrJ37ip07MHfwuAVdtEyByG\n\tYC8VCQwhUXrYt3WJRznQQG1blPLDGsuQ2ujqkmsKlVKNZ/bofBusRnr0/SwRovxAYcal\n\tD+MqbaGSLoT3LS4OL+JY5zeiBvdeF0Cv+5rU3QuUkhWnRjythRY+5b7udj2tWhJzCnht\n\tZK6Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1729448047; x=1730052847;\n\th=mime-version:message-id:in-reply-to:date:subject:cc:to:from\n\t:user-agent:references:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=dx9/efCFtdv+rJQUucTjiZgmoaGjuk6NoOvzSaFgQoM=;\n\tb=qfI2I2UjmpfeBlcvpjxSQvXPdd45xDfeshiLSBwko4eQRAaQHtv3N5M7k0D9Vdcvf7\n\tVisZ2/jArjXVnr/zgTnTR1cMDesh3AMCb2QOUuFtKpdFlRqqASLZZH+FBgN17IoXxUOO\n\toknulbFVS5fqMt129R+q/epDJBLR1N6LRRD+iSn/siTzOT1vtO0RfcrVNFrb7rVY9Zuw\n\tU8Vycv0gvOvFylXnelkj56KxzCpfcHGY4g5dOulhn8+3yc3I6xkToLBM8M4yQShtWs2L\n\tbhslbleUu4jrwSrD8/t5XMHC4zzIdEGVmSShSQvjiAC79FxW1piqhi1nAyykyDX6NhMq\n\t3YuA==","X-Gm-Message-State":"AOJu0YwLrEn0zcm2fH8XnGKAh7cchnEJd2etryCA+ccLnsK+MfbAL//d\n\twa3Voanf6GIre+ky/cV0e4YfKSiYfvuyNoj0yGCTDGpo0kgXF2+xHFeBFg==","X-Google-Smtp-Source":"AGHT+IHE40SxVTYMAl++d58xa9M2gqJncIdninhyEUDPpXOT54RlWcuU8YZBefzPTzq07wmOd2TntA==","X-Received":"by 2002:a05:6512:31d2:b0:53a:1337:5ff7 with SMTP id\n\t2adb3069b0e04-53a154e79d3mr4089203e87.40.1729448046345; \n\tSun, 20 Oct 2024 11:14:06 -0700 (PDT)","References":"<20241020152821.240726-1-mike.rudenko@gmail.com>\n\t<20241020152821.240726-5-mike.rudenko@gmail.com>","User-agent":"mu4e 1.10.8; emacs 29.4.50","From":"Mikhail Rudenko <mike.rudenko@gmail.com>","To":"Mikhail Rudenko <mike.rudenko@gmail.com>","Cc":"libcamera-devel@lists.libcamera.org, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v2 4/4] ipa: rkisp1: use active state in setControls","Date":"Sun, 20 Oct 2024 21:13:36 +0300","In-reply-to":"<20241020152821.240726-5-mike.rudenko@gmail.com>","Message-ID":"<87o73e7ic3.fsf@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain","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>"}}]