{"id":16395,"url":"https://patchwork.libcamera.org/api/patches/16395/?format=json","web_url":"https://patchwork.libcamera.org/patch/16395/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20220627162732.33160-15-jacopo@jmondi.org>","date":"2022-06-27T16:27:31","name":"[libcamera-devel,14/15] ipa: ipu3: Configure IPA with libcamera controls","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":true,"hash":"c0dfdd32fe9d479166b3baf2841d87902660f338","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16395/mbox/","series":[{"id":3224,"url":"https://patchwork.libcamera.org/api/series/3224/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3224","date":"2022-06-27T16:27:17","name":"Internal controls, sensor delays and IPA init/configure rework","version":1,"mbox":"https://patchwork.libcamera.org/series/3224/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16395/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16395/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 33D79BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Jun 2022 16:28:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C2BA26564F;\n\tMon, 27 Jun 2022 18:28:04 +0200 (CEST)","from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EE5D65635\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Jun 2022 18:27:54 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id B172B20004;\n\tMon, 27 Jun 2022 16:27:53 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656347284;\n\tbh=xWarKmTw0az9pmRqeB1pNq0yAC4/im7vDuKrVEzDcl4=;\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=fMpii3qcE/qhqGM+2rVfYpFZKBxvAz8zYFgQAtJ4njbLzUZt5BYbTnxl9g5chE31l\n\tPA9lmxuPs9Wt5dtwMRaCTGp29G8NOslxMHYopgGI9hb49p+ZbV2pkMdTFyAhBzkmiU\n\t8M1veIfJ/WKHTH4pR2qL4Vsoo3fB521GqNNvRTc6/AaivWUd0QF+4EpoifjhxjiQNI\n\tIIsVN8LvjX2cOFjyMy2IWl8UDnR7zGMzqVBhQyn9n5QdSqV8b6lUf66uk2904BpZSX\n\t3ptZd/qYnjhmS99azCRRPfe1XJvL1pRBc0k8EvBTekuHTmZnD4ws7B7lrj8ZI7s0Y5\n\tKYrsVA7MTJG/g==","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 27 Jun 2022 18:27:31 +0200","Message-Id":"<20220627162732.33160-15-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.36.1","In-Reply-To":"<20220627162732.33160-1-jacopo@jmondi.org>","References":"<20220627162732.33160-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 14/15] ipa: ipu3: Configure IPA with\n\tlibcamera controls","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":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Pass to the IPA configure() function the list of libcamera\ncontrols::internal controls in place of sending to the IPA the\nraw V4L2 control values.\n\nAs the controls::internal::ExposureTime is already expressed in\nmicro-seconds, there's not need to multiply by the line duration.\n\nAnalogueGain still requires translation using the CameraSensorHelper\nclass.\n\nWhile at it, rationalize the sequence of operations IPA::configure() to:\n- check the validity of the configuration\n- update the session configuration\n- configure algorithm\n- assign class member variables\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/ipa/ipu3/ipu3.cpp                | 67 ++++++++++++----------------\n src/libcamera/pipeline/ipu3/ipu3.cpp |  2 +-\n 2 files changed, 30 insertions(+), 39 deletions(-)","diff":"diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 1f80a10bc48d..b67ff1948bc2 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -150,7 +150,7 @@ public:\n private:\n \tvoid updateSessionConfiguration(const IPAConfigInfo &info);\n \n-\tbool validateSensorControls();\n+\tbool validateConfiguration(const IPAConfigInfo &config);\n \n \tvoid setControls(unsigned int frame);\n \tvoid calculateBdsGrid(const Size &bdsOutputSize);\n@@ -183,16 +183,6 @@ void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &info)\n \tcontext_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s\n \t\t\t\t\t\t   / sensorInfo.pixelRate;\n \n-\tconst ControlInfoMap &sensorControls = info.sensorControls;\n-\n-\tconst ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n-\tint32_t minExposure = v4l2Exposure.min().get<int32_t>();\n-\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>();\n-\n-\tconst ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;\n-\tint32_t minGain = v4l2Gain.min().get<int32_t>();\n-\tint32_t maxGain = v4l2Gain.max().get<int32_t>();\n-\n \t/*\n \t * When the AGC computes the new exposure values for a frame, it needs\n \t * to know the limits for shutter speed and analogue gain.\n@@ -200,8 +190,16 @@ void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &info)\n \t *\n \t * \\todo take VBLANK into account for maximum shutter speed\n \t */\n-\tcontext_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration;\n-\tcontext_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration;\n+\tconst ControlInfoMap &sensorControls = info.sensorControls;\n+\n+\tconst auto &[expId, exposure] = *sensorControls.find(&controls::internal::ExposureTime);\n+\tcontext_.configuration.agc.minShutterSpeed = exposure.min().get<int32_t>() * 1.0us;\n+\tcontext_.configuration.agc.maxShutterSpeed = exposure.max().get<int32_t>() * 1.0us;\n+\n+\tconst auto &[gainId, gain] = *sensorControls.find(&controls::internal::draft::SensorAnalogueGain);\n+\tint32_t minGain = gain.min().get<int32_t>();\n+\tint32_t maxGain = gain.max().get<int32_t>();\n+\n \tcontext_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n \tcontext_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n }\n@@ -209,18 +207,18 @@ void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &info)\n /**\n  * \\brief Validate that the sensor controls mandatory for the IPA exists\n  */\n-bool IPAIPU3::validateSensorControls()\n+bool IPAIPU3::validateConfiguration(const IPAConfigInfo &config)\n {\n-\tstatic const uint32_t ctrls[] = {\n-\t\tV4L2_CID_ANALOGUE_GAIN,\n-\t\tV4L2_CID_EXPOSURE,\n-\t\tV4L2_CID_VBLANK,\n+\tstatic constexpr std::array<const ControlId *, 3> ctrls = {\n+\t\t&controls::internal::ExposureTime,\n+\t\t&controls::internal::FrameDuration,\n+\t\t&controls::internal::draft::SensorAnalogueGain,\n \t};\n \n-\tfor (auto c : ctrls) {\n-\t\tif (sensorCtrls_.find(c) == sensorCtrls_.end()) {\n+\tfor (const ControlId *c : ctrls) {\n+\t\tif (config.sensorControls.find(c) == config.sensorControls.end()) {\n \t\t\tLOG(IPAIPU3, Error) << \"Unable to find sensor control \"\n-\t\t\t\t\t    << utils::hex(c);\n+\t\t\t\t\t    << c->name();\n \t\t\treturn false;\n \t\t}\n \t}\n@@ -369,30 +367,19 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \t\treturn -ENODATA;\n \t}\n \n-\tsensorInfo_ = configInfo.sensorInfo;\n-\n-\tlensCtrls_ = configInfo.lensControls;\n-\n-\t/*\n-\t * Compute the sensor V4L2 controls to be used by the algorithms and\n-\t * to be set on the sensor.\n-\t */\n-\tsensorCtrls_ = configInfo.sensorControls;\n-\n-\tcalculateBdsGrid(configInfo.bdsOutputSize);\n+\tif (!validateConfiguration(configInfo)) {\n+\t\tLOG(IPAIPU3, Error) << \"Sensor control validation failed.\";\n+\t\treturn -EINVAL;\n+\t}\n \n \t/* Clean IPAActiveState at each reconfiguration. */\n \tcontext_.activeState = {};\n \tIPAFrameContext initFrameContext;\n \tcontext_.frameContexts.fill(initFrameContext);\n \n-\tif (!validateSensorControls()) {\n-\t\tLOG(IPAIPU3, Error) << \"Sensor control validation failed.\";\n-\t\treturn -EINVAL;\n-\t}\n-\n-\t/* Update the IPASessionConfiguration using the sensor settings. */\n+\t/* Update the IPA configuration using the new settings. */\n \tupdateSessionConfiguration(configInfo);\n+\tcalculateBdsGrid(configInfo.bdsOutputSize);\n \n \tfor (auto const &algo : algorithms_) {\n \t\tint ret = algo->configure(context_, configInfo);\n@@ -400,6 +387,10 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \t\t\treturn ret;\n \t}\n \n+\tsensorInfo_ = configInfo.sensorInfo;\n+\tlensCtrls_ = configInfo.lensControls;\n+\tsensorCtrls_ = configInfo.sensorControls;\n+\n \treturn 0;\n }\n \ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 44e65d9f2d46..8bf51411581a 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -661,7 +661,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)\n \t}\n \n \tipa::ipu3::IPAConfigInfo configInfo;\n-\tconfigInfo.sensorControls = data->cio2_.sensor()->v4l2Controls();\n+\tconfigInfo.sensorControls = data->cio2_.sensor()->controls();\n \n \tCameraLens *lens = data->cio2_.sensor()->focusLens();\n \tif (lens)\n","prefixes":["libcamera-devel","14/15"]}