{"id":17168,"url":"https://patchwork.libcamera.org/api/patches/17168/?format=json","web_url":"https://patchwork.libcamera.org/patch/17168/","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":"<20220818094410.1671-14-jacopo@jmondi.org>","date":"2022-08-18T09:44:06","name":"[libcamera-devel,v3,13/17] ipa: ipu3: Re-sort methods implementation","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"66bcdb821099aad8a99d52ff71062acca40b0d2f","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/17168/mbox/","series":[{"id":3426,"url":"https://patchwork.libcamera.org/api/series/3426/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3426","date":"2022-08-18T09:43:53","name":"libcamera: Align IPU3 and RKISP1 interfaces","version":3,"mbox":"https://patchwork.libcamera.org/series/3426/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17168/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17168/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 B0D4AC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Aug 2022 09:44:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 668F861FCF;\n\tThu, 18 Aug 2022 11:44:40 +0200 (CEST)","from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4349361FD1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Aug 2022 11:44:36 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 42517FF80D;\n\tThu, 18 Aug 2022 09:44:35 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660815880;\n\tbh=l89hiHPM7YlhUtC+fO+aFPQBN+t7zcaY+iz3xUnQJnk=;\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=2Jc22eWiN8hi7UhxzgiN90AXOZAyHv5rl0jfr3WghOvKAWXasjum15ahwww/mP0wZ\n\tmWEqI33xd17LViR8ZOnzjYJuN2dUHCBAXbZpFZ7v6RCRYb/BOLBoZI0AgIvuOeMIxy\n\t04ZRu/mh2GRom3mP45E4KvkbeUB5wjXvEz2JqGdweEno3lDz1gSgvSc6/TFgKKcO3+\n\tH9WEbYVUfnnoetAAZfzDi3R4vXEXual6h91/yUs7aYSln4umg76V13/6sOW3VtTZU+\n\tm1g4mTFB98TfvKTvCGn27wpwlwUEM9rVZ8cFwrs+MOJYCMLTmPoldNv8AVhzH/MH2A\n\tp9rDdunJRJrPg==","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 18 Aug 2022 11:44:06 +0200","Message-Id":"<20220818094410.1671-14-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.37.2","In-Reply-To":"<20220818094410.1671-1-jacopo@jmondi.org>","References":"<20220818094410.1671-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 13/17] ipa: ipu3: Re-sort methods\n\timplementation","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":"Move the updateSessionConfiguration(), updateControls() and\nvalidateControls() function implementations before their unique caller\n(configure()) and re-sort them in orders they are called.\n\nFor consistency, enforce the same ordering in the RkIPS1 module.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/ipa/ipu3/ipu3.cpp     | 250 +++++++++++++++++++-------------------\n src/ipa/rkisp1/rkisp1.cpp |  39 +++---\n 2 files changed, 144 insertions(+), 145 deletions(-)","diff":"diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 077cf8050508..072d6cc28f33 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -161,13 +161,12 @@ protected:\n \tstd::string logPrefix() const override;\n \n private:\n+\tbool validateSensorControls();\n \tvoid updateControls(const IPACameraSensorInfo &sensorInfo,\n \t\t\t    const ControlInfoMap &sensorControls,\n \t\t\t    ControlInfoMap *ipaControls);\n \tvoid updateSessionConfiguration(const IPAConfigInfo &configInfo);\n \n-\tbool validateSensorControls();\n-\n \tvoid setControls(unsigned int frame);\n \tvoid calculateBdsGrid(const Size &bdsOutputSize);\n \n@@ -190,129 +189,6 @@ std::string IPAIPU3::logPrefix() const\n \treturn \"ipu3\";\n }\n \n-/**\n- * \\brief Compute IPASessionConfiguration using the sensor information and the\n- * sensor V4L2 controls\n- */\n-void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &configInfo)\n-{\n-\tconst IPACameraSensorInfo &sensorInfo = configInfo.sensorInfo;\n-\tconst ControlInfoMap &sensorControls = configInfo.sensorControls;\n-\n-\tconst ControlInfo vBlank = sensorControls.find(V4L2_CID_VBLANK)->second;\n-\tcontext_.configuration.sensor.defVBlank = vBlank.def().get<int32_t>();\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/* Clear the IPA context before the streaming session. */\n-\tcontext_.frameContexts.clear();\n-\tcontext_ = {};\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-\t * As it depends on the sensor, update it with the controls.\n-\t *\n-\t * \\todo take VBLANK into account for maximum shutter speed\n-\t */\n-\tcontext_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s\n-\t\t\t\t\t\t   / sensorInfo.pixelRate;\n-\tcontext_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration;\n-\tcontext_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration;\n-\tcontext_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n-\tcontext_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n-}\n-\n-/**\n- * \\brief Compute camera controls using the sensor information and the sensor\n- * V4L2 controls\n- *\n- * Some of the camera controls are computed by the pipeline handler, some others\n- * by the IPA module which is in charge of handling, for example, the exposure\n- * time and the frame duration.\n- *\n- * This function computes:\n- * - controls::ExposureTime\n- * - controls::FrameDurationLimits\n- */\n-void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n-\t\t\t     const ControlInfoMap &sensorControls,\n-\t\t\t     ControlInfoMap *ipaControls)\n-{\n-\tControlInfoMap::Map controls{};\n-\tdouble lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();\n-\n-\t/*\n-\t * Compute exposure time limits by using line length and pixel rate\n-\t * converted to microseconds. Use the V4L2_CID_EXPOSURE control to get\n-\t * exposure min, max and default and convert it from lines to\n-\t * microseconds.\n-\t */\n-\tconst ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n-\tint32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;\n-\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;\n-\tint32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;\n-\tcontrols[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,\n-\t\t\t\t\t\t\tdefExposure);\n-\n-\t/*\n-\t * Compute the frame duration limits.\n-\t *\n-\t * The frame length is computed assuming a fixed line length combined\n-\t * with the vertical frame sizes.\n-\t */\n-\tconst ControlInfo &v4l2HBlank = sensorControls.find(V4L2_CID_HBLANK)->second;\n-\tuint32_t hblank = v4l2HBlank.def().get<int32_t>();\n-\tuint32_t lineLength = sensorInfo.outputSize.width + hblank;\n-\n-\tconst ControlInfo &v4l2VBlank = sensorControls.find(V4L2_CID_VBLANK)->second;\n-\tstd::array<uint32_t, 3> frameHeights{\n-\t\tv4l2VBlank.min().get<int32_t>() + sensorInfo.outputSize.height,\n-\t\tv4l2VBlank.max().get<int32_t>() + sensorInfo.outputSize.height,\n-\t\tv4l2VBlank.def().get<int32_t>() + sensorInfo.outputSize.height,\n-\t};\n-\n-\tstd::array<int64_t, 3> frameDurations;\n-\tfor (unsigned int i = 0; i < frameHeights.size(); ++i) {\n-\t\tuint64_t frameSize = lineLength * frameHeights[i];\n-\t\tframeDurations[i] = frameSize / (sensorInfo.pixelRate / 1000000U);\n-\t}\n-\n-\tcontrols[&controls::FrameDurationLimits] = ControlInfo(frameDurations[0],\n-\t\t\t\t\t\t\t       frameDurations[1],\n-\t\t\t\t\t\t\t       frameDurations[2]);\n-\n-\t*ipaControls = ControlInfoMap(std::move(controls), controls::controls);\n-}\n-\n-/**\n- * \\brief Validate that the sensor controls mandatory for the IPA exists\n- */\n-bool IPAIPU3::validateSensorControls()\n-{\n-\tstatic const uint32_t ctrls[] = {\n-\t\tV4L2_CID_ANALOGUE_GAIN,\n-\t\tV4L2_CID_EXPOSURE,\n-\t\tV4L2_CID_VBLANK,\n-\t};\n-\n-\tfor (auto c : ctrls) {\n-\t\tif (sensorCtrls_.find(c) == sensorCtrls_.end()) {\n-\t\t\tLOG(IPAIPU3, Error) << \"Unable to find sensor control \"\n-\t\t\t\t\t    << utils::hex(c);\n-\t\t\treturn false;\n-\t\t}\n-\t}\n-\n-\treturn true;\n-}\n-\n /**\n  * \\brief Initialize the IPA module and its controls\n  *\n@@ -464,6 +340,130 @@ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n \t\t\t    << (int)bdsGrid.height << \" << \" << (int)bdsGrid.block_height_log2 << \")\";\n }\n \n+/**\n+ * \\brief Validate that the sensor controls mandatory for the IPA exists\n+ */\n+bool IPAIPU3::validateSensorControls()\n+{\n+\tstatic const uint32_t ctrls[] = {\n+\t\tV4L2_CID_ANALOGUE_GAIN,\n+\t\tV4L2_CID_EXPOSURE,\n+\t\tV4L2_CID_VBLANK,\n+\t};\n+\n+\tfor (auto c : ctrls) {\n+\t\tif (sensorCtrls_.find(c) == sensorCtrls_.end()) {\n+\t\t\tLOG(IPAIPU3, Error) << \"Unable to find sensor control \"\n+\t\t\t\t\t    << utils::hex(c);\n+\t\t\treturn false;\n+\t\t}\n+\t}\n+\n+\treturn true;\n+}\n+\n+/**\n+ * \\brief Compute camera controls using the sensor information and the sensor\n+ * V4L2 controls\n+ *\n+ * Some of the camera controls are computed by the pipeline handler, some others\n+ * by the IPA module which is in charge of handling, for example, the exposure\n+ * time and the frame duration.\n+ *\n+ * This function computes:\n+ * - controls::ExposureTime\n+ * - controls::FrameDurationLimits\n+ */\n+void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n+\t\t\t     const ControlInfoMap &sensorControls,\n+\t\t\t     ControlInfoMap *ipaControls)\n+{\n+\tControlInfoMap::Map controls{};\n+\tdouble lineDuration = context_.configuration.sensor.lineDuration.get<std::micro>();\n+\n+\t/*\n+\t * Compute exposure time limits by using line length and pixel rate\n+\t * converted to microseconds. Use the V4L2_CID_EXPOSURE control to get\n+\t * exposure min, max and default and convert it from lines to\n+\t * microseconds.\n+\t */\n+\tconst ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;\n+\tint32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;\n+\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;\n+\tint32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;\n+\tcontrols[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,\n+\t\t\t\t\t\t\tdefExposure);\n+\n+\t/*\n+\t * Compute the frame duration limits.\n+\t *\n+\t * The frame length is computed assuming a fixed line length combined\n+\t * with the vertical frame sizes.\n+\t */\n+\tconst ControlInfo &v4l2HBlank = sensorControls.find(V4L2_CID_HBLANK)->second;\n+\tuint32_t hblank = v4l2HBlank.def().get<int32_t>();\n+\tuint32_t lineLength = sensorInfo.outputSize.width + hblank;\n+\n+\tconst ControlInfo &v4l2VBlank = sensorControls.find(V4L2_CID_VBLANK)->second;\n+\tstd::array<uint32_t, 3> frameHeights{\n+\t\tv4l2VBlank.min().get<int32_t>() + sensorInfo.outputSize.height,\n+\t\tv4l2VBlank.max().get<int32_t>() + sensorInfo.outputSize.height,\n+\t\tv4l2VBlank.def().get<int32_t>() + sensorInfo.outputSize.height,\n+\t};\n+\n+\tstd::array<int64_t, 3> frameDurations;\n+\tfor (unsigned int i = 0; i < frameHeights.size(); ++i) {\n+\t\tuint64_t frameSize = lineLength * frameHeights[i];\n+\t\tframeDurations[i] = frameSize / (sensorInfo.pixelRate / 1000000U);\n+\t}\n+\n+\tcontrols[&controls::FrameDurationLimits] = ControlInfo(frameDurations[0],\n+\t\t\t\t\t\t\t       frameDurations[1],\n+\t\t\t\t\t\t\t       frameDurations[2]);\n+\n+\t*ipaControls = ControlInfoMap(std::move(controls), controls::controls);\n+}\n+\n+\n+/**\n+ * \\brief Compute IPASessionConfiguration using the sensor information and the\n+ * sensor V4L2 controls\n+ */\n+void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &configInfo)\n+{\n+\tconst IPACameraSensorInfo &sensorInfo = configInfo.sensorInfo;\n+\tconst ControlInfoMap &sensorControls = configInfo.sensorControls;\n+\n+\tconst ControlInfo vBlank = sensorControls.find(V4L2_CID_VBLANK)->second;\n+\tcontext_.configuration.sensor.defVBlank = vBlank.def().get<int32_t>();\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/* Clear the IPA context before the streaming session. */\n+\tcontext_.frameContexts.clear();\n+\tcontext_ = {};\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+\t * As it depends on the sensor, update it with the controls.\n+\t *\n+\t * \\todo take VBLANK into account for maximum shutter speed\n+\t */\n+\tcontext_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s\n+\t\t\t\t\t\t   / sensorInfo.pixelRate;\n+\tcontext_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration;\n+\tcontext_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration;\n+\tcontext_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n+\tcontext_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n+}\n+\n /**\n  * \\brief Configure the IPU3 IPA\n  * \\param[in] configInfo The IPA configuration data, received from the pipeline\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex 9f97c776016e..da7374815c99 100644\n--- a/src/ipa/rkisp1/rkisp1.cpp\n+++ b/src/ipa/rkisp1/rkisp1.cpp\n@@ -62,8 +62,8 @@ protected:\n \tstd::string logPrefix() const override;\n \n private:\n-\tvoid updateSessionConfiguration(const IPAConfigInfo &configInfo);\n \tbool validateSensorControls(const ControlInfoMap &sensorControls);\n+\tvoid updateSessionConfiguration(const IPAConfigInfo &configInfo);\n \n \tvoid setControls(unsigned int frame);\n \tvoid prepareMetadata(unsigned int frame, unsigned int aeState);\n@@ -194,6 +194,24 @@ void IPARkISP1::stop()\n \tcontext_.frameContexts.clear();\n }\n \n+bool IPARkISP1::validateSensorControls(const ControlInfoMap &sensorControls)\n+{\n+\tstatic const uint32_t ctrls[] = {\n+\t\tV4L2_CID_ANALOGUE_GAIN,\n+\t\tV4L2_CID_EXPOSURE,\n+\t};\n+\n+\tfor (auto c : ctrls) {\n+\t\tif (sensorControls.find(c) == sensorControls.end()) {\n+\t\t\tLOG(IPARkISP1, Error) << \"Unable to find sensor control \"\n+\t\t\t\t\t      << utils::hex(c);\n+\t\t\treturn false;\n+\t\t}\n+\t}\n+\n+\treturn true;\n+}\n+\n void IPARkISP1::updateSessionConfiguration(const IPAConfigInfo &configInfo)\n {\n \tconst IPACameraSensorInfo &sensorInfo = configInfo.sensorInfo;\n@@ -237,25 +255,6 @@ void IPARkISP1::updateSessionConfiguration(const IPAConfigInfo &configInfo)\n \tcontext_.activeState.frameCount = 0;\n }\n \n-bool IPARkISP1::validateSensorControls(const ControlInfoMap &sensorControls)\n-{\n-\tstatic const uint32_t ctrls[] = {\n-\t\tV4L2_CID_ANALOGUE_GAIN,\n-\t\tV4L2_CID_EXPOSURE,\n-\t};\n-\n-\tfor (auto c : ctrls) {\n-\t\tif (sensorControls.find(c) == sensorControls.end()) {\n-\t\t\tLOG(IPARkISP1, Error) << \"Unable to find sensor control \"\n-\t\t\t\t\t      << utils::hex(c);\n-\t\t\treturn false;\n-\t\t}\n-\t}\n-\n-\treturn true;\n-\n-}\n-\n int IPARkISP1::configure(const IPAConfigInfo &configInfo)\n {\n \tif (!validateSensorControls(configInfo.sensorControls)) {\n","prefixes":["libcamera-devel","v3","13/17"]}