From patchwork Fri Jan 30 08:09:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 26053 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 14EF9C3226 for ; Fri, 30 Jan 2026 08:10:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE35D61FDC; Fri, 30 Jan 2026 09:10:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HBn5eddS"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4EB0661FD1 for ; Fri, 30 Jan 2026 09:09:59 +0100 (CET) Received: from neptunite.hamster-moth.ts.net (unknown [IPv6:2404:7a81:160:2100:ec11:5e0c:deb8:1e2d]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 098FA1E23; Fri, 30 Jan 2026 09:09:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1769760561; bh=YkNHzAtu2r5UXKdVQG7lH8PyiJgdwYF3NoBj50v0SYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HBn5eddSzx/xcQZmdW1Tcp0QKPqmq9dk/8bKJ6mMK1k5qJkZfLOQ5Wk6cYrLD2lAV 2gucpoZd+teRl3/8eMC3CiuUdrHeJK+Q4C2pi1qLp0fUISgt4vWfRUvvg5/dKB/stT /b13dWhD/5BVnZWNsJ+IP7ZDLNRIizCee37bYUVo= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , david.plowman@raspberrypi.com, naush@raspberrypi.com, kieran.bingham@ideasonboard.com, stefan.klug@ideasonboard.com Subject: [PATCH v2 4/4] ipa: rkisp1: agc: Add support for sync Date: Fri, 30 Jan 2026 17:09:35 +0900 Message-ID: <20260130080935.2569621-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20260130080935.2569621-1-paul.elder@ideasonboard.com> References: <20260130080935.2569621-1-paul.elder@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" Add sync support to the RkISP1 IPA using the SyncHelper from libipa. The syncAdjustment is saved in the frameContext (as opposed to getting it from the SyncHelper) to avoid potential races and ensure that the same value that was set into vblank will be returned in metadata. Signed-off-by: Paul Elder --- Changes in v2: - move SyncHelper from inherited to a member of Agc - cosmetic changes --- src/ipa/rkisp1/algorithms/agc.cpp | 22 +++++++++++++++++++++- src/ipa/rkisp1/algorithms/agc.h | 3 +++ src/ipa/rkisp1/ipa_context.h | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index 55cadb1793a5..1496a118ae2b 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -156,6 +156,15 @@ int Agc::init(IPAContext &context, const YamlObject &tuningData) ControlValue(controls::AnalogueGainModeManual) } }, ControlValue(controls::AnalogueGainModeAuto)); context.ctrlMap[&controls::ExposureValue] = ControlInfo(-8.0f, 8.0f, 0.0f); + /* + * Insert the controlInfo for sync. Since FrameDurationLimits is only + * set *after* the algorithms are initialized, we have no information + * on it here. Use a sensible default here and update it later in + * configure(). + * \todo Move FrameDurationLimits from the base IPA to AGC + */ + context.ctrlMap[&controls::SyncAdjustment] = SyncHelper::controlInfo(120'000); + /* Insert the controls for agc */ context.ctrlMap.merge(controls()); return 0; @@ -208,7 +217,11 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo) context.activeState.agc.automatic.yTarget = effectiveYTarget(); + context.ctrlMap[&controls::SyncAdjustment] = + SyncHelper::controlInfo(frameDurationLimits.max().get()); + resetFrameCount(); + sync_.resetSync(); return 0; } @@ -334,6 +347,10 @@ void Agc::queueRequest(IPAContext &context, } frameContext.agc.minFrameDuration = agc.minFrameDuration; frameContext.agc.maxFrameDuration = agc.maxFrameDuration; + + const auto &sync = controls.get(controls::SyncAdjustment); + if (sync) + sync_.setSync(*sync, frameContext.agc.minFrameDuration); } /** @@ -453,6 +470,7 @@ void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext, metadata.set(controls::AeExposureMode, frameContext.agc.exposureMode); metadata.set(controls::AeConstraintMode, frameContext.agc.constraintMode); metadata.set(controls::ExposureValue, frameContext.agc.exposureValue); + metadata.set(controls::SyncAdjustment, frameContext.agc.syncAdjustment.count()); } /** @@ -511,7 +529,9 @@ void Agc::processFrameDuration(IPAContext &context, IPACameraSensorInfo &sensorInfo = context.sensorInfo; utils::Duration lineDuration = context.configuration.sensor.lineDuration; - frameContext.agc.vblank = (frameDuration / lineDuration) - sensorInfo.outputSize.height; + utils::Duration sync = sync_.getSync(); + frameContext.agc.vblank = ((frameDuration + sync) / lineDuration) - sensorInfo.outputSize.height; + frameContext.agc.syncAdjustment = sync; /* Update frame duration accounting for line length quantization. */ frameContext.agc.frameDuration = (sensorInfo.outputSize.height + frameContext.agc.vblank) * lineDuration; diff --git a/src/ipa/rkisp1/algorithms/agc.h b/src/ipa/rkisp1/algorithms/agc.h index 7867eed9c4e3..c6cc20679cf7 100644 --- a/src/ipa/rkisp1/algorithms/agc.h +++ b/src/ipa/rkisp1/algorithms/agc.h @@ -15,6 +15,7 @@ #include #include "libipa/agc_mean_luminance.h" +#include "libipa/sync_helper.h" #include "algorithm.h" @@ -58,6 +59,8 @@ private: Span weights_; std::map> meteringModes_; + + SyncHelper sync_; }; } /* namespace ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index fa748811be74..3a5b499e088e 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -164,6 +164,7 @@ struct IPAFrameContext : public FrameContext { bool updateMetering; bool autoExposureModeChange; bool autoGainModeChange; + utils::Duration syncAdjustment; } agc; struct {