[libcamera-devel] [PATCH v5 05/12] pipeline: raspberrypi: Handle OptionalStream hints for Unicam Image

Naushir Patuck naush at raspberrypi.com
Wed Jan 18 09:59:46 CET 2023


Look for OptionalStream flag in the hints field of the Unicam Image
StreamConfiguration structure. If this flag is not set, it guarantees that the
application will provide buffers for Unicam Image, so override the
minUnicamBuffers and minTotalUnicamBuffers config parameters in the following
way:

- If startup drop frames are required, allocate at least 1 internal buffer.
- If no startup drop frames are required, do not allocate any internal buffers.

All other buffer allocations remain unchanged.

Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
---
 .../pipeline/raspberrypi/raspberrypi.cpp      | 36 ++++++++++++++-----
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index 8d325c7a18c5..6ed4cc2c7ba7 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -1448,12 +1448,33 @@ int PipelineHandlerRPi::queueAllBuffers(Camera *camera)
 int PipelineHandlerRPi::prepareBuffers(Camera *camera)
 {
 	RPiCameraData *data = cameraData(camera);
-	unsigned int numRawBuffers = 0;
+	unsigned int minUnicamBuffers = data->config_.minUnicamBuffers,
+		     minTotalUnicamBuffers = data->config_.minTotalUnicamBuffers,
+		     numRawBuffers = 0;
 	int ret;
 
 	for (Stream *s : camera->streams()) {
-		if (isRaw(s->configuration().pixelFormat)) {
+		if (s == &data->unicam_[Unicam::Image]) {
 			numRawBuffers = s->configuration().bufferCount;
+			/*
+			 * If the application provides a guarantees that Unicam
+			 * image buffers will always be provided for the RAW stream
+			 * in a Request, we need:
+			 * - at least 1 internal Unicam buffer to handle startup frame drops,
+			 * - no internal Unicam buffers if there are no startup frame drops.
+			 */
+			if (!(s->configuration().hints &
+			      StreamConfiguration::Hint::OptionalStream)) {
+				if (data->dropFrameCount_) {
+					minUnicamBuffers = std::max(1u, minUnicamBuffers);
+					minTotalUnicamBuffers =
+						std::max(minUnicamBuffers, minTotalUnicamBuffers);
+				} else {
+					minUnicamBuffers = 0;
+					minTotalUnicamBuffers = 0;
+				}
+			}
+
 			break;
 		}
 	}
@@ -1465,7 +1486,6 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)
 		 * For Unicam, allocate a minimum number of buffers for internal
 		 * use as we want to avoid any frame drops.
 		 */
-		const unsigned int minBuffers = data->config_.minTotalUnicamBuffers;
 		if (stream == &data->unicam_[Unicam::Image]) {
 			/*
 			 * If an application has configured a RAW stream, allocate
@@ -1473,8 +1493,8 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)
 			 * we have at least minUnicamBuffers of internal buffers
 			 * to use to minimise frame drops.
 			 */
-			numBuffers = std::max<int>(data->config_.minUnicamBuffers,
-						   minBuffers - numRawBuffers);
+			numBuffers = std::max<int>(minUnicamBuffers,
+						   minTotalUnicamBuffers - numRawBuffers);
 		} else if (stream == &data->isp_[Isp::Input]) {
 			/*
 			 * ISP input buffers are imported from Unicam, so follow
@@ -1482,15 +1502,15 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)
 			 * available.
 			 */
 			numBuffers = numRawBuffers +
-				     std::max<int>(data->config_.minUnicamBuffers,
-						   minBuffers - numRawBuffers);
+				     std::max<int>(minUnicamBuffers,
+						   minTotalUnicamBuffers - numRawBuffers);
 
 		} else if (stream == &data->unicam_[Unicam::Embedded]) {
 			/*
 			 * Embedded data buffers are (currently) for internal use,
 			 * so allocate the minimum required to avoid frame drops.
 			 */
-			numBuffers = minBuffers;
+			numBuffers = data->config_.minTotalUnicamBuffers;
 		} else {
 			/*
 			 * Since the ISP runs synchronous with the IPA and requests,
-- 
2.25.1



More information about the libcamera-devel mailing list