{"id":17421,"url":"https://patchwork.libcamera.org/api/patches/17421/?format=json","web_url":"https://patchwork.libcamera.org/patch/17421/","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":"<20220927023642.12341-11-laurent.pinchart@ideasonboard.com>","date":"2022-09-27T02:36:19","name":"[libcamera-devel,v5,10/33] ipa: ipu3: Use the FCQueue","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"0434ca6fb230aebc634213a58226fac463c2c8cb","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17421/mbox/","series":[{"id":3506,"url":"https://patchwork.libcamera.org/api/series/3506/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3506","date":"2022-09-27T02:36:09","name":"ipa: Frame context queue, IPU3 & RkISP consolidation, and RkISP1 improvements","version":5,"mbox":"https://patchwork.libcamera.org/series/3506/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17421/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17421/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 3BE8AC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Sep 2022 02:37:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D8E7262293;\n\tTue, 27 Sep 2022 04:37:17 +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 8C3C36228B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Sep 2022 04:37:14 +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 08F9047C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Sep 2022 04:37:13 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1664246237;\n\tbh=99JUc/pduUEbHGlojTiZe+EJQy/Kb9Fep6BbBUb6jMY=;\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=y29gjel8vFvH9rfPdLMCRNMsPwq+99Khpaa3f8t7KZSItBpW+Ikg9iFk1Ml7l9B4p\n\tmczbQG1V7dC2UaTOZ4Z6exlHBSv5r2cLBbPvZK2qZ3+6yChOD1YEACki0OSZkf/Q5+\n\ti7Tor/b2b98YWwkF+KnGkURG6OUZBsYzKWf0wQAiu9KgIuMMjTEFOiYGOd1Pwm/1vI\n\tCiy6cLw/FR+Fo90qrlBKj2GGpUwWhF6Fm+sXYSNK7Af73nesYheYpMj7B4JwdwsgO/\n\tA+8bHwgDZWMX10RtOsKHlBFEpJGcjoVsmefN7xio9CuiEM2HN+RAnSdX/GYu5a5ECx\n\tSoKj1JeswA2OQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1664246234;\n\tbh=99JUc/pduUEbHGlojTiZe+EJQy/Kb9Fep6BbBUb6jMY=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=jSjlLwFthvSxNeusTNAzzZW0ut0es8rcQtc8TKyFFP1RTfN2xx/DvcK+PyHyyq7WQ\n\tqV9niyUJkutDO8PSlyXuJ5RaYplQjsWnUFpbwh2rkuxC4B0xUAYRVMhXGdfiaSrfND\n\tHGjClZdbnnzt4qDHfD2m7vc77CsdIWH85SdLjh3Y="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"jSjlLwFt\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 27 Sep 2022 05:36:19 +0300","Message-Id":"<20220927023642.12341-11-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","In-Reply-To":"<20220927023642.12341-1-laurent.pinchart@ideasonboard.com>","References":"<20220927023642.12341-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 10/33] ipa: ipu3: Use the FCQueue","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":"Replace the manual ring buffer implementation with the FCQueue class\nfrom libipa.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nChanges since v4:\n\n- Rename FCQueue::init() to alloc()\n---\n src/ipa/ipu3/ipa_context.cpp | 14 --------------\n src/ipa/ipu3/ipa_context.h   | 10 +---------\n src/ipa/ipu3/ipu3.cpp        | 32 ++++++++++++++++++++++++--------\n 3 files changed, 25 insertions(+), 31 deletions(-)","diff":"diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\nindex 9cfca0db3a0d..6904ccbbdf8b 100644\n--- a/src/ipa/ipu3/ipa_context.cpp\n+++ b/src/ipa/ipu3/ipa_context.cpp\n@@ -164,20 +164,6 @@ namespace libcamera::ipa::ipu3 {\n  * <linux/intel-ipu3.h> struct ipu3_uapi_gamma_corr_lut for further details.\n  */\n \n-/**\n- * \\brief Default constructor for IPAFrameContext\n- */\n-IPAFrameContext::IPAFrameContext() = default;\n-\n-/**\n- * \\brief Construct a IPAFrameContext instance\n- */\n-IPAFrameContext::IPAFrameContext(const ControlList &reqControls)\n-\t: frameControls(reqControls)\n-{\n-\tsensor = {};\n-}\n-\n /**\n  * \\struct IPAFrameContext\n  * \\brief IPU3-specific FrameContext\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex e8fc42769075..bfc0196e098a 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -8,8 +8,6 @@\n \n #pragma once\n \n-#include <array>\n-\n #include <linux/intel-ipu3.h>\n \n #include <libcamera/base/utils.h>\n@@ -23,9 +21,6 @@ namespace libcamera {\n \n namespace ipa::ipu3 {\n \n-/* Maximum number of frame contexts to be held */\n-static constexpr uint32_t kMaxFrameContexts = 16;\n-\n struct IPASessionConfiguration {\n \tstruct {\n \t\tipu3_uapi_grid_config bdsGrid;\n@@ -79,9 +74,6 @@ struct IPAActiveState {\n };\n \n struct IPAFrameContext : public FrameContext {\n-\tIPAFrameContext();\n-\tIPAFrameContext(const ControlList &reqControls);\n-\n \tstruct {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n@@ -94,7 +86,7 @@ struct IPAContext {\n \tIPASessionConfiguration configuration;\n \tIPAActiveState activeState;\n \n-\tstd::array<IPAFrameContext, kMaxFrameContexts> frameContexts;\n+\tFCQueue<IPAFrameContext> frameContexts;\n };\n \n } /* namespace ipa::ipu3 */\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex b1b23fd8f927..96dc2af2cb73 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -40,6 +40,8 @@\n #include \"algorithms/tone_mapping.h\"\n #include \"libipa/camera_sensor_helper.h\"\n \n+#include \"ipa_context.h\"\n+\n /* Minimum grid width, expressed as a number of cells */\n static constexpr uint32_t kMinGridWidth = 16;\n /* Maximum grid width, expressed as a number of cells */\n@@ -53,6 +55,9 @@ static constexpr uint32_t kMinCellSizeLog2 = 3;\n /* log2 of the maximum grid cell width and height, in pixels */\n static constexpr uint32_t kMaxCellSizeLog2 = 6;\n \n+/* Maximum number of frame contexts to be held */\n+static constexpr uint32_t kMaxFrameContexts = 16;\n+\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPAIPU3)\n@@ -135,6 +140,8 @@ namespace ipa::ipu3 {\n class IPAIPU3 : public IPAIPU3Interface, public Module\n {\n public:\n+\tIPAIPU3();\n+\n \tint init(const IPASettings &settings,\n \t\t const IPACameraSensorInfo &sensorInfo,\n \t\t const ControlInfoMap &sensorControls,\n@@ -183,6 +190,11 @@ private:\n \tstruct IPAContext context_;\n };\n \n+IPAIPU3::IPAIPU3()\n+\t: context_({ {}, {}, { kMaxFrameContexts } })\n+{\n+}\n+\n std::string IPAIPU3::logPrefix() const\n {\n \treturn \"ipu3\";\n@@ -205,6 +217,11 @@ void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)\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_.configuration = {};\n+\tcontext_.activeState = {};\n+\tcontext_.frameContexts.clear();\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@@ -382,6 +399,7 @@ int IPAIPU3::start()\n  */\n void IPAIPU3::stop()\n {\n+\tcontext_.frameContexts.clear();\n }\n \n /**\n@@ -488,11 +506,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n \n \tcalculateBdsGrid(configInfo.bdsOutputSize);\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@@ -572,7 +585,7 @@ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId)\n \t */\n \tparams->use = {};\n \n-\tIPAFrameContext &frameContext = context_.frameContexts[frame % kMaxFrameContexts];\n+\tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n \n \tfor (auto const &algo : algorithms())\n \t\talgo->prepare(context_, frame, frameContext, params);\n@@ -605,7 +618,7 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame,\n \tconst ipu3_uapi_stats_3a *stats =\n \t\treinterpret_cast<ipu3_uapi_stats_3a *>(mem.data());\n \n-\tIPAFrameContext &frameContext = context_.frameContexts[frame % kMaxFrameContexts];\n+\tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n \n \tframeContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get<int32_t>();\n \tframeContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());\n@@ -651,7 +664,10 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame,\n void IPAIPU3::queueRequest(const uint32_t frame, const ControlList &controls)\n {\n \t/* \\todo Start processing for 'frame' based on 'controls'. */\n-\tcontext_.frameContexts[frame % kMaxFrameContexts] = { controls };\n+\tIPAFrameContext &frameContext = context_.frameContexts.alloc(frame);\n+\n+\t/* \\todo Implement queueRequest to each algorithm. */\n+\tframeContext.frameControls = controls;\n }\n \n /**\n","prefixes":["libcamera-devel","v5","10/33"]}