From patchwork Thu Oct 17 12:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 21653 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 92F8FC32FE for ; Thu, 17 Oct 2024 12:46:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 53D156538A; Thu, 17 Oct 2024 14:46:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ncyCWVrS"; dkim-atps=neutral Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 21A2365388 for ; Thu, 17 Oct 2024 14:46:26 +0200 (CEST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-539f0f9ee49so1086963e87.1 for ; Thu, 17 Oct 2024 05:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729169185; x=1729773985; 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=RZA4Fbi06ANAkJZDjKo3YmQxc3CPBlt20nPCs8P4ek8=; b=ncyCWVrSd3wQ6vDbfg/WWmQI0fb5UeHku2jNap9NHrz3JWXa5SiWvFdtGkvbNhqlil 57m03Nchzc/RcBCMA/oF6O2ZOfA+KyDGuTMVWxWXDWQDS+VqTDYxqbc/ax3LPmF/nWea 1pEOwf0E6tRSIKwR0LaSZFRYMnncs7WHzJ7cTDQUzQ2SKwkF6h8+LTXTpUlJfrhXJddQ BTFWdgP+B8qDBOIj0UxWFu5/Rs1Bqsn7gP5Bqx1feK3Ir3y50WL6N8raNlt73xaXvfU2 cuZU1F8Jr78CDWBA6QwyvPz57sSka74Ap7o/lsrKTlFs63ziiyg5NydgyyzoAUHkXoFK dBSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729169185; x=1729773985; 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=RZA4Fbi06ANAkJZDjKo3YmQxc3CPBlt20nPCs8P4ek8=; b=nW4SpHvjxKYLs3jgUMipsTp3b2GJhQsk0HOOlzMq4SFQf28fz9a63UcqYzVLixRAkk mZ064h4d+X2JMJ8XyqlAHvqPTBsDbUREucCI/CFOkQK3H4RO5xyzSsRQqEhpA5JfJ0RT wnWh9H7BR5vFbNtMi+pejPqLsXI9Jfw4bjln+Xlmh8TsV5sogGcskxLXEbRzVY/VFuxf N1pDCvhQ41wEZxnKJyN2Ce7B6hzG+L3Q1YKxy1BNXQmvJGCmkVKM8oVuy2O3oFy+bWZY C0tP9/6pkcMIoHWMH+6jb7f+tkCXCQYiLbJIwmu79F4VT9/0htWrvFTqrYxgPbod5smc 1CCw== X-Gm-Message-State: AOJu0YyxlzHhkABWfLz1hp/a5+uUs3f3jau6XsXw19ENKsO24n9shOa3 wxHI3Cc1inZ/Gic44bbHyfxO5n+BZtvKd0+glNgTxsScp13plDYxBBm1AA== X-Google-Smtp-Source: AGHT+IHzyWKq2jdOP9vbS1gsFA3MZC1oRTqlJYIvfj7J3tTcuaXjigtrQRTs5Z/EK8gRzAdvwSCjcg== X-Received: by 2002:a05:6512:3b97:b0:539:e333:1822 with SMTP id 2adb3069b0e04-53a03f070eamr4838648e87.4.1729169184239; Thu, 17 Oct 2024 05:46:24 -0700 (PDT) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-539ffff391fsm771436e87.125.2024.10.17.05.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 05:46:23 -0700 (PDT) From: Mikhail Rudenko To: libcamera-devel@lists.libcamera.org Cc: Mikhail Rudenko Subject: [PATCH 3/3] rkisp1: synchronize sensor controls with IPA Date: Thu, 17 Oct 2024 15:46:13 +0300 Message-ID: <20241017124613.3853273-4-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017124613.3853273-1-mike.rudenko@gmail.com> References: <20241017124613.3853273-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" When IPA AGC active state is initialized in configure() method, it may fall out of sync with actual sensor controls and initial values in the delayed controls. Fix this by sending updated controls to the pipeline handler on first start() after configure(). Also reset delayedCtrls_ on start to make it capture the updated control values. Signed-off-by: Mikhail Rudenko --- include/libcamera/ipa/rkisp1.mojom | 2 +- src/ipa/rkisp1/ipa_context.h | 2 ++ src/ipa/rkisp1/rkisp1.cpp | 19 +++++++++++++++---- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 6 +++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom index 80d54a03..09900742 100644 --- a/include/libcamera/ipa/rkisp1.mojom +++ b/include/libcamera/ipa/rkisp1.mojom @@ -20,7 +20,7 @@ interface IPARkISP1Interface { libcamera.IPACameraSensorInfo sensorInfo, libcamera.ControlInfoMap sensorControls) => (int32 ret, libcamera.ControlInfoMap ipaControls); - start() => (int32 ret); + start() => (int32 ret, libcamera.ControlList sensorControls); stop(); configure(IPAConfigInfo configInfo, diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index e274d9b0..e07a5cdb 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -191,6 +191,8 @@ struct IPAContext { /* Interface to the Camera Helper */ std::unique_ptr camHelper; + + bool sensorControlsNeedSync; }; } /* namespace ipa::rkisp1 */ diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 9e161cab..680a7eee 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -55,7 +55,7 @@ public: const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls) override; - int start() override; + int start(ControlList *sensorControls) override; void stop() override; int configure(const IPAConfigInfo &ipaConfig, @@ -124,7 +124,7 @@ const ControlInfoMap::Map rkisp1Controls{ } /* namespace */ IPARkISP1::IPARkISP1() - : context_({ {}, {}, {}, {}, { kMaxFrameContexts }, {}, {} }) + : context_({ {}, {}, {}, {}, { kMaxFrameContexts }, {}, {}, false }) { } @@ -208,10 +208,19 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision, return 0; } -int IPARkISP1::start() +int IPARkISP1::start(ControlList *sensorControls) { - setControls(0); + if (context_.sensorControlsNeedSync) { + const auto &agc = context_.activeState.agc; + uint32_t exposure = agc.automatic.exposure; + uint32_t gain = context_.camHelper->gainCode(agc.automatic.gain); + *sensorControls = ControlList{ sensorControls_ }; + sensorControls->set(V4L2_CID_EXPOSURE, static_cast(exposure)); + sensorControls->set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain)); + + context_.sensorControlsNeedSync = false; + } return 0; } @@ -290,6 +299,8 @@ int IPARkISP1::configure(const IPAConfigInfo &ipaConfig, return ret; } + context_.sensorControlsNeedSync = true; + return 0; } diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 42961c12..18d98547 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -943,6 +943,7 @@ int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] const ControlL { RkISP1CameraData *data = cameraData(camera); utils::ScopeExitActions actions; + ControlList sensorControls; int ret; /* Allocate buffers for internal pipeline usage. */ @@ -951,7 +952,7 @@ int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] const ControlL return ret; actions += [&]() { freeBuffers(camera); }; - ret = data->ipa_->start(); + ret = data->ipa_->start(&sensorControls); if (ret) { LOG(RkISP1, Error) << "Failed to start IPA " << camera->id(); @@ -961,6 +962,9 @@ int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] const ControlL data->frame_ = 0; + data->sensor_->setControls(&sensorControls); + data->delayedCtrls_->reset(); + if (!isRaw_) { ret = param_->streamOn(); if (ret) {