[v1,3/5] ipa: rpi: Add StageConfig and StageParams to the IPA interface
diff mbox series

Message ID 20261203130113.47873-4-david.plowman@raspberrypi.com
State New
Headers show
Series
  • Extra pipeline processing "stages" for Raspberry Pi
Related show

Commit Message

David Plowman Dec. 2, 2026, 4:13 p.m. UTC
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 <david.plowman@raspberrypi.com>
---
 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(-)

Patch
diff mbox series

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 &params)
 		/* 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 &params)
 		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 &params)
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;