From patchwork Sun Oct 20 15:28:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 21710 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 97E4FC3304 for ; Sun, 20 Oct 2024 15:28:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B23DF65396; Sun, 20 Oct 2024 17:28:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Qfwk73r8"; dkim-atps=neutral Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 126DA6538F for ; Sun, 20 Oct 2024 17:28:41 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-53a007743e7so4302947e87.1 for ; Sun, 20 Oct 2024 08:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729438120; x=1730042920; 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; bh=4bm5r3CB3RWzDN5kuKb8SsqCek9pBMr5+Wpi3nt0Qxo=; b=Qfwk73r84L5sZL76nTUCHZVJhclVPjOMbBP9uUoKMDU6nVJYr5i9o6rVose7ZShAot nevVPZ/o87UFnR6ENlC81zk0btO6YGwWaKhO1IunB4WqQnvpXX/3giWPycw3zSwRT9MJ /IUPHotAeWQopRwEuk5qymICZ2FfWIAxYkufN6AgbGQ/Kq3B52e/8Op530cuFU93I+RV fgKwldbpoHYXf+2IeAVhCaLrbYnV42zazRqlZoE1m0LHs3um9l3IkKlBRgwpWb9pB0Ll +GKfLFDkVwP5Qm540nbtwvaDpLBla5Qp8O8gqOp1F+CxrX2Hp5QqUGraCB/apMBaer1a zGLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729438120; x=1730042920; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4bm5r3CB3RWzDN5kuKb8SsqCek9pBMr5+Wpi3nt0Qxo=; b=BsuLU41eBDKXscaaCutJPWl7b9ctSKao+LE9Dab3Izz1yoxEjYuNrNDnG3lZqP5pHb Ydmrm/sUPDXcS8LGjotiS5m1kR31o3eaLouC/+I5JY68y1Rgyf+nE7j99To8KZyxdnxZ HZ3xI6xqFT3waen/dxIzvX+Osglgje52vWe8BUbE3BH0v/pVnYFc7MxFTxFveJPWbn1r Zqyw6roMfdLf4jZxQSks3R0MhsWF2TGROvxAqh4xprlUev7FjMuyaDM+/AlW6PPM3bhE xfYNNCwTTMFIMR/oM/F35y7shkXTPDH7wNsQ6Aowdzce4v+euFY5f0A6egeWMjmYKzXc Fz2Q== X-Gm-Message-State: AOJu0YwF1Dq/t910ZvofV84GAVTmwPihksqkfFfOxf3w04iiAG3unT5F zHJGsGotXTUM55Dtdl8uf+yOmC4BNIR3kxdIacfRIAxgpOW4Qvcp19ph4A== X-Google-Smtp-Source: AGHT+IEPzDLJMBOGzCG9Gh1E7eTFZPF1IHuHkMRl0nizwqSjznyvj4d0Mq24potc+G55Vtw5DxOokQ== X-Received: by 2002:a05:6512:124c:b0:539:e873:6d7 with SMTP id 2adb3069b0e04-53a154410e0mr4051767e87.1.1729438119775; Sun, 20 Oct 2024 08:28:39 -0700 (PDT) Received: from localhost.localdomain (static.40.223.216.95.clients.your-server.de. [95.216.223.40]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53a223efad4sm249040e87.67.2024.10.20.08.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 08:28:39 -0700 (PDT) From: Mikhail Rudenko To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Mikhail Rudenko Subject: [PATCH v2 4/4] ipa: rkisp1: use active state in setControls Date: Sun, 20 Oct 2024 18:28:21 +0300 Message-ID: <20241020152821.240726-5-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241020152821.240726-1-mike.rudenko@gmail.com> References: <20241020152821.240726-1-mike.rudenko@gmail.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 results of AGC algorithm currently travel a long way before being actually applied. Let's consider the common case when 4 requests are used and frames 0-3 are queued before start(). AGC is first run when frame 0 stats are ready, and exposure/gain are saved in activeState. Then, when frame 4 is queued, they are stored in corresponding frameContext. Four frames later, frame 4 is captured, and after processing the stats buffer, exposure/gain are extracted from frameContext and queued to delayedControls in setControls(). On frame 5, delayedControls apply them. Assuming a control delay of 2, the settings will become effective for frame 7. So, it takes 7 frames for the AGC algorithm to get feedback. This results in suboptimal convergence rate. If we instead use just computed exposure/gain from the activeState in setControls, the delay is reduced from 7 frames to 3 frames. Tests on OV4689 sensor show faster convergence and no unwanted side effects. Signed-off-by: Mikhail Rudenko --- src/ipa/rkisp1/rkisp1.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) -- 2.46.0 diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 680a7eee..8793d59f 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -458,9 +458,11 @@ void IPARkISP1::setControls(unsigned int frame) * internal sensor delays and other timing parameters into account. */ - IPAFrameContext &frameContext = context_.frameContexts.get(frame); - uint32_t exposure = frameContext.agc.exposure; - uint32_t gain = context_.camHelper->gainCode(frameContext.agc.gain); + const auto &agc = context_.activeState.agc; + uint32_t exposure = agc.autoEnabled ? + agc.automatic.exposure : agc.manual.exposure; + uint32_t gain = context_.camHelper->gainCode(agc.autoEnabled ? + agc.automatic.gain : agc.manual.gain); ControlList ctrls(sensorControls_); ctrls.set(V4L2_CID_EXPOSURE, static_cast(exposure));