{"id":21398,"url":"https://patchwork.libcamera.org/api/1.1/patches/21398/?format=json","web_url":"https://patchwork.libcamera.org/patch/21398/","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":"<20240927134624.801004-6-mzamazal@redhat.com>","date":"2024-09-27T13:46:11","name":"[v8,05/18] libcamera: software_isp: Make stats frame and buffer aware","commit_ref":"c64f2f197a7eeefd283af2a1cc1c79ba76dbae0d","pull_url":null,"state":"accepted","archived":false,"hash":"f17abc2d4b4ae08da9e9e321def54539bc7529b8","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/21398/mbox/","series":[{"id":4634,"url":"https://patchwork.libcamera.org/api/1.1/series/4634/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4634","date":"2024-09-27T13:46:06","name":"Software ISP refactoring","version":8,"mbox":"https://patchwork.libcamera.org/series/4634/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21398/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21398/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 76ECDC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Sep 2024 13:46:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 748AD6351E;\n\tFri, 27 Sep 2024 15:46:53 +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 E110163519\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 15:46:47 +0200 (CEST)","from mx-prod-mc-03.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-505-Hrv9KAT3MByy6bYu7X-9UA-1;\n\tFri, 27 Sep 2024 09:46:45 -0400","from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown\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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 7AE7F18F4988; Fri, 27 Sep 2024 13:46:44 +0000 (UTC)","from nuthatch.redhat.com (unknown [10.45.224.123])\n\tby mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id A74D01944E45; Fri, 27 Sep 2024 13:46:42 +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=\"R1ba15Lx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1727444806;\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=zggw+12luMwqe+pkcziq9ChnBTV62x8urgGB28XWzmA=;\n\tb=R1ba15Lx2JFdj6HIGccSQjBI+WWc83M2AWEHra4Plb8Fy1biIugLrZuiKrCvtOUf2nF0+O\n\tj/DpbYtY7Za762H/CnWDkPQ8d0xNO66lOmnbJJ+2aBugzjCrLzPKRrNk0z0iFDvXuYyMT7\n\tWbObB0cb8DAVgB1m97ps9KLfrsmRwgk=","X-MC-Unique":"Hrv9KAT3MByy6bYu7X-9UA-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>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"[PATCH v8 05/18] libcamera: software_isp: Make stats frame and\n\tbuffer aware","Date":"Fri, 27 Sep 2024 15:46:11 +0200","Message-ID":"<20240927134624.801004-6-mzamazal@redhat.com>","In-Reply-To":"<20240927134624.801004-1-mzamazal@redhat.com>","References":"<20240927134624.801004-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>\nReviewed-by: Daniel Scally <dan.scally@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 f8e000036..3602bce85 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 0fd47bb0f..f65b6231d 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+\t\t\t     uint32 bufferId,\n+\t\t\t     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 72321f443..12b5245ed 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 81915573b..5aa52789f 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@@ -887,10 +888,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 8a757fe9e..6cc6946c7 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -807,7 +807,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 a3ae3e220..a38555684 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 815c4d4fa..c520c806e 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 363e326ff..26a2f462e 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":["v8","05/18"]}