From patchwork Wed Dec 2 16:13:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 29154 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 17B13C3355 for ; Thu, 3 Dec 2026 13:01:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B065C6AB47; Thu, 3 Dec 2026 14:01:24 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="dSgyXRoz"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 281C46AB32 for ; Thu, 3 Dec 2026 14:01:20 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-49d05d51553so97789545e9.2 for ; Thu, 03 Dec 2026 05:01:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1796302880; x=1796907680; 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:content-type; bh=N2uOILXEkguN/s7HMS9v1nbDmLk10XCivmquIUtE4zA=; b=dSgyXRozTdkdF2qDWKjHZAhPTETK5Z0si470hYS2hWzu/D3eam/AJB+2C0OKr1DV0f 7BEfQWjeoWar7Owna73FQ+UoobqYnNxj3y4OodmIwISjsTo4izsbLGXB8Vdv4zIJhT86 1+MGaEgoZuGAdokKSgNw5txOg9vc8/sMCnXnRFhW3BUouXK9s+L9Qmau0Ay7VPmCw/t5 ET6QkHVNm47n8qd3jCT9dgu2xkCVAh/zOTG8DhcE0PwZLw2hvX34pK4fZZZPgZIn5MKr 4l07OdG8Rkh0DqfMR3fGeSLYOwNbyalB21YjrVN0npzxaD7J5ZuYTZO2wzQxqr+R7oxF DX6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796302880; x=1796907680; 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:content-type; bh=N2uOILXEkguN/s7HMS9v1nbDmLk10XCivmquIUtE4zA=; b=ujSkKQHK8QRR2Z+lw5xrIqGJjhuWOxWTbMo7Cx1Qpu7ygSG8DvrgB2zqUxxE5bcNsm q43Px8jIZp21du0G0FZkli5G451ZHnPG299G2NJ4xeuHalqT/XZ/fHr4NCt0GCJIu72w T+OaR0krDk/EbvfBpiagutcc2XJ9jMUilKBgS+zW7jzXFV5mcAWa5oJNy3ip38GAiGWv 5THJhvaHflVeb1GfvFklacIfh9qitsJ2p9rToVZpaMh3z7QGZwU49sw6ZEvx1g20i909 1TLbgHyQIxj+JDTGI6yCeIv/lMoINNiNWqQG5BRihpPISp9AkC1pA88IEl5CW+/atnyE 1sWQ== X-Gm-Message-State: APuU4Z8lyJLiUa8a91BQzRUKQ3ep4m996iGdJ+vfnD0DvU8ubQr8E4fz XmqupELJGjRHkNlCpEtkQrm8q51q5cnaWYtlmBcoaprbqlLdaB9JokS3wigzEX7zYyoSEB5oR8K AvxA/ckQ= X-Gm-Gg: AZFdTZc+4nyNHVo8X06NQw8JQyOa3wu+pFuAd4VaTyqiNZHWIKEJpiaQZOn0ndE+Qdh /AXR/0wfUkRBztHw0caRTcSJK9KLj4qPkG8pM9s+9j/k8yDHv7GE7Fb8Er/FcxmESA361Pgpq61 lmoIbHNyL89Eja+XfOOeHWyEZOp+Rj1WiL0R1L8usJNEfz2ede4tHem81XyJlNPTUi1ZwNDPF1L cM9Zeqy0k0EUn3JmYnFvIv3d9/W5zWdY9KuG5+i/8TtfklOYSoEVZKNNUZrZGdGBLWx5JqOcfYA Af/AwUaYBq1SXaUenlo3a+FkeGIiOhGlAqK1/lghgCJG1AxSf3+Tq//4EqPxfKyyuPq7qTMKOrm Qt4ILTZx35nqOSz/gXNYZMAq0+B+EnW8WZwtLQF/U/eHZ5AZwLyVU6bwtZ1nLQS7+6Z4NNv1IVh B2tWB9lm6fPf0yk1+LsIElR5ZrVYfM1pgueuhDT+9JXRDPKtIFCv0RTehvBovelczD8RNJU2bSM IXapFPOotjXJVmKp/4J5+uAcBMukPU281FpL0vMEDtXf3SsHsO3Io7LQ6fOm6GjX/a2kUhI9ZpB 7yRuXzeuQTHPH34JosRWabBDKLXh0avsaxklXpJmSMNd8ftU/hKJQUgJkAg7XLOjJU+CdWn6rRe x9jnnLUpjb2fZea9mnXX82CzXE2RE/GJXUBoT3H8sDUgfiu0hqw== X-Received: by 2002:a05:600c:4e0c:b0:4bb:875b:f23f with SMTP id 5b1f17b1804b1-4bb88827f0bmr830874855e9.33.1796302879340; Thu, 03 Dec 2026 05:01:19 -0800 (PST) Received: from davidp-hailo10.pitowers.org ([2a00:1098:3142:1f:9afe:54ff:fe21:ed41]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe005543esm81555685e9.5.2026.12.03.05.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:01:18 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH v1 5/5] pipeline: rpi: Add an example additional pipeline "stage" Date: Wed, 2 Dec 2026 16:13:27 +0000 Message-ID: <20261203130113.47873-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203130113.47873-1-david.plowman@raspberrypi.com> References: <20261203130113.47873-1-david.plowman@raspberrypi.com> 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 Add an example stage, consisting of both the IPA that controls it, and the stage itself running under the pipeline handler. The example stage shows how these, and any associated mojom parameters, need to be plumbed into the code, which is the pattern other future "stages" should follow. This example stage does nothing useful itself, but we leave it here as the canonical example of adding new stages. The only thing missing in order to enable and run it, is to add the control algorithm ("rpi.example_stage") to the JSON tuning file. Signed-off-by: David Plowman --- include/libcamera/ipa/raspberrypi.mojom | 22 +++++-- src/ipa/rpi/common/ipa_base.cpp | 17 ++++- src/ipa/rpi/controller/example_stage_status.h | 20 ++++++ src/ipa/rpi/controller/meson.build | 1 + src/ipa/rpi/controller/rpi/example_stage.cpp | 63 ++++++++++++++++++ src/ipa/rpi/controller/rpi/example_stage.h | 33 ++++++++++ src/libcamera/pipeline/rpi/common/meson.build | 1 + .../pipeline/rpi/common/pipeline_base.h | 8 +-- .../rpi/common/stages/example_stage.cpp | 66 +++++++++++++++++++ .../rpi/common/stages/example_stage.h | 35 ++++++++++ 10 files changed, 255 insertions(+), 11 deletions(-) create mode 100644 src/ipa/rpi/controller/example_stage_status.h create mode 100644 src/ipa/rpi/controller/rpi/example_stage.cpp create mode 100644 src/ipa/rpi/controller/rpi/example_stage.h create mode 100644 src/libcamera/pipeline/rpi/common/stages/example_stage.cpp create mode 100644 src/libcamera/pipeline/rpi/common/stages/example_stage.h diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index eaeb8398..574f3dfc 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -46,20 +46,30 @@ struct ConfigParams { libcamera.SharedFD lsTableHandle; }; +/* Configuration for the example pipeline stage. */ +struct ExampleStageConfig { + bool enabled; + uint32 delayMs; /* sleep this long on every frame */ +}; + +/* Per-frame parameters for the example pipeline stage. */ +struct ExampleStageParams { + uint32 frame; + float analogueGain; +}; + /* * Configuration of the pipeline handler "stages", which operate on the raw - * Bayer buffers after prepareIsp() and before the ISP proper. There will be - * one structure per stage type here. + * Bayer buffers after prepareIsp() and before the ISP proper. There is one + * structure per stage type here. */ struct StageConfig { - /* Placeholder - remove once we have a stage. */ - bool unused; + ExampleStageConfig example; }; /* Per-frame parameters for the pipeline handler stages, one structure per stage. */ struct StageParams { - /* Placeholder - remove once we have a stage. */ - bool unused; + ExampleStageParams example; }; struct ConfigResult { diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index 7726a768..a131fb72 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -25,6 +25,7 @@ #include "controller/ccm_status.h" #include "controller/contrast_algorithm.h" #include "controller/denoise_algorithm.h" +#include "controller/example_stage_status.h" #include "controller/hdr_algorithm.h" #include "controller/lux_status.h" #include "controller/sharpen_algorithm.h" @@ -529,13 +530,27 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms) /* Fill in the configuration for the pipeline handler stages. */ void IpaBase::fillStageConfig(StageConfig &config) { + RPiController::Metadata &globalMetadata = controller_.getGlobalMetadata(); + config = {}; + + ExampleStageTuning exampleTuning; + if (globalMetadata.get("example_stage.config", exampleTuning) == 0) { + config.example.enabled = true; + config.example.delayMs = exampleTuning.delayMs; + } } /* Fill in the parameters for the pipeline handler stages for this frame. */ -void IpaBase::prepareStageParams([[maybe_unused]] const RPiController::Metadata &rpiMetadata) +void IpaBase::prepareStageParams(const RPiController::Metadata &rpiMetadata) { lastStageParams_ = {}; + + ExampleStageStatus exampleStatus; + if (rpiMetadata.get("example_stage.status", exampleStatus) == 0) { + lastStageParams_.example.frame = exampleStatus.frame; + lastStageParams_.example.analogueGain = exampleStatus.analogueGain; + } } /* diff --git a/src/ipa/rpi/controller/example_stage_status.h b/src/ipa/rpi/controller/example_stage_status.h new file mode 100644 index 00000000..43b25649 --- /dev/null +++ b/src/ipa/rpi/controller/example_stage_status.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2026, Raspberry Pi Ltd + * + * Example pipeline stage algorithm status + */ +#pragma once + +#include + +/* The example stage algorithm controls the example pipeline handler stage. */ + +struct ExampleStageTuning { + uint32_t delayMs; /* sleep this long on every frame */ +}; + +struct ExampleStageStatus { + uint32_t frame; + double analogueGain; +}; diff --git a/src/ipa/rpi/controller/meson.build b/src/ipa/rpi/controller/meson.build index 03ee7c20..35156245 100644 --- a/src/ipa/rpi/controller/meson.build +++ b/src/ipa/rpi/controller/meson.build @@ -18,6 +18,7 @@ rpi_ipa_controller_sources = files([ 'rpi/decompand.cpp', 'rpi/denoise.cpp', 'rpi/dpc.cpp', + 'rpi/example_stage.cpp', 'rpi/geq.cpp', 'rpi/hdr.cpp', 'rpi/lux.cpp', diff --git a/src/ipa/rpi/controller/rpi/example_stage.cpp b/src/ipa/rpi/controller/rpi/example_stage.cpp new file mode 100644 index 00000000..b1adad1e --- /dev/null +++ b/src/ipa/rpi/controller/rpi/example_stage.cpp @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2026, Raspberry Pi Ltd + * + * Example pipeline stage algorithm + */ + +#include "example_stage.h" + +#include + +#include "../device_status.h" + +using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiExampleStage) + +#define NAME "rpi.example_stage" + +ExampleStage::ExampleStage(Controller *controller) + : Algorithm(controller), tuning_{}, frame_(0) +{ +} + +char const *ExampleStage::name() const +{ + return NAME; +} + +int ExampleStage::read(const libcamera::ValueNode ¶ms) +{ + tuning_.delayMs = params["delay_ms"].get(0); + + return 0; +} + +void ExampleStage::initialise() +{ + /* Send the config data to the pipeline handler early. */ + getGlobalMetadata().set("example_stage.config", tuning_); +} + +void ExampleStage::prepare(Metadata *imageMetadata) +{ + ExampleStageStatus status{}; + status.frame = frame_++; + + DeviceStatus deviceStatus; + if (imageMetadata->get("device.status", deviceStatus) == 0) + status.analogueGain = deviceStatus.analogueGain; + else + LOG(RPiExampleStage, Warning) << "No device metadata"; + + /* Per-frame stage parameters. */ + imageMetadata->set("example_stage.status", status); +} + +static Algorithm *create(Controller *controller) +{ + return (Algorithm *)new ExampleStage(controller); +} +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/rpi/controller/rpi/example_stage.h b/src/ipa/rpi/controller/rpi/example_stage.h new file mode 100644 index 00000000..b446b62a --- /dev/null +++ b/src/ipa/rpi/controller/rpi/example_stage.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2026, Raspberry Pi Ltd + * + * Example pipeline stage algorithm + */ +#pragma once + +#include "../algorithm.h" +#include "../example_stage_status.h" + +/* + * This algorithm drives the example pipeline handler stage. It does nothing + * useful, but shows how to plumb in a new pipeline handler stage. + */ + +namespace RPiController { + +class ExampleStage : public Algorithm +{ +public: + ExampleStage(Controller *controller); + char const *name() const override; + int read(const libcamera::ValueNode ¶ms) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + +private: + ExampleStageTuning tuning_; + uint32_t frame_; +}; + +} /* namespace RPiController */ diff --git a/src/libcamera/pipeline/rpi/common/meson.build b/src/libcamera/pipeline/rpi/common/meson.build index 5411ae84..d3281a49 100644 --- a/src/libcamera/pipeline/rpi/common/meson.build +++ b/src/libcamera/pipeline/rpi/common/meson.build @@ -5,4 +5,5 @@ libcamera_internal_sources += files([ 'pipeline_base.cpp', 'rpi_stream.cpp', 'stage_runner.cpp', + 'stages/example_stage.cpp', ]) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 408a4b58..f744b329 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -31,6 +31,8 @@ #include #include +#include "stages/example_stage.h" + #include "delayed_controls.h" #include "rpi_stream.h" #include "stage.h" @@ -55,10 +57,8 @@ public: { stageRunner_.stagesComplete.connect(this, &CameraData::stagesComplete); - /* - * Stages that can run on every platform would be added here: - * e.g. addStage(std::make_unique()); - */ + /* Stages that can run on every platform are added here. */ + addStage(std::make_unique()); } virtual ~CameraData() diff --git a/src/libcamera/pipeline/rpi/common/stages/example_stage.cpp b/src/libcamera/pipeline/rpi/common/stages/example_stage.cpp new file mode 100644 index 00000000..330e9c7c --- /dev/null +++ b/src/libcamera/pipeline/rpi/common/stages/example_stage.cpp @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Raspberry Pi Ltd + * + * Example pipeline handler stage + * + * Add + * { + * "rpi.example_stage": + * { + * } + * } + * to the tuning file algorithms to run this stage. + */ + +#include "example_stage.h" + +#include +#include + +#include + +#include "libcamera/internal/dma_buf_allocator.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(RPiExampleStage) + +namespace RPi { + +int ExampleStage::configure(const ipa::RPi::StageConfig &config, const StageFormat &format) +{ + config_ = config.example; + + if (!config_.enabled) + return 0; + + LOG(RPiExampleStage, Info) + << "Configured: delay " << config_.delayMs << "ms, raw format " + << format.pixelFormat << " " << format.size << " stride " << format.stride; + + return 1; +} + +void ExampleStage::run(StageJob &job) +{ + const ipa::RPi::ExampleStageParams ¶ms = job.params.example; + + /* Print out the first Bayer quad as 16-bit values, regardless of the format. */ + DmaSyncer sync(job.bayerFd, DmaSyncer::SyncType::Read); + + const uint8_t *data = job.bayerData.data(); /* assume large enough! */ + const uint16_t *row0 = reinterpret_cast(data); + const uint16_t *row1 = reinterpret_cast(data + job.bayerFormat.stride); + + LOG(RPiExampleStage, Info) + << "Frame " << params.frame << ", analogue gain " << params.analogueGain + << ", first quad " << row0[0] << " " << row0[1] << " " + << row1[0] << " " << row1[1]; + + std::this_thread::sleep_for(std::chrono::milliseconds(config_.delayMs)); +} + +} /* namespace RPi */ + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/common/stages/example_stage.h b/src/libcamera/pipeline/rpi/common/stages/example_stage.h new file mode 100644 index 00000000..d5b55bc5 --- /dev/null +++ b/src/libcamera/pipeline/rpi/common/stages/example_stage.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Raspberry Pi Ltd + * + * Example pipeline handler stage + */ + +#pragma once + +#include "../stage.h" + +namespace libcamera { + +namespace RPi { + +/* + * An example stage that does nothing useful. For every frame it logs the + * parameters it was given and the first few raw pixel values, and can add a + * delay, just to mix up the timings. + */ +class ExampleStage : public Stage +{ +public: + const char *name() const override { return "example"; } + + int configure(const ipa::RPi::StageConfig &config, const StageFormat &format) override; + void run(StageJob &job) override; + +private: + ipa::RPi::ExampleStageConfig config_; +}; + +} /* namespace RPi */ + +} /* namespace libcamera */