summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-02-29 17:14:42 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-09-30 11:15:28 +0300
commit2355b5c947778bec4c148e5bafa63b53d2513f82 (patch)
treea4e98da7f967cbf32aa9ab8f2a6e810f26602a63
parent4a56269a35f1f0271e29ea6ecda79e43562dd1b7 (diff)
pipeline: raspberrypi: vc4: Reorganize platformConfigure()
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@ideasonboard.com>
-rw-r--r--src/libcamera/pipeline/rpi/vc4/vc4.cpp65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
index 269e8af7..e083cdd9 100644
--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp
+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp
@@ -536,9 +536,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;
@@ -547,6 +547,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);
@@ -558,11 +560,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;
@@ -570,7 +568,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;
@@ -677,27 +705,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);