{"id":17667,"url":"https://patchwork.libcamera.org/api/1.1/patches/17667/?format=json","web_url":"https://patchwork.libcamera.org/patch/17667/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221024000356.29521-5-laurent.pinchart@ideasonboard.com>","date":"2022-10-24T00:03:47","name":"[libcamera-devel,v3,04/13] ipa: rkisp1: Add support for manual gain and exposure","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"8d2c5c909c5e53b3ea1543acf275412857415ba7","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17667/mbox/","series":[{"id":3574,"url":"https://patchwork.libcamera.org/api/1.1/series/3574/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3574","date":"2022-10-24T00:03:43","name":"Add Bayer format support for RkISP1","version":3,"mbox":"https://patchwork.libcamera.org/series/3574/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17667/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17667/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5DB09BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Oct 2022 00:04:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 96F6F62EEE;\n\tMon, 24 Oct 2022 02:04:30 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 59A7562ED2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Oct 2022 02:04:27 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D93F5471;\n\tMon, 24 Oct 2022 02:04:26 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666569870;\n\tbh=SkFItuPc7oOntFA2TStR/Q7B3gL7P7w2oG2LpfBc+jU=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=xozh/ugKx+Q2Dxh7wMuKsws78fagUCpX1CusxptDPmdjw+Af600eDlT1ndZ6b0RD3\n\tKjdOjEnYpy2B7z8ADH226t9RQSb9NlRr0e/SEf1kX0gY/37zvEvrLCBGp9krR6myhS\n\tZq/qkGb3exkHsVPuyZM7WtAzhmtbHW+4tmzfJqRU9METKHYOhmzvcPHo34tWwHhp6T\n\tAfazw8cqAbPx1dgBPm2k2nRnJSamtDaYlQnLp+GodCra7mKEc+bKQATyy1PcHXdoy+\n\tnKvA6yc2xpsx0a1M8kvWIz/495L7++Nm92clnM6G80HYfTgtOhv+HvRcL0E3lii+Eh\n\tGa4Er9eWaOadQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1666569867;\n\tbh=SkFItuPc7oOntFA2TStR/Q7B3gL7P7w2oG2LpfBc+jU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Wi+E5uNdkfoH4jSC20RF2cr1V/4UqSOCwJzyWw4Iq3F0QYFPos8fNTQQpuCNeIoIZ\n\tFmuKbglVAk6ha6UnXq/uJ1izMWv3SjLOb31/KVXriHa0EMMKa5SdApGSnnSHdRktpW\n\t6MGGQwpi256jYUd5rLJq/8gQtnd1oZjPgzAqrwAw="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Wi+E5uNd\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 24 Oct 2022 03:03:47 +0300","Message-Id":"<20221024000356.29521-5-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.37.4","In-Reply-To":"<20221024000356.29521-1-laurent.pinchart@ideasonboard.com>","References":"<20221024000356.29521-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 04/13] ipa: rkisp1: Add support for\n\tmanual gain and exposure","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Paul Elder <paul.elder@ideasonboard.com>\n\nAdd support for manual gain and exposure in the rkisp1 IPA.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n include/libcamera/ipa/rkisp1.mojom       |  2 +-\n src/ipa/rkisp1/algorithms/agc.cpp        | 62 +++++++++++++++++++++---\n src/ipa/rkisp1/algorithms/agc.h          |  4 ++\n src/ipa/rkisp1/ipa_context.h             | 13 ++++-\n src/ipa/rkisp1/rkisp1.cpp                | 17 +++++++\n src/libcamera/pipeline/rkisp1/rkisp1.cpp |  2 +-\n 6 files changed, 89 insertions(+), 11 deletions(-)","diff":"diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom\nindex eaf3955e4096..b526450d9949 100644\n--- a/include/libcamera/ipa/rkisp1.mojom\n+++ b/include/libcamera/ipa/rkisp1.mojom\n@@ -10,7 +10,7 @@ import \"include/libcamera/ipa/core.mojom\";\n \n interface IPARkISP1Interface {\n \tinit(libcamera.IPASettings settings,\n-\t     uint32 hwRevision)\n+\t     uint32 hwRevision, libcamera.ControlInfoMap sensorControls)\n \t\t=> (int32 ret, libcamera.ControlInfoMap ipaControls);\n \tstart() => (int32 ret);\n \tstop();\ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex 169afe372803..377a3e8a0efd 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -74,9 +74,14 @@ Agc::Agc()\n int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n {\n \t/* Configure the default exposure and gain. */\n-\tcontext.activeState.agc.gain = std::max(context.configuration.sensor.minAnalogueGain,\n-\t\t\t\t\t\tkMinAnalogueGain);\n-\tcontext.activeState.agc.exposure = 10ms / context.configuration.sensor.lineDuration;\n+\tcontext.activeState.agc.automatic.gain =\n+\t\tstd::max(context.configuration.sensor.minAnalogueGain,\n+\t\t\t kMinAnalogueGain);\n+\tcontext.activeState.agc.automatic.exposure =\n+\t\t10ms / context.configuration.sensor.lineDuration;\n+\tcontext.activeState.agc.manual.gain = context.activeState.agc.automatic.gain;\n+\tcontext.activeState.agc.manual.exposure = context.activeState.agc.automatic.exposure;\n+\tcontext.activeState.agc.autoEnabled = true;\n \n \t/*\n \t * According to the RkISP1 documentation:\n@@ -108,14 +113,57 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n \treturn 0;\n }\n \n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::queueRequest\n+ */\n+void Agc::queueRequest(IPAContext &context,\n+\t\t       [[maybe_unused]] const uint32_t frame,\n+\t\t       IPAFrameContext &frameContext,\n+\t\t       const ControlList &controls)\n+{\n+\tauto &agc = context.activeState.agc;\n+\n+\tconst auto &agcEnable = controls.get(controls::AeEnable);\n+\tif (agcEnable && *agcEnable != agc.autoEnabled) {\n+\t\tagc.autoEnabled = *agcEnable;\n+\n+\t\tLOG(RkISP1Agc, Debug)\n+\t\t\t<< (*agcEnable ? \"Enabling\" : \"Disabling\") << \" AGC\";\n+\t}\n+\n+\tconst auto &exposure = controls.get(controls::ExposureTime);\n+\tif (exposure && !agc.autoEnabled) {\n+\t\tagc.manual.exposure = *exposure;\n+\n+\t\tLOG(RkISP1Agc, Debug)\n+\t\t\t<< \"Set exposure to: \" << agc.manual.exposure;\n+\t}\n+\n+\tconst auto &gain = controls.get(controls::AnalogueGain);\n+\tif (gain && !agc.autoEnabled) {\n+\t\tagc.manual.gain = *gain;\n+\n+\t\tLOG(RkISP1Agc, Debug) << \"Set gain to: \" << agc.manual.gain;\n+\t}\n+\n+\tframeContext.agc.autoEnabled = agc.autoEnabled;\n+\n+\tif (!frameContext.agc.autoEnabled) {\n+\t\tframeContext.agc.exposure = agc.manual.exposure;\n+\t\tframeContext.agc.gain = agc.manual.gain;\n+\t}\n+}\n+\n /**\n  * \\copydoc libcamera::ipa::Algorithm::prepare\n  */\n void Agc::prepare(IPAContext &context, const uint32_t frame,\n \t\t  IPAFrameContext &frameContext, rkisp1_params_cfg *params)\n {\n-\tframeContext.agc.exposure = context.activeState.agc.exposure;\n-\tframeContext.agc.gain = context.activeState.agc.gain;\n+\tif (frameContext.agc.autoEnabled) {\n+\t\tframeContext.agc.exposure = context.activeState.agc.automatic.exposure;\n+\t\tframeContext.agc.gain = context.activeState.agc.automatic.gain;\n+\t}\n \n \tif (frame > 0)\n \t\treturn;\n@@ -263,8 +311,8 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext &frameContext,\n \t\t\t      << stepGain;\n \n \t/* Update the estimated exposure and gain. */\n-\tactiveState.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n-\tactiveState.agc.gain = stepGain;\n+\tactiveState.agc.automatic.exposure = shutterTime / configuration.sensor.lineDuration;\n+\tactiveState.agc.automatic.gain = stepGain;\n }\n \n /**\ndiff --git a/src/ipa/rkisp1/algorithms/agc.h b/src/ipa/rkisp1/algorithms/agc.h\nindex da4d2d4e8359..a228d0c37768 100644\n--- a/src/ipa/rkisp1/algorithms/agc.h\n+++ b/src/ipa/rkisp1/algorithms/agc.h\n@@ -26,6 +26,10 @@ public:\n \t~Agc() = default;\n \n \tint configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override;\n+\tvoid queueRequest(IPAContext &context,\n+\t\t\t  const uint32_t frame,\n+\t\t\t  IPAFrameContext &frameContext,\n+\t\t\t  const ControlList &controls) override;\n \tvoid prepare(IPAContext &context, const uint32_t frame,\n \t\t     IPAFrameContext &frameContext,\n \t\t     rkisp1_params_cfg *params) override;\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 3e47ac663c58..b9b2065328d6 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -54,8 +54,16 @@ struct IPASessionConfiguration {\n \n struct IPAActiveState {\n \tstruct {\n-\t\tuint32_t exposure;\n-\t\tdouble gain;\n+\t\tstruct {\n+\t\t\tuint32_t exposure;\n+\t\t\tdouble gain;\n+\t\t} manual;\n+\t\tstruct {\n+\t\t\tuint32_t exposure;\n+\t\t\tdouble gain;\n+\t\t} automatic;\n+\n+\t\tbool autoEnabled;\n \t} agc;\n \n \tstruct {\n@@ -96,6 +104,7 @@ struct IPAFrameContext : public FrameContext {\n \tstruct {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n+\t\tbool autoEnabled;\n \t} agc;\n \n \tstruct {\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex 538e42cb6f7f..5c041ded0db4 100644\n--- a/src/ipa/rkisp1/rkisp1.cpp\n+++ b/src/ipa/rkisp1/rkisp1.cpp\n@@ -50,6 +50,7 @@ public:\n \tIPARkISP1();\n \n \tint init(const IPASettings &settings, unsigned int hwRevision,\n+\t\t const ControlInfoMap &sensorControls,\n \t\t ControlInfoMap *ipaControls) override;\n \tint start() override;\n \tvoid stop() override;\n@@ -116,6 +117,7 @@ std::string IPARkISP1::logPrefix() const\n }\n \n int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision,\n+\t\t    const ControlInfoMap &sensorControls,\n \t\t    ControlInfoMap *ipaControls)\n {\n \t/* \\todo Add support for other revisions */\n@@ -184,6 +186,21 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision,\n \n \t/* Return the controls handled by the IPA. */\n \tControlInfoMap::Map ctrlMap = rkisp1Controls;\n+\n+\tauto exposureTimeInfo = sensorControls.find(V4L2_CID_EXPOSURE);\n+\tif (exposureTimeInfo != sensorControls.end()) {\n+\t\tctrlMap.emplace(&controls::ExposureTime,\n+\t\t\t\tControlInfo(exposureTimeInfo->second.min(),\n+\t\t\t\t\t    exposureTimeInfo->second.max()));\n+\t}\n+\n+\tauto analogueGainInfo = sensorControls.find(V4L2_CID_ANALOGUE_GAIN);\n+\tif (analogueGainInfo != sensorControls.end()) {\n+\t\tctrlMap.emplace(&controls::AnalogueGain,\n+\t\t\t\tControlInfo(static_cast<float>(analogueGainInfo->second.min().get<int32_t>()),\n+\t\t\t\t\t    static_cast<float>(analogueGainInfo->second.max().get<int32_t>())));\n+\t}\n+\n \t*ipaControls = ControlInfoMap(std::move(ctrlMap), controls::controls);\n \n \treturn 0;\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 455ee2a0a711..1418dc9a47fb 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -348,7 +348,7 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision)\n \t}\n \n \tint ret = ipa_->init({ ipaTuningFile, sensor_->model() }, hwRevision,\n-\t\t\t     &controlInfo_);\n+\t\t\t     sensor_->controls(), &controlInfo_);\n \tif (ret < 0) {\n \t\tLOG(RkISP1, Error) << \"IPA initialization failure\";\n \t\treturn ret;\n","prefixes":["libcamera-devel","v3","04/13"]}