From patchwork Wed Dec 2 16:13:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 29150 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 EE46EC3304 for ; Thu, 3 Dec 2026 13:01:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 783706AB3A; Thu, 3 Dec 2026 14:01:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lXFs9Rzk"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9F6C06AB30 for ; Thu, 3 Dec 2026 14:01:17 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-4a34ffd3e39so7890087f8f.0 for ; Thu, 03 Dec 2026 05:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1796302877; x=1796907677; 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=86rqBrvNKm9b5n+TzYazoH1VWUGT/Bec9+hmYS/sBAo=; b=lXFs9Rzksduqi8rDFIlkL306XYrRZ6KSOGmzC8Skc326YkV2mEynvpZ1axpijJcBtd dQ1qZA45FXtwqIlDABJfu+eeqGbRAEyfZ/HWAGiX0lSXvmnostWO2RYikbEziKNkhZPS Zy0PZMTzjiGILQ9Uv/Ye5azgk/ZepRiWtx6pGj0H1khyxRLnBrSeu/BzOxQugtrdRCv4 8On716DvrSar3dcWLyhxDxjj1rXnSz7kMp6hkIOAS30Si9zbiFd1yyHUyhoadYoiwtFp w/fjfllJMJ18yeKETxR+BWTd0nDd1P5sNl5Nm1zYwHL8rrx5gcM0kPdJ2Bt3U1+5wLlh c0rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796302877; x=1796907677; 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=86rqBrvNKm9b5n+TzYazoH1VWUGT/Bec9+hmYS/sBAo=; b=OOXwFAYamHbJ4PwEBmCCbMoI7VAQqCAxNOt3tiwkRspap/aBOEiUjM0oyjXkk3d0j9 2fy4rgg1pwAXcIvGWHEntEvSLkm0Dh4sFDIqNg/cpaZ6mou/RSXZ4K6vmRe41QXJH2mb qzgrb951HqkFvXjHDIY8epZvCvXziWlfuo4qiUErdXAkvQx+q14KVBPgrxmh5nv2ksGP uhMRhtQeZKz6pVrRXVPeR98LijyaiK/cO8eKvaS389S08x/Qu6Z6t8K/41nmzAg5+SYl UONZVrZ97rHlbh8NNaWKk0c30Rds9djGtBaWZjjpiJQu8jzLEhwXT3BiQPsd+rmEOT2h RzEg== X-Gm-Message-State: APuU4Z9CZosK/CczjqaHEIerGVsFD98QnwZ+NJhxg4qrvo9DFaiyRYQ6 Nm0Ne7L2uaxN3Y86T8Zg9Umkfht6VSSzv/PFUFVu+0qDurDglCbgPg4HlGdm7s8qJl71kDTFt7Z Z4TujTxQ= X-Gm-Gg: AZFdTZdItLbc00B+sYgUCxdmJh6TbqOuxzOZuFq+wx9spuaVGapqf5ApwGse1samzvu 21qYdwD+4ef3+49gnTlEYx3244D/TRKJUacW0HjNMDpNAUkfHX/9WuCqRTvXaDNWFsVRvW0z6Pz Gi3OhZbIi+7dXgpMBZWxlPbKkT2SPNDAqs7oECXqHWV/VXJbY2xN4sOC+aroUfM28R7P3AC73Zi Y6MTuwqieXeWfPLqzvJNi3MAzRcfc7Trvi3vHib8NG2jE7wC5YdGYoVXEUtFquZ69YA3JWzAGEq XYLqBLnUkVwqeVZmR4ZZwG1FkAceK3Nm6q/fetcLyhXZ3E27G1BDBLpaWrjeA2mvPrD5/O/GoQX kUOD5A3ed/u8wc8810Bkh1z0vg4LpYYHWa68d/8Fzi1dYM0nIVR4NASqdzrAOrpNnYWacpDN1qh yf+EozFU5tyMOWjvIkX8K78hCf9wUkQttguG6j6zTUGstb56O71xbwOoJWeYPEn2vSapw4K8YQj mw7dxC2W01f0Ur1XC1uD3p+8eDuJpvOdbRpe0wE/gHQ2IwQNamIuB6MHqhsqSO7peeadVARCsIX ceejU1IesBYIYc4ws+fX2RavUzzTJ5tTJPOPAaPtYp+JDZiRdeQBGY2PQr43+WRkNNVuW5eubVN aJziJCsRyK2zGe+PqSpAF6umuIjkcMjixB8TAdmAFsHpivNZq6g== X-Received: by 2002:a05:600c:5303:b0:4a2:fe11:9a8a with SMTP id 5b1f17b1804b1-4bb88786cfamr836683595e9.0.1796302876970; Thu, 03 Dec 2026 05:01:16 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:01:16 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH v1 1/5] pipeline: rpi: vc4: Memory map the Unicam image buffers Date: Wed, 2 Dec 2026 16:13:23 +0000 Message-ID: <20261203130113.47873-2-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 Mmap the raw Bayer buffers on the VC4 platform, as we are already doing on PiSP devices. This means we can add common code in future to inspect or process those pixel values, without worrying about the platform. Signed-off-by: David Plowman --- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 200e3b58..8b8eb166 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -325,7 +325,8 @@ int PipelineHandlerVc4::platformRegister(std::unique_ptr &camer return -ENOENT; /* Locate and open the unicam video streams. */ - data->unicam_[Unicam::Image] = RPi::Stream("Unicam Image", unicamImage); + data->unicam_[Unicam::Image] = RPi::Stream("Unicam Image", unicamImage, + StreamFlag::RequiresMmap); /* An embedded data node will not be present if the sensor does not support it. */ MediaEntity *unicamEmbedded = unicam->getEntityByName("unicam-embedded"); From patchwork Wed Dec 2 16:13:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 29151 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 8F5FFC3355 for ; Thu, 3 Dec 2026 13:01:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C2E56AB41; Thu, 3 Dec 2026 14:01:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="rsghiXiz"; 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 0BFC96AB33 for ; Thu, 3 Dec 2026 14:01:18 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4a2153c8525so113387685e9.3 for ; Thu, 03 Dec 2026 05:01:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1796302877; x=1796907677; 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=3wQX6+SKohOfCBWWl/8e2O4QIN2hq05aJh/Gri5+oek=; b=rsghiXizVNhCscl5R1adkYkMD1HVAXcT7C9dRZoLzdfs1s+FWZWJIvdXNKwZT8sq+Y yIcfgownuY479ZFAEABeXjJa1xRv5l73uOXsnZgyI6Ua6fHzhWXutCiME6iT7FTFvcPp SokLgLtz90AAZN9KT+OPzWRqOGn8TZmsu6neFZIzMCRiekTs59OwDNwnbbHV4Myjtkn5 XpZYHC/lIWMn9YcPUzgkPmqyycqatJM22YPgu/82zJ92w3Ea6CIprUB6ZZGKstpx/aoa vKHjSZRpnayaiNgG+fSVdFEfp7+DC3g4w6RQ1FAreGEu+0OU6TlonueBJXV3BlrWMuNT gQRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796302877; x=1796907677; 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=3wQX6+SKohOfCBWWl/8e2O4QIN2hq05aJh/Gri5+oek=; b=wxKFyIleyaVJ3DhnMz0fw8jh5jgOxBmG60ETGLal5bLKqcEfEtXB4TuFN3ZFtSTwL7 7NUZ0F5qK96eVeAEmD+MGQ/uCnudtGp2MAoFOs4vgnP4sDsh5uSJC6ccl6qcvgY7cUMJ 40F4hjY4hMG1T/R1+vBZpckCQoZxkeVXaDj3DbeB+aZdVHXhQkVlo35uzhPhsCuycUAV rLi0VvKqr47ORLFE2ChPe6MmXM4Zt3ZLmUM8spJL4K0DndqG0W4pYz6bbtKOHbdVNp9H pw/1AhzNIvAXeNmECNRfPa1Z+QLxkzKEtYWzrG1uflYtz2W+qsyCqqDZLiKi0H6Vqhcx TC+w== X-Gm-Message-State: APuU4Z8kRr4ujXbyXGMYnOFo3nyQHFo2/wtmvkrwGMHg6ci42btTcA7J qBUjzKKX6olD3gY4wkSprju3xrhaTUqUbUOaTULBOJSeijL2RzY3ks53Ovu5Fm+aiBsX3E2COup hcBiyiGU= X-Gm-Gg: AZFdTZf5eDHOMl2F0aHw4ZlbXFeu0aDaB+0VOlgatbjFZpp8RRXqXE7q6S5NV0TS6Ov pcJZVeDYmRZRtH+xjhvQ/OEpT7KQpafugnS69+NwMjDv3kegQAoXeC/bzHB5r5bnDobUhIsv3lf Z2KgyqRwPyLdCp5K0xlI4uMrnlh6Thowr/qnB5gTI999ggcvg9+sQ8M4UrNbaiOXmvpWOGeouCl XM/1FJDPcTch/43U2IU37xFFNksNcNepw/oyadyCWopMJhTFDKQcQkAWwvwNXOmkQZhjxdtIeyy 5JN9tvf7wutLlU02hottRe+osEBG8bIUpXD7qnCMvIV51TpJdRbYWc5utLPcZVJbS7oyx6K3Rjv PZDzQQiwifZh44/odEtyZHo0qwJuiNh/KCWU4Xu5v8+Is7FUsVjVR+HwOtKduBEb+lLaQiHW4OJ GEmJ7A3LSwNQ3Q1GzBCEJGDsL9LOJxqMksfo65ImS5xH0EDIJcB+EeUt1D0BiymTgOXVj5dDieb 4s6lgdCArxjXKeb6wKBiYT9uYgaeDuEDZWqH8efWttEHfhrCttxbU+r1QroJQ4Rd7JP2BPVeoAd KzbmF1SSSOoePbdbMYA8t/WUJLNaWYDyXbrc/zyFeSnqzK/dFf1S2N63nzimXm8B+qjf0KiKbzI TQ9q01jJisjwLihdo4PbjpC8KZ8abAcgsVyjsm+PtV0PnwZgjnA== X-Received: by 2002:a05:600c:c84:b0:4a8:9a2f:d27 with SMTP id 5b1f17b1804b1-4bb8881f47emr887060485e9.25.1796302877412; Thu, 03 Dec 2026 05:01:17 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:01:17 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH v1 2/5] ipa: rpi: Pass raw buffer format to the IPA Date: Wed, 2 Dec 2026 16:13:24 +0000 Message-ID: <20261203130113.47873-3-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 IPAs may in general need to behave differently based on the raw pixel format, so we should make this information available. This may be particularly important for the new pipeline "stages", where the IPA side may need to do different things based on what it knows its associated stage may do. Signed-off-by: David Plowman --- include/libcamera/ipa/raspberrypi.mojom | 2 ++ src/ipa/rpi/common/ipa_base.cpp | 1 + src/ipa/rpi/controller/camera_mode.h | 3 +++ .../pipeline/rpi/common/pipeline_base.cpp | 14 ++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index 1b7e0358..ed048526 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -37,6 +37,8 @@ struct BufferIds { struct ConfigParams { uint32 transform; + uint32 rawFormat; /* raw buffer PixelFormat fourcc, or zero if unknown */ + uint64 rawFormatModifier; /* raw buffer PixelFormat modifier */ libcamera.ControlInfoMap sensorControls; libcamera.ControlInfoMap ispControls; libcamera.ControlInfoMap lensControls; diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index c2848344..2ed80d3e 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -215,6 +215,7 @@ int32_t IpaBase::configure(const IPACameraSensorInfo &sensorInfo, const ConfigPa setMode(sensorInfo); mode_.transform = static_cast(params.transform); + mode_.rawFormat = PixelFormat(params.rawFormat, params.rawFormatModifier); /* Pass the camera mode to the CamHelper to setup algorithms. */ helper_->setCameraMode(mode_); diff --git a/src/ipa/rpi/controller/camera_mode.h b/src/ipa/rpi/controller/camera_mode.h index 61162b32..400e5938 100644 --- a/src/ipa/rpi/controller/camera_mode.h +++ b/src/ipa/rpi/controller/camera_mode.h @@ -6,6 +6,7 @@ */ #pragma once +#include #include #include @@ -43,6 +44,8 @@ struct CameraMode { libcamera::utils::Duration maxFrameDuration; /* any camera transform *not* reflected already in the camera tuning */ libcamera::Transform transform; + /* PixelFormat of the raw buffers */ + libcamera::PixelFormat rawFormat; /* minimum and maximum frame lengths in units of lines */ uint32_t minFrameLength; uint32_t maxFrameLength; diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index d6ce2dbf..6944d5c4 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -1236,6 +1236,20 @@ int CameraData::configureIPA(const CameraConfiguration *config, ipa::RPi::Config Transform transform = config->orientation / Orientation::Rotate0; params.transform = static_cast(transform); + /* + * Send the format of the raw Bayer buffers, which should match what's + * set on the frontend device, whether buffers are internal or not. + */ + V4L2DeviceFormat frontendFormat; + ret = frontendDevice()->getFormat(&frontendFormat); + if (ret) { + LOG(RPI, Error) << "Failed to get the frontend format"; + return ret; + } + const PixelFormat rawFormat = frontendFormat.fourcc.toPixelFormat(); + params.rawFormat = rawFormat.fourcc(); + params.rawFormatModifier = rawFormat.modifier(); + /* Ready the IPA - it must know about the sensor resolution. */ ret = ipa_->configure(sensorInfo_, params, result); if (ret < 0) { From patchwork Wed Dec 2 16:13:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 29152 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 5F2A8C3304 for ; Thu, 3 Dec 2026 13:01:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0257A6AB3D; Thu, 3 Dec 2026 14:01:22 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="djRATo6J"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E3A056AB32 for ; Thu, 3 Dec 2026 14:01:18 +0100 (CET) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4bbd2c5931bso23944965e9.2 for ; Thu, 03 Dec 2026 05:01:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1796302878; x=1796907678; 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=tf0sjbuXggJQ6MhZp0aCZPPG3eNNYUFFT5zYH3bjAXw=; b=djRATo6JFHhOgOZKzjQEIKS/E3m7EHXpspJAsdimhfiIjUtAAEb3h+u91h1hmWe+1Z B+wqBc1bx+2mKoWzYeCTmE/B7FUKqJTC4K5YjDsdBbX8NtSM13lf7sSucjYx1gCMZAv6 IDox9FBcGPZUwKHtnjIDBrEueVpxqki3pezIi53eNdlJWPyX3Y3UGskueIkp3Ox59geq WyR9ny0MWYycYP0NKWorUth3BA+M6gdGTSeVAUSLiVzd/zLaRjsiliv4vSOq/q1QaxL0 YH7CI7706Z9AXv1Kez+Wzk6aJMMTVGaDdbH68VS65uuqTCnklKGcr6Kw8lQf0EPWzxLw 82rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796302878; x=1796907678; 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=tf0sjbuXggJQ6MhZp0aCZPPG3eNNYUFFT5zYH3bjAXw=; b=ZszFQ10J+OSi0pUDMCDknZXct6T0Rlmx2bu/k1CZQDExaxj9sUiypo9WN1i12ctxEs /V8my9WXj/5pSoyO3tf2lQNEi6CFYgQlCiFVRuOsoH24eKn9AhDx2vjt8bnOU9knpSri xYsgMeNXaRAd8uPs09SR1vUQN+ogrPExjLACn7vEV4qWOb1YtjtW2Q+MQA3d6TEm9vBV zLr15v9G6UMz0OHUyZgvdVG/0F+3/JkBwsu386KDin7ucbTvAKegGywUM1WU5OZduTEY ukyE81CCxc+2EVGjXDjU0I1Twi0Q8vMfhOUdxzp67y20n+KvnHF2M/cSj06sHkvQwhKD SwLQ== X-Gm-Message-State: APuU4Z8ohIXcDr51NWp5kZZJr1ZTLdy3oIDVtGpuIK0JjA6tCvOSHeap ry0xOsuQ/9ng16CUgO8uGrmCW0QE6mYSW6W74KAE38QsevOj4bV74i26pcVTYfhknG+79PxDl3B 4d9YBz2M= X-Gm-Gg: AZFdTZe2xPRjPj9cw9YJCE/FptUJBA6a++vMXyt4k0PpsEgNUcpi1h1PrpIK80Nljx4 6rUlMSxT/h+ShWvbCH0JgVFMYqIwMmk77c5egzJG61XKJyhDurZo5dunMDvDZpgU3+p5Fst7e/0 0xQ4Ph3V19znSv4Gc9KZuK4g1jVMnE07DYupIPcQBenCIAJZozkM5L09b17j3aLBDgYDe7YFPbF OTJ4hHU2cdBucgDZ+J9YQnhZoHHSJp2xXXuZp7+G/8cOSu+yqZLJhTSQ08Nb8vhNOIv/ef6DvgA t3H7W3ADneC29LDol7IjW9N7VVku8DvHHhpMrBR6Y5cgkEGt0XgwbnjcEiiO0TUSJ3IiLCzn3qw 1SEKfOto3YOVEiMwQlSqfJozwiB4OPhLAHJr05APUdc6xpCxz0tml0AljXYb24wJsJoznnrQgpc NECgAvunHrDYX2+QCBflkzmYcsp4ylnn9w1xbwWzM+aVtHSUt8y5F76D0Wo6zbEY7uFMOZy7K3O 0pbiF5cCY96Q1LxqwcN9/l6qozfSPtHyczKUhuPC4FW7LgBsnuWz1HujFjkwUgQGjjZPs3kWF3L zwap7ushRoh9Lt5Uk3HDLy3kiY6rTSLIaMKCOFA+FJESuQtASGOZkoE2pCFxbOk0WLSBLk9Cghl cBQTWDhpi8h2GgaqJFtkZkM7znSBXiKFn6lk9Bv6LONMOEooI3g== X-Received: by 2002:a05:600c:a085:b0:4bb:7bee:5496 with SMTP id 5b1f17b1804b1-4bb8880f04dmr898335965e9.13.1796302878108; Thu, 03 Dec 2026 05:01:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:01:17 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH v1 3/5] ipa: rpi: Add StageConfig and StageParams to the IPA interface Date: Wed, 2 Dec 2026 16:13:25 +0000 Message-ID: <20261203130113.47873-4-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 The newly proposed pipeline processing "stages" will still be configured and controlled through the existing IPA mechanism. StageConfig is returned by configureIPA to configure stages, and StageParams is returned by every prepareISP call with specific parameters for that frame. We include the boilerplate code for filling the config and params structures to be returned, and update the IPA event callback on the pipeline handler side for the new structures. As we have no real stages currently, the structures have placeholder fields. Signed-off-by: David Plowman --- include/libcamera/ipa/raspberrypi.mojom | 30 +++++++++++++++++---- src/ipa/rpi/common/ipa_base.cpp | 33 ++++++++++++++++++++++-- src/ipa/rpi/common/ipa_base.h | 6 +++++ src/libcamera/pipeline/rpi/pisp/pisp.cpp | 6 +++-- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 6 +++-- 5 files changed, 70 insertions(+), 11 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index ed048526..eaeb8398 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -46,11 +46,28 @@ struct ConfigParams { libcamera.SharedFD lsTableHandle; }; +/* + * 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. + */ +struct StageConfig { + /* Placeholder - remove once we have a stage. */ + bool unused; +}; + +/* Per-frame parameters for the pipeline handler stages, one structure per stage. */ +struct StageParams { + /* Placeholder - remove once we have a stage. */ + bool unused; +}; + struct ConfigResult { float modeSensitivity; libcamera.ControlInfoMap controlInfo; libcamera.ControlList sensorControls; libcamera.ControlList lensControls; + StageConfig stageConfig; }; struct StartResult { @@ -136,8 +153,9 @@ interface IPARPiInterface { * parameters, e.g. the lens shading table memory handle for VC4. * * The \a result parameter returns the available controls for the given - * camera mode, a list of controls to apply to the sensor device, and - * the requested mode's sensitivity characteristics. + * camera mode, a list of controls to apply to the sensor device, the + * requested mode's sensitivity characteristics, and the configuration + * of the pipeline handler extra processing "stages". */ configure(libcamera.IPACameraSensorInfo sensorInfo, ConfigParams params) => (int32 ret, ConfigResult result); @@ -223,13 +241,15 @@ interface IPARPiEventInterface { * \brief Signal completion of \a prepareIsp * \param[in] buffers Bayer and embedded buffers actioned. * \param[in] stitchSwapBuffers Whether the stitch block buffers need to be swapped. + * \param[in] stageParams Parameters for the pipeline handler stages for this frame. * * This asynchronous event is signalled to the pipeline handler once * the \a prepareIsp signal has completed, and the ISP is ready to start - * processing the frame. The embedded data buffer may be recycled after - * this event. + * processing the frame. Any pipeline handler stages are run, with the + * \a stageParams, before the ISP. The embedded data buffer may be recycled + * after this event. */ - prepareIspComplete(BufferIds buffers, bool stitchSwapBuffers); + prepareIspComplete(BufferIds buffers, bool stitchSwapBuffers, StageParams stageParams); /** * \fn processStatsComplete() diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index 2ed80d3e..7726a768 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -229,6 +229,9 @@ int32_t IpaBase::configure(const IPACameraSensorInfo &sensorInfo, const ConfigPa /* The pipeline handler passes out the mode's sensitivity. */ result->modeSensitivity = mode_.sensitivity; + /* Tell the pipeline handler which stages to run, and their configurations. */ + fillStageConfig(result->stageConfig); + if (firstStart_) { /* Supply initial values for frame durations. */ applyFrameDurations(defaultMinFrameDuration, defaultMaxFrameDuration); @@ -300,6 +303,9 @@ void IpaBase::start(const ControlList &controls, StartResult *result) controller_.switchMode(mode_, &metadata); + /* Extra pipeline "stages" won't want parameters from a before a mode switch. */ + lastStageParams_ = {}; + /* Reset the frame lengths queue state. */ lastTimeout_ = 0s; frameLengths_.clear(); @@ -504,8 +510,11 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms) /* Actually prepare the ISP parameters for the frame. */ platformPrepareIsp(params, rpiMetadata); platformPrepareAgc(rpiMetadata); - } else + prepareStageParams(rpiMetadata); + } else { platformPrepareAgc(rpiMetadata); + repeatStageParams(); + } frameCount_++; @@ -514,7 +523,27 @@ void IpaBase::prepareIsp(const PrepareParams ¶ms) reportMetadata(ipaContext); /* Ready to push the input buffer into the ISP. */ - prepareIspComplete.emit(params.buffers, stitchSwapBuffers_); + prepareIspComplete.emit(params.buffers, stitchSwapBuffers_, lastStageParams_); +} + +/* Fill in the configuration for the pipeline handler stages. */ +void IpaBase::fillStageConfig(StageConfig &config) +{ + config = {}; +} + +/* Fill in the parameters for the pipeline handler stages for this frame. */ +void IpaBase::prepareStageParams([[maybe_unused]] const RPiController::Metadata &rpiMetadata) +{ + lastStageParams_ = {}; +} + +/* + * If prepare() was skipped for this frame, send the same stage params again, + * but this method allows for the possibility that some fields may need changing. + */ +void IpaBase::repeatStageParams() +{ } void IpaBase::processStats(const ProcessParams ¶ms) diff --git a/src/ipa/rpi/common/ipa_base.h b/src/ipa/rpi/common/ipa_base.h index 0d7842f1..b9a87cfb 100644 --- a/src/ipa/rpi/common/ipa_base.h +++ b/src/ipa/rpi/common/ipa_base.h @@ -100,6 +100,9 @@ private: virtual void handleControls(const ControlList &controls) = 0; void fillDeviceStatus(const ControlList &sensorControls, unsigned int ipaContext); void reportMetadata(unsigned int ipaContext); + void fillStageConfig(StageConfig &config); + void prepareStageParams(const RPiController::Metadata &rpiMetadata); + void repeatStageParams(); void applyFrameDurations(utils::Duration minFrameDuration, utils::Duration maxFrameDuration); void applyAGC(struct AgcStatus *agcStatus, ControlList &ctrls); @@ -144,6 +147,9 @@ private: bool awbEnabled_; utils::Duration controllerMinFrameDuration_; + + /* If prepare() doesn't run, send the last pipeline "stage" parameters again. */ + StageParams lastStageParams_; }; } /* namespace ipa::RPi */ diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp index 159c6b05..40ad91c2 100644 --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp @@ -759,7 +759,8 @@ public: void beOutputDequeue(FrameBuffer *buffer); void processStatsComplete(const ipa::RPi::BufferIds &buffers); - void prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers); + void prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers, + const ipa::RPi::StageParams &stageParams); void setCameraTimeout(uint32_t maxFrameLengthMs); /* Array of CFE and ISP device streams and associated buffers/streams. */ @@ -1885,7 +1886,8 @@ void PiSPCameraData::setCameraTimeout(uint32_t maxFrameLengthMs) cfe_[Cfe::Output0].dev()->setDequeueTimeout(timeout); } -void PiSPCameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers) +void PiSPCameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers, + [[maybe_unused]] const ipa::RPi::StageParams &stageParams) { unsigned int embeddedId = buffers.embedded & RPi::MaskID; unsigned int bayerId = buffers.bayer & RPi::MaskID; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 8b8eb166..4bcaae54 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -79,7 +79,8 @@ public: void ispOutputDequeue(FrameBuffer *buffer); void processStatsComplete(const ipa::RPi::BufferIds &buffers); - void prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers); + void prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers, + const ipa::RPi::StageParams &stageParams); void setIspControls(const ControlList &controls); void setCameraTimeout(uint32_t maxFrameLengthMs); @@ -864,7 +865,8 @@ void Vc4CameraData::processStatsComplete(const ipa::RPi::BufferIds &buffers) } void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, - [[maybe_unused]] bool stitchSwapBuffers) + [[maybe_unused]] bool stitchSwapBuffers, + [[maybe_unused]] const ipa::RPi::StageParams &stageParams) { unsigned int embeddedId = buffers.embedded & RPi::MaskID; unsigned int bayer = buffers.bayer & RPi::MaskID; From patchwork Wed Dec 2 16:13:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 29153 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 40A77C3361 for ; Thu, 3 Dec 2026 13:01:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B62846AB4D; Thu, 3 Dec 2026 14:01:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="O2Cs+bTY"; 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 80AB66AB3F for ; Thu, 3 Dec 2026 14:01:19 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4bb85e07aadso172667165e9.1 for ; Thu, 03 Dec 2026 05:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1796302879; x=1796907679; 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=pcGaAXUwDRRs8547/WG9SGJvLxc1ZhSt1tXSILvvO0c=; b=O2Cs+bTYYmE7tM6EgE5/StPEMzYGy2BhKVh93vwu2tTET8FTPJm0o6PaHAJSxUvupn 0SPH0f0n+8AgwMU9X//yGyrE5CKnmJmBey7YriugXhHCifSpX904q/m0rnByAwjGuLIY ApfnW2mrzgx3wXHfIhjFufl213rkYKoXBwZ6v9xi5Zc/6VHPoAg5RYMSdv4NFraiTVdn mvaxSkb/aogrJNQEOoA0Zi4xj8n0dUzBJVVKhHROFndOaAV+0/n2u3D+67KqUus461yP kI7ELp1Kfo7221RTt5jvOHnly55UCqIHGJTJE2m4FujdVbFLcpy3YZAKc/jNSYJOtdfu G50w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796302879; x=1796907679; 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=pcGaAXUwDRRs8547/WG9SGJvLxc1ZhSt1tXSILvvO0c=; b=Dv9agKUDgLToigG5Kx0RKbHXRk5lZUYqS5WiIe+1N8YA22f51j01lrDaMotf8X3498 jST4MuzIjJ/POrjkifJn1bHeurYfqCxqhqyZJCn2T/ErmlmfhTFAzytKGHEQAGpWnAFr gKHP7KdkDqttIWuyLyFamp0KzkHqsWLr/XWZfBVwq++p9urZ8ergi3woIHoHc2k97FHR gfpzuKcI6Mdq2uF3gs5sf48J3lmb0b4g8PxXI9k2g5Aovn4tnvEoGP9apQnaBmj2C2T+ hnFIP86L+WlkpSpelK3/YivmqZTl9Ie4xQOKOpUp7u7/Q/LqZxvqoljylY/kRX+qBUCd UlcA== X-Gm-Message-State: APuU4Z+Qmf8HiLtaZpDZtlmEnm/576076l8zwUcapMrneClU5wRPyBOe Wto+h6m27YexKOQlEwv+Cw5yGvHxf9rOlWYgHRuKfw9VuqQ/YnB4cr9TENgKDFV4OwHEQ9sH/yn x3z+JcqA= X-Gm-Gg: AZFdTZe9SLKHgSGakpaAYGexlOSxmPYwyh3IxN5FXnYSMUKrUz0uFQakdWfQUfXxhMN oC3j5wvf0SZhCUJElMikxeXEqjsaVna/mNtYRwL4d8bx0zA10svfi/6UZBffDZZCHGJhOk0GKrL 1CekI9regQeefk9rc1IWVnKkTbUeVrXlyoVROAej1n5gQlrFQAdwmz7Vd2nZ0CfgKrDGUry5RoD kV6FBwiZ3OXdHdeGWEEarQJ2y8tAk76mtg7BeLfX+iPD3FrMW8fLUdsmrSCV3YNVNucXF9Liz2c cJNH+E9BmJu+uzvookm9ULF6Er4ZJUQPE4f44zDWYJQmjzk+Rt0VoyAF1ue5Oa1g6FU5KqL6xmB 2OoR30z9W0hfCvC4t3dfXsdZsOJ3GGNMdSt4BFxd/FnxrUeYatgiHPvJG6YgsVh37cIcq64SvHY 90kuoZ+ihrGNuw6VESNjagtAElcu3vkmWyT7XHiZ+whBCki0JZXAkUhHQLBX9oTeh5vxaEqFdmA M2agzM8MDrlrcrIsdU4Ryibf+s/8Ouy+pcIWE+KfwplKIH7ekRN8ye/ad88tNt1SBYGLyQq/Pde zeHJ/lpLv3d+rqeGHRgfAlwhBy3bd2IsQ1EAxiGEW/ybchZ17rFzwVmGQO8LcRNSMugDw2Yvigx 5cAeJh91KX0ZB+2+UnHUI5FDhQh7JjvpIp6idxPmC7NQphSy/jw== X-Received: by 2002:a05:600c:5303:b0:4a2:1655:87db with SMTP id 5b1f17b1804b1-4bb88785d2fmr828797895e9.0.1796302878639; Thu, 03 Dec 2026 05:01:18 -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 4/5] pipeline: rpi: Add infrastructure for additional pipeline "stages" Date: Wed, 2 Dec 2026 16:13:26 +0000 Message-ID: <20261203130113.47873-5-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 A pipeline stage operates on a raw Bayer buffer after the IPA's prepareIsp and before the main ISP runs. Stages are configured and controlled like other IPAs, but those parameters are passed back to the pipeline handler to create the requested stages, and to run them in a per-camera worker thread. Most of this commit defines the Stage base class and the StageRunner that executes them, trying to follow the pattern of the Software ISP. But we also include the PiSP/vc4 code that allows the pipeline handler to stay in the "busy" state while those stages are running, moving on only when the runner signals completion. Signed-off-by: David Plowman --- src/libcamera/pipeline/rpi/common/meson.build | 1 + .../pipeline/rpi/common/pipeline_base.cpp | 83 ++++++++++ .../pipeline/rpi/common/pipeline_base.h | 36 +++++ src/libcamera/pipeline/rpi/common/stage.h | 75 +++++++++ .../pipeline/rpi/common/stage_runner.cpp | 149 ++++++++++++++++++ .../pipeline/rpi/common/stage_runner.h | 74 +++++++++ src/libcamera/pipeline/rpi/pisp/pisp.cpp | 37 ++++- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 34 +++- 8 files changed, 482 insertions(+), 7 deletions(-) create mode 100644 src/libcamera/pipeline/rpi/common/stage.h create mode 100644 src/libcamera/pipeline/rpi/common/stage_runner.cpp create mode 100644 src/libcamera/pipeline/rpi/common/stage_runner.h diff --git a/src/libcamera/pipeline/rpi/common/meson.build b/src/libcamera/pipeline/rpi/common/meson.build index b2b1a0a6..5411ae84 100644 --- a/src/libcamera/pipeline/rpi/common/meson.build +++ b/src/libcamera/pipeline/rpi/common/meson.build @@ -4,4 +4,5 @@ libcamera_internal_sources += files([ 'delayed_controls.cpp', 'pipeline_base.cpp', 'rpi_stream.cpp', + 'stage_runner.cpp', ]) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 6944d5c4..2c324035 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -559,6 +559,12 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) return ret; } + ret = data->configureStages(result.stageConfig); + if (ret) { + LOG(RPI, Error) << "Failed to configure the pipeline stages: " << ret; + return ret; + } + /* * Update the ScalerCropMaximum to the correct value for this camera mode. * For us, it's the same as the "analogue crop". @@ -700,6 +706,8 @@ int PipelineHandlerBase::start(Camera *camera, const ControlList *controls) /* A good moment to add an initial clock sample. */ data->wallClockRecovery_.addSample(); + data->startStages(); + /* * Reset the delayed controls with the gain and exposure values set by * the IPA. @@ -729,6 +737,10 @@ void PipelineHandlerBase::stopDevice(Camera *camera) CameraData *data = cameraData(camera); data->state_ = CameraData::State::Stopped; + + /* Wait for any stages to finish. Any pending completions will be discarded. */ + data->stopStages(); + data->platformStop(); for (const auto stream : data->streams_) { @@ -1265,6 +1277,77 @@ int CameraData::configureIPA(const CameraConfiguration *config, ipa::RPi::Config return 0; } +/* + * Configure all the pipeline stages enabled in the stage configuration from + * the IPA, and make a list of them for the worker to run. + */ +int CameraData::configureStages(const ipa::RPi::StageConfig &config) +{ + V4L2DeviceFormat format; + int ret = frontendDevice()->getFormat(&format); + if (ret) { + LOG(RPI, Error) << "Failed to get the frontend format"; + return ret; + } + + stageFormat_.pixelFormat = format.fourcc.toPixelFormat(); + stageFormat_.size = format.size; + stageFormat_.stride = format.planes[0].bpl; + + ret = stageRunner_.configure(config, stageFormat_); + if (ret) + return ret; + + if (stagesActive()) + LOG(RPI, Debug) << "Pipeline stages active, raw format " + << stageFormat_.pixelFormat << " " << stageFormat_.size + << " stride " << stageFormat_.stride; + + return 0; +} + +bool CameraData::stagesActive() const +{ + return stageRunner_.hasActiveStages(); +} + +void CameraData::startStages() +{ + if (stagesActive()) + stageRunner_.start(); +} + +/* Wait for the stages to finish and stop them. */ +void CameraData::stopStages() +{ + stageRunner_.stop(); +} + +/* Pass the frame to the stage worker thread, along with all the info it needs. */ +void CameraData::runStages(const ipa::RPi::BufferIds &buffers, const ipa::RPi::StageParams ¶ms, + const BufferObject &bayer) +{ + stageBuffers_ = buffers; + + StageJob job; + job.params = params; + if (bayer.mapped && !bayer.mapped->planes().empty()) + job.bayerData = bayer.mapped->planes()[0]; + job.bayerFd = bayer.buffer->planes()[0].fd; + job.bayerFormat = stageFormat_; + + stageRunner_.run(job); +} + +/* This is what gets signalled when all the stages finish with a frame. */ +void CameraData::stagesComplete() +{ + if (!isRunning()) + return; + + platformStagesComplete(stageBuffers_); +} + void CameraData::metadataReady(const ControlList &metadata) { if (!isRunning()) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 7b872555..408a4b58 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -33,6 +33,8 @@ #include "delayed_controls.h" #include "rpi_stream.h" +#include "stage.h" +#include "stage_runner.h" using namespace std::chrono_literals; @@ -51,6 +53,12 @@ public: : Camera::Private(pipe), state_(State::Stopped), startupFrameCount_(0), invalidFrameCount_(0), buffersAllocated_(false) { + stageRunner_.stagesComplete.connect(this, &CameraData::stagesComplete); + + /* + * Stages that can run on every platform would be added here: + * e.g. addStage(std::make_unique()); + */ } virtual ~CameraData() @@ -99,6 +107,21 @@ public: virtual int platformPipelineConfigure(const std::unique_ptr &root) = 0; + /* + * Pipeline handler "stages" (stage.h) operate on the raw Bayer + * buffer after the IPA's prepareIsp, and before the ISP proper. They + * run in a per-camera worker thread, which is all handled here. + */ + int configureStages(const ipa::RPi::StageConfig &config); + void startStages(); + void stopStages(); + bool stagesActive() const; + void runStages(const ipa::RPi::BufferIds &buffers, const ipa::RPi::StageParams ¶ms, + const BufferObject &bayer); + void stagesComplete(); + /* How the platform carries on with a frame once its stages are done. */ + virtual void platformStagesComplete(const ipa::RPi::BufferIds &buffers) = 0; + std::unique_ptr ipa_; std::unique_ptr sensor_; @@ -196,8 +219,21 @@ protected: virtual void tryRunPipeline() = 0; + /* Register a stage. Platforms add their own stages in their constructors. */ + void addStage(std::unique_ptr stage) { stageRunner_.addStage(std::move(stage)); } + private: void checkRequestCompleted(); + + /* Owns the stages, and runs them in its worker thread. */ + StageRunner stageRunner_; + /* The raw Bayer format (taken from the frontend device), for the stages. */ + StageFormat stageFormat_; + /* + * The buffers of the frame in the stages, for when they've finished (there's + * only ever a single frame in flight). + */ + ipa::RPi::BufferIds stageBuffers_; }; class PipelineHandlerBase : public PipelineHandler diff --git a/src/libcamera/pipeline/rpi/common/stage.h b/src/libcamera/pipeline/rpi/common/stage.h new file mode 100644 index 00000000..d3f1b74f --- /dev/null +++ b/src/libcamera/pipeline/rpi/common/stage.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Raspberry Pi Ltd + * + * Base class for pipeline handler "stages" + */ + +#pragma once + +#include +#include + +#include + +#include +#include + +#include + +namespace libcamera { + +namespace RPi { + +/* The format of the raw Bayer buffers. */ +struct StageFormat { + PixelFormat pixelFormat; + Size size; + unsigned int stride = 0; +}; + +/* Everything the stages need to process a frame. */ +struct StageJob { + /* Per-frame parameters for all the stages, from the IPA. */ + ipa::RPi::StageParams params; + + /* The raw Bayer buffer (empty if not mapped) and associated info. */ + std::span bayerData; + SharedFD bayerFd; + StageFormat bayerFormat; +}; + +/* + * A pipeline handler stage operates on the raw Bayer buffer after the IPA's + * prepareIsp and before the ISP proper. To create one, derive from Stage and + * implement the functions below. It gets added in the CameraData constructor + * (or a platform's derived constructor if it can't run everywhere). + * + * An IPA algorithm must also be provided to supply the configuration and + * per-frame parameters. + */ +class Stage +{ +public: + virtual ~Stage() = default; + + virtual const char *name() const = 0; + + /* + * Called when the camera is configured. Return a positive value if + * the stage will run, 0 if it won't, or a negative error code if it + * should run but can't, which causes the camera configuration to fail. + */ + virtual int configure(const ipa::RPi::StageConfig &config, const StageFormat &format) = 0; + + /* Called when the camera starts and stops, for stages that are enabled. */ + virtual void start() {} + virtual void stop() {} + + /* Runs in the stage worker thread for every frame. */ + virtual void run(StageJob &job) = 0; +}; + +} /* namespace RPi */ + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/common/stage_runner.cpp b/src/libcamera/pipeline/rpi/common/stage_runner.cpp new file mode 100644 index 00000000..fb227f3b --- /dev/null +++ b/src/libcamera/pipeline/rpi/common/stage_runner.cpp @@ -0,0 +1,149 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Raspberry Pi Ltd + * + * Worker thread for running pipeline handler stages + * + * The structure broadly follows the Software ISP (software_isp.cpp): an + * object used from the pipeline handler has a worker thread where it runs + * its "stages", signalling back to the pipeline handler when they're done. + */ + +#include "stage_runner.h" + +#include +#include + +namespace libcamera { + +LOG_DECLARE_CATEGORY(RPI) + +namespace RPi { + +void StageWorker::process(StageJob job) +{ + for (Stage *stage : stages_) + stage->run(job); + + done.emit(); +} + +void StageWorker::stop() +{ + /* Nothing to do. A blocking call will wait for everything to finish. */ +} + +StageRunner::StageRunner() + : stageWorkerThread_("RPiStageWorker"), + worker_(std::make_unique()), running_(false) +{ + /* All the actual work has to be done in the worker thread. */ + worker_->done.connect(this, &StageRunner::workerDone); + worker_->moveToThread(&stageWorkerThread_); +} + +StageRunner::~StageRunner() +{ + stop(); + + /* Destroy the worker object before its thread goes. */ + worker_.reset(); +} + +/* Register a stage. Stages run in the order they were added. */ +void StageRunner::addStage(std::unique_ptr stage) +{ + ASSERT(!running_); + + LOG(RPI, Debug) << "Added stage " << stage->name(); + stages_.push_back(std::move(stage)); +} + +/* + * Configure all the stages, and make a list of the enabled ones. Fails if any + * stage should run but can't, in which case none will run. + */ +int StageRunner::configure(const ipa::RPi::StageConfig &config, const StageFormat &format) +{ + ASSERT(!running_); + + worker_->stages_.clear(); + + for (auto &stage : stages_) { + int ret = stage->configure(config, format); + if (ret < 0) { + LOG(RPI, Error) << "Stage " << stage->name() << " failed to configure: " << ret; + worker_->stages_.clear(); + return ret; + } + if (ret > 0) { + worker_->stages_.push_back(stage.get()); + LOG(RPI, Debug) << "Stage " << stage->name() << " is active"; + } + } + + return 0; +} + +/* Start the stages, and the worker thread that runs them. */ +void StageRunner::start() +{ + if (running_) + return; + + for (Stage *stage : worker_->stages_) + stage->start(); + + stageWorkerThread_.start(); + running_ = true; + + LOG(RPI, Debug) << "Stage worker thread started with " + << worker_->stages_.size() << " stage(s)"; +} + +/* + * Wait for any job in progress to finish, and then stop everything + * (don't forget to send completion signals). + */ +void StageRunner::stop() +{ + if (!running_) + return; + + stopThread(); + + for (Stage *stage : worker_->stages_) + stage->stop(); + + running_ = false; + + LOG(RPI, Debug) << "Stage worker thread stopped"; +} + +void StageRunner::stopThread() +{ + if (!stageWorkerThread_.isRunning()) + return; + + worker_->invokeMethod(&StageWorker::stop, ConnectionTypeBlocking); + + stageWorkerThread_.exit(); + stageWorkerThread_.wait(); + + Thread::current()->dispatchMessages(Message::Type::InvokeMessage, this); +} + +void StageRunner::run(const StageJob &job) +{ + ASSERT(running_); + worker_->invokeMethod(&StageWorker::process, ConnectionTypeQueued, job); +} + +void StageRunner::workerDone() +{ + stagesComplete.emit(); +} + +} /* namespace RPi */ + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/common/stage_runner.h b/src/libcamera/pipeline/rpi/common/stage_runner.h new file mode 100644 index 00000000..a5c72434 --- /dev/null +++ b/src/libcamera/pipeline/rpi/common/stage_runner.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Raspberry Pi Ltd + * + * Worker thread for running pipeline handler stages + */ + +#pragma once + +#include +#include + +#include +#include +#include + +#include "stage.h" + +namespace libcamera { + +namespace RPi { + +/* + * The StageWorker runs all the active stages in the worker thread, + * and signals when they're done. + */ +class StageWorker : public Object +{ +public: + void process(StageJob job); + void stop(); + + Signal<> done; + + /* The active stages. Only changed while the worker thread isn't running. */ + std::vector stages_; +}; + +/* + * The StageRunner owns all the stages, keeps a list of the active ones, and + * has the worker thread that runs them. + */ +class StageRunner : public Object +{ +public: + StageRunner(); + ~StageRunner(); + + void addStage(std::unique_ptr stage); + int configure(const ipa::RPi::StageConfig &config, const StageFormat &format); + bool hasActiveStages() const { return !worker_->stages_.empty(); } + + void start(); + void stop(); + + void run(const StageJob &job); + + Signal<> stagesComplete; + +private: + void stopThread(); + void workerDone(); + + /* All the stages, in the order they run, whether active or not. */ + std::vector> stages_; + + Thread stageWorkerThread_; + std::unique_ptr worker_; + bool running_; +}; + +} /* namespace RPi */ + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp index 40ad91c2..fc7b283a 100644 --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp @@ -761,6 +761,7 @@ public: void processStatsComplete(const ipa::RPi::BufferIds &buffers); void prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers, const ipa::RPi::StageParams &stageParams); + void finishPrepareIsp(unsigned int bayerId, bool stitchSwapBuffers); void setCameraTimeout(uint32_t maxFrameLengthMs); /* Array of CFE and ISP device streams and associated buffers/streams. */ @@ -774,6 +775,12 @@ public: SharedMemObject be_; bool beEnabled_; + /* + * The stitch buffer swap flag for the frame in the pipeline stages, for + * when they've finished. Only one frame is ever in the stages at a time. + */ + bool stagesStitchSwapBuffers_ = false; + std::unique_ptr csi2Subdev_; std::unique_ptr feSubdev_; @@ -807,6 +814,8 @@ public: private: int platformConfigure(const RPi::RPiCameraConfiguration *rpiConfig) override; + void platformStagesComplete(const ipa::RPi::BufferIds &buffers) override; + int platformConfigureIpa([[maybe_unused]] ipa::RPi::ConfigParams ¶ms) override { return 0; @@ -1887,7 +1896,7 @@ void PiSPCameraData::setCameraTimeout(uint32_t maxFrameLengthMs) } void PiSPCameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers, - [[maybe_unused]] const ipa::RPi::StageParams &stageParams) + const ipa::RPi::StageParams &stageParams) { unsigned int embeddedId = buffers.embedded & RPi::MaskID; unsigned int bayerId = buffers.bayer & RPi::MaskID; @@ -1901,6 +1910,27 @@ void PiSPCameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool handleStreamBuffer(buffer, &cfe_[Cfe::Embedded]); } + if (stagesActive()) { + /* + * Run stages on the raw buffer asynchronously, this will signal + * back to platformStagesComplete() once it's done. + */ + const RPi::BufferObject &bayer = cfe_[Cfe::Output0].getBuffers().at(bayerId); + stagesStitchSwapBuffers_ = stitchSwapBuffers; + runStages(buffers, stageParams, bayer); + return; + } + + finishPrepareIsp(bayerId, stitchSwapBuffers); +} + +/* Raw buffer is ready for the Back End, either straight from prepareIspComplete + * or via runStages signalling back to us. + */ +void PiSPCameraData::finishPrepareIsp(unsigned int bayerId, bool stitchSwapBuffers) +{ + FrameBuffer *buffer; + if (!beEnabled_) { /* * If there is no need to run the Backend, just signal that the @@ -1915,6 +1945,11 @@ void PiSPCameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool handleState(); } +void PiSPCameraData::platformStagesComplete(const ipa::RPi::BufferIds &buffers) +{ + finishPrepareIsp(buffers.bayer & RPi::MaskID, stagesStitchSwapBuffers_); +} + int PiSPCameraData::configureCfe() { V4L2DeviceFormat cfeFormat; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 4bcaae54..7a010cf3 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -81,6 +81,8 @@ public: void processStatsComplete(const ipa::RPi::BufferIds &buffers); void prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers, const ipa::RPi::StageParams &stageParams); + void queueIspInput(unsigned int bayerId); + void platformStagesComplete(const ipa::RPi::BufferIds &buffers) override; void setIspControls(const ControlList &controls); void setCameraTimeout(uint32_t maxFrameLengthMs); @@ -866,7 +868,7 @@ void Vc4CameraData::processStatsComplete(const ipa::RPi::BufferIds &buffers) void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, [[maybe_unused]] bool stitchSwapBuffers, - [[maybe_unused]] const ipa::RPi::StageParams &stageParams) + const ipa::RPi::StageParams &stageParams) { unsigned int embeddedId = buffers.embedded & RPi::MaskID; unsigned int bayer = buffers.bayer & RPi::MaskID; @@ -875,11 +877,15 @@ void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, if (!isRunning()) return; - buffer = unicam_[Unicam::Image].getBuffers().at(bayer & RPi::MaskID).buffer; - LOG(RPI, Debug) << "Input re-queue to ISP, buffer id " << (bayer & RPi::MaskID) - << ", timestamp: " << buffer->metadata().timestamp; - - isp_[Isp::Input].queueBuffer(buffer); + if (stagesActive()) { + /* + * Run stages on the raw buffer asynchronously, this will signal + * back to platformStagesComplete() once it's done. + */ + const RPi::BufferObject &bayerBuffer = unicam_[Unicam::Image].getBuffers().at(bayer); + runStages(buffers, stageParams, bayerBuffer); + } else + queueIspInput(bayer); if (sensorMetadata_ && embeddedId) { buffer = unicam_[Unicam::Embedded].getBuffers().at(embeddedId & RPi::MaskID).buffer; @@ -889,6 +895,22 @@ void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers, handleState(); } +void Vc4CameraData::queueIspInput(unsigned int bayerId) +{ + FrameBuffer *buffer = unicam_[Unicam::Image].getBuffers().at(bayerId).buffer; + + LOG(RPI, Debug) << "Input re-queue to ISP, buffer id " << bayerId + << ", timestamp: " << buffer->metadata().timestamp; + + isp_[Isp::Input].queueBuffer(buffer); +} + +void Vc4CameraData::platformStagesComplete(const ipa::RPi::BufferIds &buffers) +{ + queueIspInput(buffers.bayer & RPi::MaskID); + handleState(); +} + void Vc4CameraData::setIspControls(const ControlList &controls) { ControlList ctrls = controls; 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 */