Patch Detail
Show a patch.
GET /api/1.1/patches/20887/?format=api
{ "id": 20887, "url": "https://patchwork.libcamera.org/api/1.1/patches/20887/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20887/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20240812115009.946036-14-mzamazal@redhat.com>", "date": "2024-08-12T11:50:02", "name": "[13/16] libcamera: software_isp: Allocate statistics buffers", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "3dda1c9fc9e046f5a0b5ef799d36a1d962d69f7f", "submitter": { "id": 177, "url": "https://patchwork.libcamera.org/api/1.1/people/177/?format=api", "name": "Milan Zamazal", "email": "mzamazal@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20887/mbox/", "series": [ { "id": 4511, "url": "https://patchwork.libcamera.org/api/1.1/series/4511/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4511", "date": "2024-08-12T11:49:49", "name": "Software ISP: Share params and stats buffers", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4511/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20887/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20887/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 0AACBC324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Aug 2024 11:50:52 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7E6B8633D9;\n\tMon, 12 Aug 2024 13:50:51 +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 9C786633C7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 13:50:42 +0200 (CEST)", "from mx-prod-mc-05.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-657-sN3QjctLOk6o-JQBfG5abA-1;\n\tMon, 12 Aug 2024 07:50:40 -0400", "from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.15])\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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS\n\tid 9749B1955F3D for <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 11:50:39 +0000 (UTC)", "from nuthatch.redhat.com (unknown [10.45.225.57])\n\tby mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 8B9C419772C4; Mon, 12 Aug 2024 11:50:38 +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=\"bA/RPFGE\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1723463441;\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=RYkEQqU4OQMZuH1F9JMEKFSiqPXzGv1mheEG5il1IjA=;\n\tb=bA/RPFGEW4kEj1hnjWZ7tcLKJv848N0Nra7hYIv6T0DrSN1DAnEK7ksKKmKareILZ/CUD+\n\tBY1vmbjIFxGCmCA7aGt52Ss686Zrg3NTIAdoM4zcipNagZ1PBgTv7gWztLiU9fVPSJ1Y0E\n\t5dqhifovCbqTKC0DmHwwBLkgcwf7eTg=", "X-MC-Unique": "sN3QjctLOk6o-JQBfG5abA-1", "From": "Milan Zamazal <mzamazal@redhat.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Milan Zamazal <mzamazal@redhat.com>", "Subject": "[PATCH 13/16] libcamera: software_isp: Allocate statistics buffers", "Date": "Mon, 12 Aug 2024 13:50:02 +0200", "Message-ID": "<20240812115009.946036-14-mzamazal@redhat.com>", "In-Reply-To": "<20240812115009.946036-1-mzamazal@redhat.com>", "References": "<20240812115009.946036-1-mzamazal@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.0 on 10.30.177.15", "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": "In order to be able to use multiple shared statistics buffers, we must\nallocate them. They are allocated in SoftwareIsp and passed to\nSwIspStats. This changes the previous behavior when the (single) shared\nstatistics buffer was created in SwIspStats. Centralizing it to\nSoftwareIsp makes sharing multiple buffers with IPA easier.\n\nCurrently only one of the allocated buffers is used. This will be\nchanged once the buffers are shared with IPA in a followup patch.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n .../internal/software_isp/software_isp.h | 5 +++\n src/libcamera/software_isp/software_isp.cpp | 44 ++++++++++++++++---\n src/libcamera/software_isp/swstats_cpu.cpp | 16 ++++---\n src/libcamera/software_isp/swstats_cpu.h | 9 ++--\n 4 files changed, 57 insertions(+), 17 deletions(-)", "diff": "diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\nindex ae64b247..a6ba4a07 100644\n--- a/include/libcamera/internal/software_isp/software_isp.h\n+++ b/include/libcamera/internal/software_isp/software_isp.h\n@@ -33,6 +33,8 @@\n #include \"libcamera/internal/shared_mem_object.h\"\n #include \"libcamera/internal/software_isp/debayer_params.h\"\n \n+#include \"software_isp/swstats_cpu.h\"\n+\n namespace libcamera {\n \n class DebayerCpu;\n@@ -100,6 +102,9 @@ private:\n \tDebayerParams debayerParams_;\n \tstd::queue<uint32_t> availableParams_;\n \tbool allocateParamsBuffers(const unsigned int bufferCount);\n+\tstd::unique_ptr<SwStatsCpu> allocateStatsBuffers(\n+\t\tstd::vector<SharedFD> &fdStats,\n+\t\tconst unsigned int bufferCount);\n \tDmaBufAllocator dmaHeap_;\n \n \tstd::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\ndiff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\nindex 5d9f5008..1e224b6f 100644\n--- a/src/libcamera/software_isp/software_isp.cpp\n+++ b/src/libcamera/software_isp/software_isp.cpp\n@@ -12,6 +12,8 @@\n #include <sys/mman.h>\n #include <sys/types.h>\n #include <unistd.h>\n+#include <utility>\n+#include <vector>\n \n #include <libcamera/base/shared_fd.h>\n \n@@ -20,7 +22,9 @@\n #include <libcamera/stream.h>\n \n #include \"libcamera/internal/ipa_manager.h\"\n+#include \"libcamera/internal/shared_mem_object.h\"\n #include \"libcamera/internal/software_isp/debayer_params.h\"\n+#include \"libcamera/internal/software_isp/swisp_stats.h\"\n \n #include \"debayer_cpu.h\"\n \n@@ -79,17 +83,15 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n \tif (!allocateParamsBuffers(bufferCount))\n \t\treturn;\n \n-\tauto stats = std::make_unique<SwStatsCpu>();\n-\tif (!stats->isValid()) {\n-\t\tLOG(SoftwareIsp, Error) << \"Failed to create SwStatsCpu object\";\n-\t\treturn;\n-\t}\n-\tstats->statsReady.connect(this, &SoftwareIsp::statsReady);\n-\n \tstd::vector<SharedFD> fdParams;\n \tfor (auto &item : sharedParams_)\n \t\tfdParams.emplace_back(item.second.fd());\n \n+\tstd::vector<SharedFD> fdStats;\n+\tauto stats = allocateStatsBuffers(fdStats, bufferCount);\n+\tif (!stats)\n+\t\treturn;\n+\n \tdebayer_ = std::make_unique<DebayerCpu>(std::move(stats), fdParams);\n \tdebayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady);\n \tdebayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady);\n@@ -169,6 +171,34 @@ bool SoftwareIsp::allocateParamsBuffers(const unsigned int bufferCount)\n \treturn true;\n }\n \n+std::unique_ptr<SwStatsCpu> SoftwareIsp::allocateStatsBuffers(\n+\tstd::vector<SharedFD> &fdStats,\n+\tconst unsigned int bufferCount)\n+{\n+\tauto sharedStats = std::make_unique<std::map<uint32_t, SharedMemObject<SwIspStats>>>();\n+\tfor (unsigned int i = 0; i < bufferCount; i++) {\n+\t\tauto shared = SharedMemObject<SwIspStats>(\"softIsp_stats\");\n+\t\tif (!shared) {\n+\t\t\tLOG(SoftwareIsp, Error) << \"Failed to create shared memory for statistics\";\n+\t\t\treturn std::unique_ptr<SwStatsCpu>();\n+\t\t}\n+\t\tif (!shared.fd().isValid()) {\n+\t\t\tLOG(SoftwareIsp, Error) << \"Invalid fd of shared statistics\";\n+\t\t\treturn std::unique_ptr<SwStatsCpu>();\n+\t\t}\n+\n+\t\tASSERT(shared.fd().get() >= 0);\n+\t\tunsigned int bufferId = shared.fd().get();\n+\t\tfdStats.emplace_back(shared.fd());\n+\t\tsharedStats->emplace(bufferId, std::move(shared));\n+\t}\n+\n+\tauto stats = std::make_unique<SwStatsCpu>(std::move(sharedStats));\n+\tstats->statsReady.connect(this, &SoftwareIsp::statsReady);\n+\n+\treturn stats;\n+}\n+\n /**\n * \\fn int SoftwareIsp::loadConfiguration([[maybe_unused]] const std::string &filename)\n * \\brief Load a configuration from a file\ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex b8ee06a0..cb411a18 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -11,6 +11,8 @@\n \n #include \"swstats_cpu.h\"\n \n+#include <memory>\n+\n #include <libcamera/base/log.h>\n \n #include <libcamera/stream.h>\n@@ -129,12 +131,14 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(SwStatsCpu)\n \n-SwStatsCpu::SwStatsCpu()\n-\t: sharedStats_(\"softIsp_stats\")\n+/**\n+ * \\brief The constructor of SwStatsCpu\n+ * \\param [in] sharedStats Mapping of statistics buffer ids to statistics\n+ * instances that are shared with the IPA\n+ */\n+SwStatsCpu::SwStatsCpu(std::unique_ptr<std::map<uint32_t, SharedMemObject<SwIspStats>>> sharedStats)\n+\t: sharedStats_(std::move(sharedStats))\n {\n-\tif (!sharedStats_)\n-\t\tLOG(SwStatsCpu, Error)\n-\t\t\t<< \"Failed to create shared memory for statistics\";\n }\n \n static constexpr unsigned int kRedYMul = 77; /* 0.299 * 256 */\n@@ -316,7 +320,7 @@ void SwStatsCpu::startFrame([[maybe_unused]] const uint32_t statsBufferId)\n */\n void SwStatsCpu::finishFrame(uint32_t frame, const uint32_t statsBufferId)\n {\n-\t*sharedStats_ = stats_;\n+\t*(sharedStats_->at(statsBufferId)) = stats_;\n \tstatsReady.emit(frame, statsBufferId);\n }\n \ndiff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h\nindex 402eef2d..fbdea4a3 100644\n--- a/src/libcamera/software_isp/swstats_cpu.h\n+++ b/src/libcamera/software_isp/swstats_cpu.h\n@@ -11,6 +11,7 @@\n \n #pragma once\n \n+#include <map>\n #include <stdint.h>\n \n #include <libcamera/base/signal.h>\n@@ -29,12 +30,12 @@ struct StreamConfiguration;\n class SwStatsCpu\n {\n public:\n-\tSwStatsCpu();\n+\tSwStatsCpu(std::unique_ptr<std::map<uint32_t, SharedMemObject<SwIspStats>>> sharedStats);\n \t~SwStatsCpu() = default;\n \n-\tbool isValid() const { return sharedStats_.fd().isValid(); }\n+\tbool isValid() const { return sharedStats_->begin()->second.fd().isValid(); }\n \n-\tconst SharedFD &getStatsFD() { return sharedStats_.fd(); }\n+\tconst SharedFD &getStatsFD() { return sharedStats_->begin()->second.fd(); }\n \n \tconst Size &patternSize() { return patternSize_; }\n \n@@ -90,7 +91,7 @@ private:\n \n \tunsigned int xShift_;\n \n-\tSharedMemObject<SwIspStats> sharedStats_;\n+\tstd::unique_ptr<std::map<uint32_t, SharedMemObject<SwIspStats>>> sharedStats_;\n \tSwIspStats stats_;\n };\n \n", "prefixes": [ "13/16" ] }