libcamera: pipeline: rkisp1: Don't rely on bufferCount
diff mbox series

Message ID 20250527153732.39348-2-s.pueschel@pengutronix.de
State New
Headers show
Series
  • libcamera: pipeline: rkisp1: Don't rely on bufferCount
Related show

Commit Message

Sven Püschel May 27, 2025, 3:14 p.m. UTC
From: Nícolas F. R. A. Prado <nfraprado@collabora.com>

Currently the rkisp1 pipeline handler relies on bufferCount to decide on
the number of parameter and statistics buffers to allocate internally.
Instead, the number of internal buffers should be the minimum required
by the pipeline to keep the requests flowing, in order to avoid wasting
memory.

Stop relying on bufferCount for these numbers and instead set them to
kPipelineDepth, as this already limits the number of buffers queued
to the driver.

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

---
- Migrated from [1]
  - Removed rkisp1_path adjustments, as they are already handled by Stefan's patches
  - Removed Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
  - Removed Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

[1] https://lists.libcamera.org/pipermail/libcamera-devel/2025-April/050029.html
---
 src/libcamera/pipeline/rkisp1/rkisp1.cpp | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index ea94bccd..51918f4b 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -157,6 +157,10 @@  private:
 
 namespace {
 
+/*
+ * This many internal buffers (or rather parameter and statistics buffer
+ * pairs) ensures that the pipeline runs smoothly, without frame drops.
+ */
 const unsigned int kPipelineDepth = 4;
 
 };
@@ -991,24 +995,19 @@  int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)
 	unsigned int ipaBufferId = 1;
 	int ret;
 
-	unsigned int maxCount = std::max({
-		data->mainPathStream_.configuration().bufferCount,
-		data->selfPathStream_.configuration().bufferCount,
-	});
-
 	if (!isRaw_) {
-		ret = param_->allocateBuffers(maxCount, &paramBuffers_);
+		ret = param_->allocateBuffers(kPipelineDepth, &paramBuffers_);
 		if (ret < 0)
 			goto error;
 
-		ret = stat_->allocateBuffers(maxCount, &statBuffers_);
+		ret = stat_->allocateBuffers(kPipelineDepth, &statBuffers_);
 		if (ret < 0)
 			goto error;
 	}
 
 	/* If the dewarper is being used, allocate internal buffers for ISP. */
 	if (useDewarper_) {
-		ret = mainPath_.exportBuffers(maxCount, &mainPathBuffers_);
+		ret = mainPath_.exportBuffers(kPipelineDepth, &mainPathBuffers_);
 		if (ret < 0)
 			goto error;