From patchwork Thu Nov 20 23:20:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25109 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 36E85C3330 for ; Thu, 20 Nov 2025 23:20:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C120B60A80; Fri, 21 Nov 2025 00:20:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="J2zaqsXK"; dkim-atps=neutral Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A92DA60A80 for ; Fri, 21 Nov 2025 00:20:39 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-47790b080e4so7868475e9.3 for ; Thu, 20 Nov 2025 15:20:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1763680839; x=1764285639; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yrAaF8kfmIMdOuL0ewQtH4n9iA/J3ddd4eeCQCFdbAQ=; b=J2zaqsXKdYfb4qR5zRPZx9zUi3QgHE7nYaPzk8avgI+obGylmPvslxCEg1gicJIB9s zOFuMqbi6pG3qJJmRnaC9dujeK4dBwrA71XxBalcnUisIVyQY1j85qYHyZYLCtIKv1LZ 6BIShXxOFJBtQhilw5NPDP7kFKwdtZm/TS+Y55J/6+7ZJVFW/aFwtD82ajc7JtIJXRgp jAS7RutHSa0nv3uJNTR3TS/j3CD+b1IhdZh4WfrBliJgHmJ19vwFMuYbWj58ZrWvLyqj J1PljdaZWRytJd2wP2TWnPeLszhj8kCBeSUDKy9U8paiGRUs1An7vfo+jDiEmgKENX1I gkvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763680839; x=1764285639; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yrAaF8kfmIMdOuL0ewQtH4n9iA/J3ddd4eeCQCFdbAQ=; b=vi9lkEGNPyPUc9Q5gxdSf2WqCTOR0P152Zzn8thvNcWdXUY9SNS5u49rnORn7xSrJ7 B1X0/ZYjiC/430EqZH2llKOB1m5t3JXioOstKocbnCxfywvN/ZT1A6pChYqNUHIRIDk5 2FOb3MV25JuhPxbNlz8sY9wj3RjROJOcSPWLqvfzJqbVdp1nE1HeNdnRHdXmiQMnDlLI IGA4mDSnIrDd+S6DkeakDqtaIblVP2B9tid6KybwP8/sSK6OdmegC4VbEe2Y8Kl7ERuO v06oJiSXZ7nNvKRG4669FF8aTqpmI73f7ObwRS/FE0eFgKP6WZ6heV+lDQXt8ZDsfipS TlzQ== X-Gm-Message-State: AOJu0Ywk3566R2CKwBRUX/R8Gvso16HYIm/lfVabqvaiaU6rCOl0O+lK FRMIyvC1llguz4BUaDhNWWPNNkpIRGrDU3zevMK+L2Lb7pqN+3+kN5JNLFtnFkxDLHd25V/ICWd VpoP/61Y= X-Gm-Gg: ASbGncssvz/g6RmNFwOcbx3cgr6ENYrpm1xGKGC3BU6N4lj6K0Xo2qlRh1juclirtGU +ravdMLrvXSp/fdr1zNLVk0ZMynopggGtntvCvsyr9q4EfYvyng9Gs+IWHObDYs7s8HJWYnMb5i l4u2GjQ+tJkkHmhieDzRJnNGbat3AiZ8tH3G2TAuKb2X/MlrUgkmUCH1aykaXT+lC1gPr+oBcVj rs+kKXVMuifJi+kzJkECDcnobjQhqbf0XlHdim1Inu9g6QhG3nSxTSV28oF1kZ5Zyzo8T5mSISy F49wyS+ymem2fuu6bCZgFuMlOcQLvPy2mzHDtkCzA0H7WgOdssz76xe4ZNf7dBDT23dJre3ZkqG +IcAAQEWI0z8Mic56lLiRmZrtaETpYg/vw/SLvuyCCZ9N2KH8Vt6X95yZwBeoT7QPA684gHblaG Y5xWQFN02cgRwwtUZl1iObH92wbblk5l8W6IbqlrjkNhp4PiTPmoG4TM/k4e9DKb9IgeY= X-Google-Smtp-Source: AGHT+IGgZPdT5NZicNYjfh8wf1cTv/cHhtJi3V01I6n5XNRPO7z9oA9MFXsK8cnXMGEp2jgP3xFT+A== X-Received: by 2002:a05:600c:19d4:b0:477:63b5:6f3a with SMTP id 5b1f17b1804b1-477c112635amr345725e9.27.1763680838921; Thu, 20 Nov 2025 15:20:38 -0800 (PST) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477bf3af0ecsm11618415e9.9.2025.11.20.15.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 15:20:38 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Hans de Goede , Milan Zamazal , Kieran Bingham , Bryan O'Donoghue Subject: [PATCH 08/22] libcamera: swstats_cpu: Add processFrame() method Date: Thu, 20 Nov 2025 23:20:05 +0000 Message-ID: <20251120232019.3590-9-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251120232019.3590-1-bryan.odonoghue@linaro.org> References: <20251120232019.3590-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Hans de Goede Add a method to the SwstatsCpu class to process a whole Framebuffer in one go, rather then line by line. This is useful for gathering stats when debayering is not necessary or is not done on the CPU. Reviewed-by: Milan Zamazal Signed-off-by: Hans de Goede [bod: various rebase splats fixed] [bod: Added constructor Doxygen header] Reviewed-by: Kieran Bingham Signed-off-by: Bryan O'Donoghue --- .../internal/software_isp/swstats_cpu.h | 15 ++++- src/libcamera/software_isp/software_isp.cpp | 5 +- src/libcamera/software_isp/swstats_cpu.cpp | 64 ++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h index fae575f85..64b3e23f5 100644 --- a/include/libcamera/internal/software_isp/swstats_cpu.h +++ b/include/libcamera/internal/software_isp/swstats_cpu.h @@ -18,18 +18,23 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/framebuffer.h" +#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/shared_mem_object.h" #include "libcamera/internal/software_isp/swisp_stats.h" +#include "benchmark.h" + namespace libcamera { class PixelFormat; +class MappedFrameBuffer; struct StreamConfiguration; class SwStatsCpu { public: - SwStatsCpu(); + SwStatsCpu(const GlobalConfiguration &configuration); ~SwStatsCpu() = default; /* @@ -50,6 +55,7 @@ public: void setWindow(const Rectangle &window); void startFrame(uint32_t frame); void finishFrame(uint32_t frame, uint32_t bufferId); + void processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input); void processLine0(uint32_t frame, unsigned int y, const uint8_t *src[]) { @@ -79,6 +85,7 @@ public: private: using statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]); + using processFrameFn = void (SwStatsCpu::*)(MappedFrameBuffer &in); int setupStandardBayerOrder(BayerFormat::Order order); /* Bayer 8 bpp unpacked */ @@ -91,6 +98,10 @@ private: void statsBGGR10PLine0(const uint8_t *src[]); void statsGBRG10PLine0(const uint8_t *src[]); + void processBayerFrame2(MappedFrameBuffer &in); + + processFrameFn processFrame_; + /* Variables set by configure(), used every line */ statsProcessFn stats0_; statsProcessFn stats2_; @@ -103,9 +114,11 @@ private: Size patternSize_; unsigned int xShift_; + unsigned int stride_; SharedMemObject sharedStats_; SwIspStats stats_; + Benchmark bench_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 341c0352c..928a2520c 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -108,14 +108,15 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, return; } - auto stats = std::make_unique(); + const GlobalConfiguration &configuration = pipe->cameraManager()->_d()->configuration(); + + auto stats = std::make_unique(configuration); if (!stats->isValid()) { LOG(SoftwareIsp, Error) << "Failed to create SwStatsCpu object"; return; } stats->statsReady.connect(this, &SoftwareIsp::statsReady); - const GlobalConfiguration &configuration = pipe->cameraManager()->_d()->configuration(); debayer_ = std::make_unique(std::move(stats), configuration); debayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady); debayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady); diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 55e764b0a..f5906197b 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -16,6 +16,7 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/mapped_framebuffer.h" namespace libcamera { @@ -34,6 +35,15 @@ namespace libcamera { * instead of processing the whole frame. */ +/** + * \fn SwStatsCpu::SwStatsCpu(const GlobalConfiguration &configuration) + * \brief Construct a SwStatsCpu object + * \param[in] configuration Global configuration reference + * + * Creates a SwStatsCpu object and initialises shared memory for statistics + * exchange. + */ + /** * \fn bool SwStatsCpu::isValid() const * \brief Gets whether the statistics object is valid @@ -144,8 +154,8 @@ namespace libcamera { LOG_DEFINE_CATEGORY(SwStatsCpu) -SwStatsCpu::SwStatsCpu() - : sharedStats_("softIsp_stats") +SwStatsCpu::SwStatsCpu(const GlobalConfiguration &configuration) + : sharedStats_("softIsp_stats"), bench_(configuration) { if (!sharedStats_) LOG(SwStatsCpu, Error) @@ -386,11 +396,14 @@ int SwStatsCpu::setupStandardBayerOrder(BayerFormat::Order order) */ int SwStatsCpu::configure(const StreamConfiguration &inputCfg) { + stride_ = inputCfg.stride; + BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputCfg.pixelFormat); if (bayerFormat.packing == BayerFormat::Packing::None && setupStandardBayerOrder(bayerFormat.order) == 0) { + processFrame_ = &SwStatsCpu::processBayerFrame2; switch (bayerFormat.bitDepth) { case 8: stats0_ = &SwStatsCpu::statsBGGR8Line0; @@ -411,6 +424,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg) /* Skip every 3th and 4th line, sample every other 2x2 block */ ySkipMask_ = 0x02; xShift_ = 0; + processFrame_ = &SwStatsCpu::processBayerFrame2; switch (bayerFormat.order) { case BayerFormat::BGGR: @@ -475,4 +489,50 @@ void SwStatsCpu::setWindow(const Rectangle &window) window_.height &= ~(patternSize_.height - 1); } +void SwStatsCpu::processBayerFrame2(MappedFrameBuffer &in) +{ + const uint8_t *src = in.planes()[0].data(); + const uint8_t *linePointers[3]; + + /* Adjust src for starting at window_.y */ + src += window_.y * stride_; + + for (unsigned int y = 0; y < window_.height; y += 2) { + if (y & ySkipMask_) { + src += stride_ * 2; + continue; + } + + /* linePointers[0] is not used by any stats0_ functions */ + linePointers[1] = src; + linePointers[2] = src + stride_; + (this->*stats0_)(linePointers); + src += stride_ * 2; + } +} + +/** + * \brief Calculate statistics for a frame in one go + * \param[in] frame The frame number + * \param[in] bufferId ID of the statistics buffer + * \param[in] input The frame to process + * + * This may only be called after a successful setWindow() call. + */ +void SwStatsCpu::processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input) +{ + bench_.startFrame(); + startFrame(frame); + + MappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read); + if (!in.isValid()) { + LOG(SwStatsCpu, Error) << "mmap-ing buffer(s) failed"; + return; + } + + (this->*processFrame_)(in); + finishFrame(frame, bufferId); + bench_.finishFrame(); +} + } /* namespace libcamera */