[PATCH v11 07/19] libcamera: pipeline: vimc, uvcvideo: Don't rely on bufferCount

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


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

Instead of using bufferCount as the number of V4L2 buffer slots to
reserve in the vimc and uvcvideo pipeline handlers, use a reasonably
high constant: 16. Overallocating isn't a problem as buffer slots are
cheap. Having too few, on the other hand, could degrade performance. It
is expected that this number will be more than enough for most, if not
all, use cases.

This makes way for removing bufferCount.

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

---
Changes in v11:
- rebased

Changes in v9:
- rebased

Changes in v8:
- New
---
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 5 +++--
 src/libcamera/pipeline/vimc/vimc.cpp         | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 60c82364..e1259cf3 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -109,6 +109,8 @@ private:
 	{
 		return static_cast<UVCCameraData *>(camera->_d());
 	}
+
+	static constexpr unsigned int kUVCBufferSlotCount = 16;
 };
 
 namespace {
@@ -291,9 +293,8 @@ int PipelineHandlerUVC::exportFrameBuffers(Camera *camera,
 int PipelineHandlerUVC::start(Camera *camera, [[maybe_unused]] const ControlList *controls)
 {
 	UVCCameraData *data = cameraData(camera);
-	unsigned int count = data->stream_.configuration().bufferCount;
 
-	int ret = data->video_->importBuffers(count);
+	int ret = data->video_->importBuffers(kUVCBufferSlotCount);
 	if (ret < 0)
 		return ret;
 
diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
index 8833647a..e66dbd78 100644
--- a/src/libcamera/pipeline/vimc/vimc.cpp
+++ b/src/libcamera/pipeline/vimc/vimc.cpp
@@ -109,6 +109,8 @@ private:
 	{
 		return static_cast<VimcCameraData *>(camera->_d());
 	}
+
+	static constexpr unsigned int kVimcBufferSlotCount = 16;
 };
 
 namespace {
@@ -356,9 +358,8 @@ int PipelineHandlerVimc::exportFrameBuffers(Camera *camera,
 int PipelineHandlerVimc::start(Camera *camera, [[maybe_unused]] const ControlList *controls)
 {
 	VimcCameraData *data = cameraData(camera);
-	unsigned int count = data->stream_.configuration().bufferCount;
 
-	int ret = data->video_->importBuffers(count);
+	int ret = data->video_->importBuffers(kVimcBufferSlotCount);
 	if (ret < 0)
 		return ret;
 
-- 
2.49.0



More information about the libcamera-devel mailing list