[PATCH/RFC 26/32] pipeline: raspberrypi: vc4: Reorganize platformConfigure()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Mar 1 22:21:15 CET 2024


The Vc4CameraData::platformConfigure() function configures inicam and
the ISP. The corresponding configuration steps are interleaved, making
it more difficult to read the code and follow the flow. Reorganize the
function to improve readability.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/libcamera/pipeline/rpi/vc4/vc4.cpp | 65 ++++++++++++++------------
 1 file changed, 36 insertions(+), 29 deletions(-)

diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
index 4b0eb93745cf..3c3c1b30f9e3 100644
--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp
+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
@@ -537,9 +537,9 @@ int Vc4CameraData::platformPipelineConfigure(const std::unique_ptr<YamlObject> &
 
 int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfig)
 {
-	const std::vector<StreamParams> &rawStreams = rpiConfig->rawStreams_;
-	const std::vector<StreamParams> &outStreams = rpiConfig->outStreams_;
-	int ret;
+	/*
+	 * 1. Configure the Unicam video devices.
+	 */
 
 	V4L2VideoDevice *unicam = unicam_[Unicam::Image].dev();
 	V4L2DeviceFormat unicamFormat;
@@ -548,6 +548,8 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi
 	 * See which streams are requested, and route the user
 	 * StreamConfiguration appropriately.
 	 */
+	const std::vector<StreamParams> &rawStreams = rpiConfig->rawStreams_;
+
 	if (!rawStreams.empty()) {
 		rawStreams[0].cfg->setStream(&unicam_[Unicam::Image]);
 		unicam_[Unicam::Image].setFlags(StreamFlag::External);
@@ -559,11 +561,7 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi
 								     BayerFormat::Packing::CSI2);
 	}
 
-	ret = unicam->setFormat(&unicamFormat);
-	if (ret)
-		return ret;
-
-	ret = isp_[Isp::Input].dev()->setFormat(&unicamFormat);
+	int ret = unicam->setFormat(&unicamFormat);
 	if (ret)
 		return ret;
 
@@ -571,7 +569,37 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi
 		       << " - Selected sensor format: " << rpiConfig->sensorFormat_
 		       << " - Selected unicam format: " << unicamFormat;
 
+	/*
+	 * Configure the Unicam embedded data output format only if the sensor
+	 * supports it.
+	 */
+	if (sensorMetadata_) {
+		V4L2SubdeviceFormat embeddedFormat;
+
+		sensor_->device()->getFormat(1, &embeddedFormat);
+		V4L2DeviceFormat format{};
+		format.fourcc = V4L2PixelFormat(V4L2_META_FMT_SENSOR_DATA);
+		format.planes[0].size = embeddedFormat.size.width * embeddedFormat.size.height;
+
+		LOG(RPI, Debug) << "Setting embedded data format " << format;
+		ret = unicam_[Unicam::Embedded].dev()->setFormat(&format);
+		if (ret) {
+			LOG(RPI, Error) << "Failed to set format on Unicam embedded: "
+					<< format;
+			return ret;
+		}
+	}
+
+	/*
+	 * 2. Configure the ISP.
+	 */
+
+	ret = isp_[Isp::Input].dev()->setFormat(&unicamFormat);
+	if (ret)
+		return ret;
+
 	/* Use a sensible small default size if no output streams are configured. */
+	const std::vector<StreamParams> &outStreams = rpiConfig->outStreams_;
 	Size maxSize = outStreams.empty() ? Size(320, 240) : outStreams[0].cfg->size;
 	V4L2DeviceFormat format;
 
@@ -678,27 +706,6 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi
 
 	ispOutputTotal_++;
 
-	/*
-	 * Configure the Unicam embedded data output format only if the sensor
-	 * supports it.
-	 */
-	if (sensorMetadata_) {
-		V4L2SubdeviceFormat embeddedFormat;
-
-		sensor_->device()->getFormat(1, &embeddedFormat);
-		format = {};
-		format.fourcc = V4L2PixelFormat(V4L2_META_FMT_SENSOR_DATA);
-		format.planes[0].size = embeddedFormat.size.width * embeddedFormat.size.height;
-
-		LOG(RPI, Debug) << "Setting embedded data format " << format;
-		ret = unicam_[Unicam::Embedded].dev()->setFormat(&format);
-		if (ret) {
-			LOG(RPI, Error) << "Failed to set format on Unicam embedded: "
-					<< format;
-			return ret;
-		}
-	}
-
 	/* Figure out the smallest selection the ISP will allow. */
 	Rectangle testCrop(0, 0, 1, 1);
 	isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &testCrop);
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list