From patchwork Mon Aug 10 10:38:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27702 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 D1333BDE4C for ; Mon, 10 Aug 2026 10:39:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 524FA68231; Mon, 10 Aug 2026 12:39:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="g9d20P7X"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 304E0681DA for ; Mon, 10 Aug 2026 12:38:57 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 354B7887 for ; Mon, 10 Aug 2026 12:37:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786358263; bh=Lp+fzoEK4Oc0Q84BfXk/kSZWF/Qs328pvpBYMIjiHLQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=g9d20P7XJMeangkdo1WB/6WyG/Fu/6okt2bPWsWDaI+ieThiojEuoh0OU0aPSf0Mg 4xZG9aKRT1oQtJtc/Q2NwDo1AMxuK1zbYjWo4JLZU9avW3FZ3s89SpYT7xKCBGYb/V 1A+cUzyuf1x1QIYZEGpRAksg0ywyIiUR52mBc/hc= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v4 29/49] ipa: libipa: agc: Calculate vblank and frame duration sooner Date: Mon, 10 Aug 2026 12:38:25 +0200 Message-ID: <20260810103846.1075936-30-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810103846.1075936-1-barnabas.pocze@ideasonboard.com> References: <20260810103846.1075936-1-barnabas.pocze@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" Calculating the vblank and frame duration is problematic in `process()` because at the moment it is calculated for an already finished frame based on the new suggested exposure time. Instead, move the calculation to `prepare()` where the frame's exposure and gain are finalized. Signed-off-by: Barnabás Pőcze --- src/ipa/libipa/agc.cpp | 29 ++++++++++++++--------------- src/ipa/libipa/agc.h | 3 ++- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp index def60a8570..8e141a3a53 100644 --- a/src/ipa/libipa/agc.cpp +++ b/src/ipa/libipa/agc.cpp @@ -504,7 +504,7 @@ void AgcAlgorithm::queueRequest(const agc::Session &session, agc::ActiveState &s /** * \brief Handle a \a prepare operation */ -void AgcAlgorithm::prepare(agc::ActiveState &state, agc::FrameContext &frameContext) +void AgcAlgorithm::prepare(const agc::Session &session, agc::ActiveState &state, agc::FrameContext &frameContext) { uint32_t activeAutoExposure = state.automatic.exposure; double activeAutoGain = state.automatic.gain; @@ -535,6 +535,19 @@ void AgcAlgorithm::prepare(agc::ActiveState &state, agc::FrameContext &frameCont } frameContext.yTarget = state.automatic.yTarget; + + /* + * Expand the target frame duration so that we do not run faster than + * the minimum frame duration when we have short exposures. + */ + const auto frameDuration = std::max( + frameContext.minFrameDuration / session.lineDuration, + frameContext.exposure); + frameContext.vblank = frameDuration - session.sensor.outputSize.height; + + /* Update frame duration accounting for line length quantization. */ + frameContext.frameDuration = + (session.sensor.outputSize.height + frameContext.vblank) * session.lineDuration; } /** @@ -545,7 +558,6 @@ void AgcAlgorithm::process(const agc::Session &session, agc::ActiveState &state, ControlList &metadata) { const utils::Duration &lineDuration = session.lineDuration; - utils::Duration newExposureTime = {}; if (params) { ASSERT(session.autoAllowed); @@ -605,8 +617,6 @@ void AgcAlgorithm::process(const agc::Session &session, agc::ActiveState &state, state.automatic.digitalGain = newEv.digitalGain; state.automatic.yTarget = newEv.yTarget; - newExposureTime = newEv.exposureTime; - LOG(Agc, Debug) << "exposure-time:" << utils::Duration(state.automatic.exposure * lineDuration) << " analogue-gain:" << state.automatic.gain @@ -614,17 +624,6 @@ void AgcAlgorithm::process(const agc::Session &session, agc::ActiveState &state, << " digital-gain:" << state.automatic.digitalGain; } - /* - * Expand the target frame duration so that we do not run faster than - * the minimum frame duration when we have short exposures. - */ - const auto frameDuration = std::max(frameContext.minFrameDuration, newExposureTime); - frameContext.vblank = (frameDuration / lineDuration) - session.sensor.outputSize.height; - - /* Update frame duration accounting for line length quantization. */ - frameContext.frameDuration = - (session.sensor.outputSize.height + frameContext.vblank) * lineDuration; - metadata.set(controls::AnalogueGain, frameContext.gain); metadata.set(controls::ExposureTime, utils::Duration(lineDuration * frameContext.exposure).get()); diff --git a/src/ipa/libipa/agc.h b/src/ipa/libipa/agc.h index 728f25911c..d02dbff562 100644 --- a/src/ipa/libipa/agc.h +++ b/src/ipa/libipa/agc.h @@ -129,7 +129,8 @@ public: void queueRequest(const agc::Session &session, agc::ActiveState &state, agc::FrameContext &frameContext, const ControlList &controls); - void prepare(agc::ActiveState &state, agc::FrameContext &frameContext); + void prepare(const agc::Session &session, agc::ActiveState &state, + agc::FrameContext &frameContext); struct ProcessParams { const AgcMeanLuminance::Traits &traits;