From patchwork Sun Oct 20 15:28:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 21708 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 259DCC3304 for ; Sun, 20 Oct 2024 15:28:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AEC8A65391; Sun, 20 Oct 2024 17:28:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Q71tmijn"; 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 CAD856538D for ; Sun, 20 Oct 2024 17:28:40 +0200 (CEST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-53a0c160b94so1523389e87.2 for ; Sun, 20 Oct 2024 08:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729438119; x=1730042919; 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=Q71tmijnrj+BNqzH4llfeK46Q9vjNzETTJ5n2GTZOudcG/8X6rpafvu0/iABVsG5zV kN23LgRGO3kK2xZ/yK+lQ1Ht5mYBD4gMDB/NuzktAO1yQcjrVRzK9kOzT7ZZJCeaIKq0 oLmFAGgZHw2GivIMeSIz0IPfUPpvtr4Zgam2XE0u2ZAyCDRqbxdVndl4z0hFHI3AsKKb jtqsAd+ITWc3H+uSo1Jqayd7C8Mnr4JEQqGhKdQocm9cZhz0SecWhaWbdIcmDvMgJdN8 QBoeLameOIsbDQI/gKLm24nYjxGWvkRArMKCsG42M5v2+HvEu05GZlaoVh+6Ir4VMU9P /Cmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729438119; x=1730042919; 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=k2fccAxVNgdrV+K8sXqxl5+q02sQO3IJfADh4uFV+2HrbbFRBg0O5QuOAJABdX0q88 Un0uQsTdbtdpJQbOvofWv4eCafVUA4y+PrGOf+lx10FwqIPjoKZkGJUaidwsgm1FvuSC dQg+uHy2Em7aCF3CIH5XIqvszj4bZuFY3Vwz2dJnpgZWFVJiao0eoQaNskvpapyeeUwA yFlNpixBQ2wDEA57NN327s96oeCjQsN3gDG3br0kT0L4Cr1qVVBtPZijtyzKElBl+pvA GcmcxryIyYTANBagHPIsG4kvRVW8HLauixmMXKxbMF0WY5f31DfS7XrlwomKvXkRMIn2 M5hg== X-Gm-Message-State: AOJu0YzW/CNgMd7Sj2yFKcnXWJD4YDb9S8LFCQAzhez1OvbA41jIvRxH F5eZoEbFGLQFmuDl8sME7IHrro1Bs2OkAGv6qqdzN+lcGHvy+Thg2Xu1sQ== X-Google-Smtp-Source: AGHT+IGKQ6bO1b06MR/GAadxCz0WBSNE02p8qQwapqRscOpQKcqikdpN0SrwnLDCaHGqMGWbHFDlOA== X-Received: by 2002:a05:6512:1582:b0:539:9f3c:3bfd with SMTP id 2adb3069b0e04-53a154ab92amr4950134e87.58.1729438118613; Sun, 20 Oct 2024 08:28:38 -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:38 -0700 (PDT) From: Mikhail Rudenko To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Mikhail Rudenko Subject: [PATCH v2 3/4] rkisp1: synchronize sensor controls with IPA Date: Sun, 20 Oct 2024 18:28:20 +0300 Message-ID: <20241020152821.240726-4-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" 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) {