[PATCH v11 03/19] libcamera: pipeline: rpi: Don't rely on bufferCount

Sven Püschel s.pueschel at pengutronix.de
Mon Apr 28 11:02:28 CEST 2025


From: Nícolas F. R. A. Prado <nfraprado at collabora.com>

Currently the raspberrypi pipeline handler relies on bufferCount to
decide on the number of buffers to allocate internally and for the
number of V4L2 buffer slots to reserve.

There already exists a procedure for determining the number of buffers
to reserve, so to remove reliance on bufferCount we simply replace the
one instance that it is used in, as well as remove populating it in
generateConfiguration().

Signed-off-by: Nícolas F. R. A. Prado <nfraprado at collabora.com>
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
Signed-off-by: Sven Püschel <s.pueschel at pengutronix.de>

---
Changes in v11:
- adapted pisp.cpp similar to vc4.cpp
- corrected spelling errors in commit description

Changes in v10:
- completely changed, to leverage the existing buffer count calculations
  - the refactoring that was in v9's rebase wasn't necessary, i think
  - this also makes it conflict less with [1] which ought to be coming
    soon
[1] https://patchwork.libcamera.org/project/libcamera/list/?series=3663

Changes in v9:
- rebased
  - I've decided that the buffer allocation decisions that N?colas
    implemented covered the same cases that were added in
    PipelineHandlerRPi::prepareBuffers(), but in a slightly nicer way,
    especially considering that bufferCount is to be removed from
    StreamConfiguration in this series. Comments welcome, of course.

Changes in v8:
- Reworked buffer allocation handling in the raspberrypi pipeline handler
- New
---
 src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 6 ------
 src/libcamera/pipeline/rpi/pisp/pisp.cpp            | 2 +-
 src/libcamera/pipeline/rpi/vc4/vc4.cpp              | 2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index dc1e0a2e..bcc74052 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -388,7 +388,6 @@ PipelineHandlerBase::generateConfiguration(Camera *camera, Span<const StreamRole
 	std::unique_ptr<CameraConfiguration> config =
 		std::make_unique<RPiCameraConfiguration>(data);
 	V4L2SubdeviceFormat sensorFormat;
-	unsigned int bufferCount;
 	PixelFormat pixelFormat;
 	V4L2VideoDevice::Formats fmts;
 	Size size;
@@ -407,7 +406,6 @@ PipelineHandlerBase::generateConfiguration(Camera *camera, Span<const StreamRole
 							    BayerFormat::Packing::CSI2);
 			ASSERT(pixelFormat.isValid());
 			colorSpace = ColorSpace::Raw;
-			bufferCount = 2;
 			break;
 
 		case StreamRole::StillCapture:
@@ -421,7 +419,6 @@ PipelineHandlerBase::generateConfiguration(Camera *camera, Span<const StreamRole
 			colorSpace = ColorSpace::Sycc;
 			/* Return the largest sensor resolution. */
 			size = sensorSize;
-			bufferCount = 1;
 			break;
 
 		case StreamRole::VideoRecording:
@@ -441,7 +438,6 @@ PipelineHandlerBase::generateConfiguration(Camera *camera, Span<const StreamRole
 			 */
 			colorSpace = ColorSpace::Rec709;
 			size = { 1920, 1080 };
-			bufferCount = 4;
 			break;
 
 		case StreamRole::Viewfinder:
@@ -449,7 +445,6 @@ PipelineHandlerBase::generateConfiguration(Camera *camera, Span<const StreamRole
 			pixelFormat = formats::XRGB8888;
 			colorSpace = ColorSpace::Sycc;
 			size = { 800, 600 };
-			bufferCount = 4;
 			break;
 
 		default:
@@ -494,7 +489,6 @@ PipelineHandlerBase::generateConfiguration(Camera *camera, Span<const StreamRole
 		cfg.size = size;
 		cfg.pixelFormat = pixelFormat;
 		cfg.colorSpace = colorSpace;
-		cfg.bufferCount = bufferCount;
 		config->addConfiguration(cfg);
 	}
 
diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp
index 91e7f4c9..0f607a64 100644
--- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp
+++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp
@@ -965,7 +965,7 @@ int PipelineHandlerPiSP::prepareBuffers(Camera *camera)
 
 	for (Stream *s : camera->streams()) {
 		if (PipelineHandlerBase::isRaw(s->configuration().pixelFormat)) {
-			numRawBuffers = s->configuration().bufferCount;
+			numRawBuffers = data->cfe_[Cfe::Output0].getBuffers().size();
 			break;
 		}
 	}
diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
index fe910bdf..97e7a6ff 100644
--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp
+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
@@ -224,7 +224,7 @@ int PipelineHandlerVc4::prepareBuffers(Camera *camera)
 
 	for (Stream *s : camera->streams()) {
 		if (BayerFormat::fromPixelFormat(s->configuration().pixelFormat).isValid()) {
-			numRawBuffers = s->configuration().bufferCount;
+			numRawBuffers = data->unicam_[Unicam::Image].getBuffers().size();
 			break;
 		}
 	}
-- 
2.49.0



More information about the libcamera-devel mailing list