[{"id":31029,"web_url":"https://patchwork.libcamera.org/comment/31029/","msgid":"<20240901200036.GB7282@pendragon.ideasonboard.com>","date":"2024-09-01T20:00:36","subject":"Re: [PATCH v5 05/18] libcamera: software_isp: Make stats frame and\n\tbuffer aware","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Milan,\n\nThank you for the patch.\n\nOn Fri, Aug 30, 2024 at 09:25:41AM +0200, Milan Zamazal wrote:\n> This patch adds frame and bufferId arguments to stats related calls.\n> Although the parameters are currently unused, because frame ids are not\n> tracked and used and the stats buffer is passed around directly rather\n> than being referred by its id, they bring the internal APIs closer to\n> their counterparts in hardware pipelines.\n> \n> It 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> \n> Frame and buffer ids are unrelated for the given purposes but since they\n> are passed together at the same places, the change is implemented as a\n> single patch rather than two, basically the same, patches.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> Reviewed-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(-)\n> \n> diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\n> index 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>  \n> diff --git a/include/libcamera/ipa/soft.mojom b/include/libcamera/ipa/soft.mojom\n> index 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\nWrong indentation (use tabs instead of spaces). I'll fix it locally if\nthere's no need for a v6.\n\n>  };\n>  \n>  interface IPASoftEventInterface {\n> diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\n> index 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)\n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 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>  \n> diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\n> index 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>  }\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index 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)\n> diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n> index 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>  /**\n> diff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h\n> index 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[]);","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 A2132C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  1 Sep 2024 20:01:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC75B63469;\n\tSun,  1 Sep 2024 22:01:09 +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 7CD2F63466\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  1 Sep 2024 22:01:07 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 846594CE;\n\tSun,  1 Sep 2024 21:59:56 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"DJwpS57p\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1725220796;\n\tbh=kmijR5XKuvYAF3i+nIK2jm2NYV3DtcM/aK15wgZdigU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DJwpS57p+Y5DHgVW3QVZQQ4FwMB/nzZviM9dwf6INBN8fG23e6p5JtJU2MVV2AhPD\n\tKTO8Lb14A5rwbBuNhGIHrwCO/msa6q8v6LWat48k7EYQVFHL/6vxbgF2ruM7B8Gc4m\n\thzxUUsb3IVx+oeMYG+H/VQPlTg5hRH1ygRIKBFvE=","Date":"Sun, 1 Sep 2024 23:00:36 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>","Subject":"Re: [PATCH v5 05/18] libcamera: software_isp: Make stats frame and\n\tbuffer aware","Message-ID":"<20240901200036.GB7282@pendragon.ideasonboard.com>","References":"<20240830072554.180672-1-mzamazal@redhat.com>\n\t<20240830072554.180672-6-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240830072554.180672-6-mzamazal@redhat.com>","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>"}}]