{"id":21061,"url":"https://patchwork.libcamera.org/api/1.1/patches/21061/?format=json","web_url":"https://patchwork.libcamera.org/patch/21061/","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":"<20240830072554.180672-6-mzamazal@redhat.com>","date":"2024-08-30T07:25:41","name":"[v5,05/18] libcamera: software_isp: Make stats frame and buffer aware","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e6a847462aefbaf31b1930520e4f696c22d54fde","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/1.1/people/177/?format=json","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21061/mbox/","series":[{"id":4548,"url":"https://patchwork.libcamera.org/api/1.1/series/4548/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4548","date":"2024-08-30T07:25:36","name":"Software ISP refactoring","version":5,"mbox":"https://patchwork.libcamera.org/series/4548/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21061/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21061/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 0AD5DC32C2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 30 Aug 2024 07:26:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 90C3B634CB;\n\tFri, 30 Aug 2024 09:26:24 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CF53A634BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 30 Aug 2024 09:26:21 +0200 (CEST)","from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-523-Io6m27VJML6RX3GpbSi-6g-1;\n\tFri, 30 Aug 2024 03:26:17 -0400","from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.40])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 8FCE819560B7; Fri, 30 Aug 2024 07:26:16 +0000 (UTC)","from nuthatch.redhat.com (unknown [10.45.225.65])\n\tby mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 7072519560A3; Fri, 30 Aug 2024 07:26:14 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"CiLFGxYq\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1725002780;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=q2v30WFtc+QLkbchyPhtbVVN0nHMzx8KfR3ygJ58HBw=;\n\tb=CiLFGxYqDbU66Z5pkBLL+wE6ZqT7G8UHGFNTI0fXt3QRjmtOp6dsNedyizGsP3Cz0F5Yvd\n\tLtT1y0JXW21tVJ7TP2FHQshsQk30mALRKLPSJMgo4WECZGGRAHtkW3T2k/JRcz83KytqP+\n\tVTPoLjRjntyIxiRtdRjUPiyHD4fSBhY=","X-MC-Unique":"Io6m27VJML6RX3GpbSi-6g-1","From":"Milan Zamazal <mzamazal@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>,\n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>","Subject":"[PATCH v5 05/18] libcamera: software_isp: Make stats frame and\n\tbuffer aware","Date":"Fri, 30 Aug 2024 09:25:41 +0200","Message-ID":"<20240830072554.180672-6-mzamazal@redhat.com>","In-Reply-To":"<20240830072554.180672-1-mzamazal@redhat.com>","References":"<20240830072554.180672-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.40","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain; charset=\"US-ASCII\"; x-default=true","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This patch adds frame and bufferId arguments to stats related calls.\nAlthough the parameters are currently unused, because frame ids are not\ntracked and used and the stats buffer is passed around directly rather\nthan being referred by its id, they bring the internal APIs closer to\ntheir counterparts in hardware pipelines.\n\nIt serves as a preparation for followup patches that will introduce:\n\n- Frame number tracking in order to switch to DelayedControls\n  (software ISP TODO #11 + #12).\n- A ring buffer for stats in order to improve passing the stats\n  (software ISP TODO #2).\n\nFrame and buffer ids are unrelated for the given purposes but since they\nare passed together at the same places, the change is implemented as a\nsingle patch rather than two, basically the same, patches.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n .../libcamera/internal/software_isp/software_isp.h    |  8 +++++---\n include/libcamera/ipa/soft.mojom                      |  4 +++-\n src/ipa/simple/soft_simple.cpp                        |  7 +++++--\n src/libcamera/pipeline/simple/simple.cpp              |  8 +++++---\n src/libcamera/software_isp/debayer_cpu.cpp            |  8 +++++++-\n src/libcamera/software_isp/software_isp.cpp           | 11 +++++++----\n src/libcamera/software_isp/swstats_cpu.cpp            |  6 ++++--\n src/libcamera/software_isp/swstats_cpu.h              |  4 ++--\n 8 files changed, 38 insertions(+), 18 deletions(-)","diff":"diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\nindex f8e00003..3602bce8 100644\n--- a/include/libcamera/internal/software_isp/software_isp.h\n+++ b/include/libcamera/internal/software_isp/software_isp.h\n@@ -11,6 +11,7 @@\n #include <initializer_list>\n #include <map>\n #include <memory>\n+#include <stdint.h>\n #include <string>\n #include <tuple>\n #include <vector>\n@@ -66,7 +67,8 @@ public:\n \tint exportBuffers(const Stream *stream, unsigned int count,\n \t\t\t  std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n \n-\tvoid processStats(const ControlList &sensorControls);\n+\tvoid processStats(const uint32_t frame, const uint32_t bufferId,\n+\t\t\t  const ControlList &sensorControls);\n \n \tint start();\n \tvoid stop();\n@@ -78,13 +80,13 @@ public:\n \n \tSignal<FrameBuffer *> inputBufferReady;\n \tSignal<FrameBuffer *> outputBufferReady;\n-\tSignal<> ispStatsReady;\n+\tSignal<uint32_t, uint32_t> ispStatsReady;\n \tSignal<const ControlList &> setSensorControls;\n \n private:\n \tvoid saveIspParams();\n \tvoid setSensorCtrls(const ControlList &sensorControls);\n-\tvoid statsReady();\n+\tvoid statsReady(uint32_t frame, uint32_t bufferId);\n \tvoid inputReady(FrameBuffer *input);\n \tvoid outputReady(FrameBuffer *output);\n \ndiff --git a/include/libcamera/ipa/soft.mojom b/include/libcamera/ipa/soft.mojom\nindex 0fd47bb0..cc5c37b2 100644\n--- a/include/libcamera/ipa/soft.mojom\n+++ b/include/libcamera/ipa/soft.mojom\n@@ -23,7 +23,9 @@ interface IPASoftInterface {\n \tconfigure(libcamera.ControlInfoMap sensorCtrlInfoMap)\n \t\t=> (int32 ret);\n \n-\t[async] processStats(libcamera.ControlList sensorControls);\n+\t[async] processStats(uint32 frame,\n+                             uint32 bufferId,\n+                             libcamera.ControlList sensorControls);\n };\n \n interface IPASoftEventInterface {\ndiff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\nindex 72321f44..12b5245e 100644\n--- a/src/ipa/simple/soft_simple.cpp\n+++ b/src/ipa/simple/soft_simple.cpp\n@@ -75,7 +75,8 @@ public:\n \tint start() override;\n \tvoid stop() override;\n \n-\tvoid processStats(const ControlList &sensorControls) override;\n+\tvoid processStats(const uint32_t frame, const uint32_t bufferId,\n+\t\t\t  const ControlList &sensorControls) override;\n \n protected:\n \tstd::string logPrefix() const override;\n@@ -249,7 +250,9 @@ void IPASoftSimple::stop()\n {\n }\n \n-void IPASoftSimple::processStats(const ControlList &sensorControls)\n+void IPASoftSimple::processStats([[maybe_unused]] const uint32_t frame,\n+\t\t\t\t [[maybe_unused]] const uint32_t bufferId,\n+\t\t\t\t const ControlList &sensorControls)\n {\n \tSwIspStats::Histogram histogram = stats_->yHistogram;\n \tif (ignoreUpdates_ > 0)\ndiff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 1e7ec7d9..48a568da 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -13,6 +13,7 @@\n #include <memory>\n #include <queue>\n #include <set>\n+#include <stdint.h>\n #include <string.h>\n #include <string>\n #include <unordered_map>\n@@ -291,7 +292,7 @@ private:\n \tvoid conversionInputDone(FrameBuffer *buffer);\n \tvoid conversionOutputDone(FrameBuffer *buffer);\n \n-\tvoid ispStatsReady();\n+\tvoid ispStatsReady(uint32_t frame, uint32_t bufferId);\n \tvoid setSensorControls(const ControlList &sensorControls);\n };\n \n@@ -891,10 +892,11 @@ void SimpleCameraData::conversionOutputDone(FrameBuffer *buffer)\n \t\tpipe->completeRequest(request);\n }\n \n-void SimpleCameraData::ispStatsReady()\n+void SimpleCameraData::ispStatsReady(uint32_t frame, uint32_t bufferId)\n {\n \t/* \\todo Use the DelayedControls class */\n-\tswIsp_->processStats(sensor_->getControls({ V4L2_CID_ANALOGUE_GAIN,\n+\tswIsp_->processStats(frame, bufferId,\n+\t\t\t     sensor_->getControls({ V4L2_CID_ANALOGUE_GAIN,\n \t\t\t\t\t\t    V4L2_CID_EXPOSURE }));\n }\n \ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 077f7f4b..2a2e7edb 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -777,7 +777,13 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams\n \t\t}\n \t}\n \n-\tstats_->finishFrame();\n+\t/*\n+\t * Frame and buffer ids are currently not used, so pass zeros as parameters.\n+\t *\n+\t * \\todo Pass real values once frame is passed here and stats buffer passing\n+\t * is changed.\n+\t */\n+\tstats_->finishFrame(0, 0);\n \toutputBufferReady.emit(output);\n \tinputBufferReady.emit(input);\n }\ndiff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\nindex a3ae3e22..a3855568 100644\n--- a/src/libcamera/software_isp/software_isp.cpp\n+++ b/src/libcamera/software_isp/software_isp.cpp\n@@ -155,15 +155,18 @@ SoftwareIsp::~SoftwareIsp()\n \n /**\n  * \\brief Process the statistics gathered\n+ * \\param[in] frame The frame number\n+ * \\param[in] bufferId ID of the statistics buffer\n  * \\param[in] sensorControls The sensor controls\n  *\n  * Requests the IPA to calculate new parameters for ISP and new control\n  * values for the sensor.\n  */\n-void SoftwareIsp::processStats(const ControlList &sensorControls)\n+void SoftwareIsp::processStats(const uint32_t frame, const uint32_t bufferId,\n+\t\t\t       const ControlList &sensorControls)\n {\n \tASSERT(ipa_);\n-\tipa_->processStats(sensorControls);\n+\tipa_->processStats(frame, bufferId, sensorControls);\n }\n \n /**\n@@ -349,9 +352,9 @@ void SoftwareIsp::setSensorCtrls(const ControlList &sensorControls)\n \tsetSensorControls.emit(sensorControls);\n }\n \n-void SoftwareIsp::statsReady()\n+void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId)\n {\n-\tispStatsReady.emit();\n+\tispStatsReady.emit(frame, bufferId);\n }\n \n void SoftwareIsp::inputReady(FrameBuffer *input)\ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex 815c4d4f..c520c806 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -311,13 +311,15 @@ void SwStatsCpu::startFrame(void)\n \n /**\n  * \\brief Finish statistics calculation for the current frame\n+ * \\param[in] frame The frame number\n+ * \\param[in] bufferId ID of the statistics buffer\n  *\n  * This may only be called after a successful setWindow() call.\n  */\n-void SwStatsCpu::finishFrame(void)\n+void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId)\n {\n \t*sharedStats_ = stats_;\n-\tstatsReady.emit();\n+\tstatsReady.emit(frame, bufferId);\n }\n \n /**\ndiff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h\nindex 363e326f..26a2f462 100644\n--- a/src/libcamera/software_isp/swstats_cpu.h\n+++ b/src/libcamera/software_isp/swstats_cpu.h\n@@ -41,7 +41,7 @@ public:\n \tint configure(const StreamConfiguration &inputCfg);\n \tvoid setWindow(const Rectangle &window);\n \tvoid startFrame();\n-\tvoid finishFrame();\n+\tvoid finishFrame(uint32_t frame, uint32_t bufferId);\n \n \tvoid processLine0(unsigned int y, const uint8_t *src[])\n \t{\n@@ -61,7 +61,7 @@ public:\n \t\t(this->*stats2_)(src);\n \t}\n \n-\tSignal<> statsReady;\n+\tSignal<uint32_t, uint32_t> statsReady;\n \n private:\n \tusing statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]);\n","prefixes":["v5","05/18"]}