[v1,2/3] ipa: rpi: Memory map raw stream buffers
diff mbox series

Message ID 20261118140719.46849-3-david.plowman@raspberrypi.com
State New
Headers show
Series
  • RPi: prepare for "pixel peeping" IPAs
Related show

Commit Message

David Plowman Nov. 18, 2026, 1:15 p.m. UTC
We memory map the raw stream buffers and track their fds, so that the
raw stream buffer, plus its shared fd, can in future be passed to
control algorithms (the fd is provided for DMA sync operations).

This will support future IPAs that may want to "pixel peep" at the raw
image data.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
---
 src/ipa/rpi/common/ipa_base.cpp               |  6 ++--
 src/ipa/rpi/common/ipa_base.h                 |  2 ++
 .../pipeline/rpi/common/pipeline_base.cpp     | 30 ++++++++++++++++++-
 .../pipeline/rpi/common/pipeline_base.h       |  1 +
 4 files changed, 34 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp
index 2ed80d3e..6707ab11 100644
--- a/src/ipa/rpi/common/ipa_base.cpp
+++ b/src/ipa/rpi/common/ipa_base.cpp
@@ -392,17 +392,15 @@  void IpaBase::mapBuffers(const std::vector<IPABuffer> &buffers)
 		const FrameBuffer fb(buffer.planes);
 		buffers_.emplace(buffer.id,
 				 MappedFrameBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite));
+		buffersFds_.emplace(buffer.id, buffer.planes[0].fd);
 	}
 }
 
 void IpaBase::unmapBuffers(const std::vector<unsigned int> &ids)
 {
 	for (unsigned int id : ids) {
-		auto it = buffers_.find(id);
-		if (it == buffers_.end())
-			continue;
-
 		buffers_.erase(id);
+		buffersFds_.erase(id);
 	}
 }
 
diff --git a/src/ipa/rpi/common/ipa_base.h b/src/ipa/rpi/common/ipa_base.h
index 0d7842f1..e3d8c3e6 100644
--- a/src/ipa/rpi/common/ipa_base.h
+++ b/src/ipa/rpi/common/ipa_base.h
@@ -11,6 +11,7 @@ 
 #include <map>
 #include <stdint.h>
 
+#include <libcamera/base/shared_fd.h>
 #include <libcamera/base/utils.h>
 #include <libcamera/controls.h>
 
@@ -104,6 +105,7 @@  private:
 	void applyAGC(struct AgcStatus *agcStatus, ControlList &ctrls);
 
 	std::map<unsigned int, MappedFrameBuffer> buffers_;
+	std::map<unsigned int, SharedFD> buffersFds_;
 
 	bool lensPresent_;
 	bool monoSensor_;
diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index 6944d5c4..6dc91a47 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -690,6 +690,9 @@  int PipelineHandlerBase::start(Camera *camera, const ControlList *controls)
 		data->buffersAllocated_ = true;
 	}
 
+	/* Map any Bayer buffers for IPAs that might want to "pixel peep". */
+	mapBayerBuffers(camera);
+
 	ret = queueAllBuffers(camera);
 	if (ret) {
 		LOG(RPI, Error) << "Failed to queue buffers";
@@ -775,6 +778,10 @@  int PipelineHandlerBase::queueRequestDevice(Camera *camera, Request *request)
 			 * so we can track it.
 			 */
 			stream->setExportedBuffer(buffer);
+
+			/* Map any new Bayer buffers. */
+			if (data->frontendDevice() == stream->dev())
+				mapBayerBuffers(camera);
 		}
 
 		/*
@@ -910,6 +917,10 @@  void PipelineHandlerBase::mapBuffers(Camera *camera, const BufferMap &buffers, u
 	 * handler and the IPA.
 	 */
 	for (const auto &[id, buffer] : buffers) {
+		/* Not essential, but avoids churn for buffers we already know about. */
+		if (data->bufferIds_.contains(mask | id))
+			continue;
+
 		std::span<const FrameBuffer::Plane> planes = buffer.buffer->planes();
 
 		bufferIds.emplace_back(mask | id,
@@ -917,7 +928,24 @@  void PipelineHandlerBase::mapBuffers(Camera *camera, const BufferMap &buffers, u
 		data->bufferIds_.insert(mask | id);
 	}
 
-	data->ipa_->mapBuffers(bufferIds);
+	if (!bufferIds.empty())
+		data->ipa_->mapBuffers(bufferIds);
+}
+
+/*
+ * Map all the Bayer buffers to the IPA, for any IPAs that may want to
+ * pixel-peep. Buffers that are already mapped are skipped.
+ */
+void PipelineHandlerBase::mapBayerBuffers(Camera *camera)
+{
+	CameraData *data = cameraData(camera);
+
+	for (const auto stream : data->streams_) {
+		if (stream->dev() == data->frontendDevice()) {
+			mapBuffers(camera, stream->getBuffers(), RPi::MaskBayerData);
+			break;
+		}
+	}
 }
 
 int PipelineHandlerBase::queueAllBuffers(Camera *camera)
diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h
index 7b872555..c027c235 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h
@@ -245,6 +245,7 @@  protected:
 			   MediaEntity *sensorEntity);
 
 	void mapBuffers(Camera *camera, const BufferMap &buffers, unsigned int mask);
+	void mapBayerBuffers(Camera *camera);
 
 	virtual int platformRegister(std::unique_ptr<CameraData> &cameraData,
 				     std::shared_ptr<MediaDevice> unicam,