{"id":23357,"url":"https://patchwork.libcamera.org/api/1.1/patches/23357/?format=json","web_url":"https://patchwork.libcamera.org/patch/23357/","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":"<20250510141220.54872-6-hdegoede@redhat.com>","date":"2025-05-10T14:12:17","name":"[v2,5/8] libcamera: swstats_cpu: Add processFrame() method","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"2d17decffe9749a830f95c0f75ce6aaed8ab3e81","submitter":{"id":102,"url":"https://patchwork.libcamera.org/api/1.1/people/102/?format=json","name":"Hans de Goede","email":"hdegoede@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23357/mbox/","series":[{"id":5169,"url":"https://patchwork.libcamera.org/api/1.1/series/5169/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5169","date":"2025-05-10T14:12:12","name":"libcamera: Add swstats_cpu::processFrame() and atomisp pipeline handler","version":2,"mbox":"https://patchwork.libcamera.org/series/5169/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23357/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23357/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 7FC22C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 10 May 2025 14:12:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E30468B68;\n\tSat, 10 May 2025 16:12:44 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D640B68B62\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 10 May 2025 16:12:41 +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-650-4z98azqlP9K-2uW-6Z3tpQ-1;\n\tSat, 10 May 2025 10:12:39 -0400","from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.93])\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 963D41956086 for <libcamera-devel@lists.libcamera.org>;\n\tSat, 10 May 2025 14:12:38 +0000 (UTC)","from localhost.localdomain (unknown [10.45.224.58])\n\tby mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 472841800359; Sat, 10 May 2025 14:12:37 +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=\"DtadYcBh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1746886361;\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=oXjQFWyQEO7ckjYtpecCE4rTR5BqusAWdvB1WYfoooc=;\n\tb=DtadYcBhLrTbI6Zx6JTER90hEskCHSBZZL6ReRyyw5A/KMFm7t9qFagsCaw1QaM5Ju1Wnw\n\teiSaHfZ1YqAV/lpNIfGbGLnZUY9Lip6To7yoz85y0d07Q0NNsszcsjKK4MzLGQY6gD5oQV\n\tGEKMgTWFaD2+TSpf+VSz4Cd2O2QUmYY=","X-MC-Unique":"4z98azqlP9K-2uW-6Z3tpQ-1","X-Mimecast-MFC-AGG-ID":"4z98azqlP9K-2uW-6Z3tpQ_1746886358","From":"Hans de Goede <hdegoede@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>, Hans de Goede <hdegoede@redhat.com>","Subject":"[PATCH v2 5/8] libcamera: swstats_cpu: Add processFrame() method","Date":"Sat, 10 May 2025 16:12:17 +0200","Message-ID":"<20250510141220.54872-6-hdegoede@redhat.com>","In-Reply-To":"<20250510141220.54872-1-hdegoede@redhat.com>","References":"<20250510141220.54872-1-hdegoede@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.93","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"MXL75LiMOfoUXzYu8cqkcVCfurd8LAeC3IilfaTNso4_1746886358","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":"Add a method to the SwstatsCpu class to process a whole Framebuffer in\none go, rather then line by line. This is useful for gathering stats\nwhen debayering is not necessary or is not done on the CPU.\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\nChanges since the RFC:\n- Make processFrame() call startFrame() and finishFrame() rather then\n  making the caller do this\n- Add doxygen documentation for processFrame()\n---\n .../internal/software_isp/swstats_cpu.h       | 12 +++++\n src/libcamera/software_isp/swstats_cpu.cpp    | 51 +++++++++++++++++++\n 2 files changed, 63 insertions(+)","diff":"diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\nindex 26a2f462..fa47cec9 100644\n--- a/include/libcamera/internal/software_isp/swstats_cpu.h\n+++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n@@ -18,12 +18,16 @@\n #include <libcamera/geometry.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/framebuffer.h\"\n #include \"libcamera/internal/shared_mem_object.h\"\n #include \"libcamera/internal/software_isp/swisp_stats.h\"\n \n+#include \"benchmark.h\"\n+\n namespace libcamera {\n \n class PixelFormat;\n+class MappedFrameBuffer;\n struct StreamConfiguration;\n \n class SwStatsCpu\n@@ -42,6 +46,7 @@ public:\n \tvoid setWindow(const Rectangle &window);\n \tvoid startFrame();\n \tvoid finishFrame(uint32_t frame, uint32_t bufferId);\n+\tvoid processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input);\n \n \tvoid processLine0(unsigned int y, const uint8_t *src[])\n \t{\n@@ -65,6 +70,7 @@ public:\n \n private:\n \tusing statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]);\n+\tusing processFrameFn = void (SwStatsCpu::*)(MappedFrameBuffer &in);\n \n \tint setupStandardBayerOrder(BayerFormat::Order order);\n \t/* Bayer 8 bpp unpacked */\n@@ -77,6 +83,10 @@ private:\n \tvoid statsBGGR10PLine0(const uint8_t *src[]);\n \tvoid statsGBRG10PLine0(const uint8_t *src[]);\n \n+\tvoid processBayerFrame2(MappedFrameBuffer &in);\n+\n+\tprocessFrameFn processFrame_;\n+\n \t/* Variables set by configure(), used every line */\n \tstatsProcessFn stats0_;\n \tstatsProcessFn stats2_;\n@@ -89,9 +99,11 @@ private:\n \tSize patternSize_;\n \n \tunsigned int xShift_;\n+\tunsigned int stride_;\n \n \tSharedMemObject<SwIspStats> sharedStats_;\n \tSwIspStats stats_;\n+\tBenchmark bench_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex aa5654dc..1ff15f5b 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -16,6 +16,7 @@\n #include <libcamera/stream.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n namespace libcamera {\n \n@@ -360,11 +361,14 @@ int SwStatsCpu::setupStandardBayerOrder(BayerFormat::Order order)\n  */\n int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n {\n+\tstride_ = inputCfg.stride;\n+\n \tBayerFormat bayerFormat =\n \t\tBayerFormat::fromPixelFormat(inputCfg.pixelFormat);\n \n \tif (bayerFormat.packing == BayerFormat::Packing::None &&\n \t    setupStandardBayerOrder(bayerFormat.order) == 0) {\n+\t\tprocessFrame_ = &SwStatsCpu::processBayerFrame2;\n \t\tswitch (bayerFormat.bitDepth) {\n \t\tcase 8:\n \t\t\tstats0_ = &SwStatsCpu::statsBGGR8Line0;\n@@ -385,6 +389,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n \t\t/* Skip every 3th and 4th line, sample every other 2x2 block */\n \t\tySkipMask_ = 0x02;\n \t\txShift_ = 0;\n+\t\tprocessFrame_ = &SwStatsCpu::processBayerFrame2;\n \n \t\tswitch (bayerFormat.order) {\n \t\tcase BayerFormat::BGGR:\n@@ -425,4 +430,50 @@ void SwStatsCpu::setWindow(const Rectangle &window)\n \twindow_.height &= ~(patternSize_.height - 1);\n }\n \n+void SwStatsCpu::processBayerFrame2(MappedFrameBuffer &in)\n+{\n+\tconst uint8_t *src = in.planes()[0].data();\n+\tconst uint8_t *linePointers[3];\n+\n+\t/* Adjust src for starting at window_.y */\n+\tsrc += window_.y * stride_;\n+\n+\tfor (unsigned int y = 0; y < window_.height; y += 2) {\n+\t\tif (y & ySkipMask_) {\n+\t\t\tsrc += stride_ * 2;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* linePointers[0] is not used by any stats0_ functions */\n+\t\tlinePointers[1] = src;\n+\t\tlinePointers[2] = src + stride_;\n+\t\t(this->*stats0_)(linePointers);\n+\t\tsrc += stride_ * 2;\n+\t}\n+}\n+\n+/**\n+ * \\brief Calculate statistics for a frame in one go\n+ * \\param[in] frame The frame number\n+ * \\param[in] bufferId ID of the statistics buffer\n+ * \\param[in] input The frame to process\n+ *\n+ * This may only be called after a successful setWindow() call.\n+ */\n+void SwStatsCpu::processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input)\n+{\n+\tbench_.startFrame();\n+\tstartFrame();\n+\n+\tMappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read);\n+\tif (!in.isValid()) {\n+\t\tLOG(SwStatsCpu, Error) << \"mmap-ing buffer(s) failed\";\n+\t\treturn;\n+\t}\n+\n+\t(this->*processFrame_)(in);\n+\tfinishFrame(frame, bufferId);\n+\tbench_.finishFrame();\n+}\n+\n } /* namespace libcamera */\n","prefixes":["v2","5/8"]}