[libcamera-devel] [PATCH 1/2] libcamera: pipeline: simple: make sure the formats at the link's pads match

Andrey Konovalov andrey.konovalov at linaro.org
Tue Apr 21 22:39:53 CEST 2020


Change SimpleCameraData::setupFormats() to return -EINVAL if the sink
pad of the link doesn't support the format set on the source pad of this
link.

Signed-off-by: Andrey Konovalov <andrey.konovalov at linaro.org>
---
 src/libcamera/pipeline/simple/simple.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index b5f9177..8212bd9 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -372,6 +372,7 @@ int SimpleCameraData::setupFormats(V4L2SubdeviceFormat *format,
 		MediaLink *link = e.link;
 		MediaPad *source = link->source();
 		MediaPad *sink = link->sink();
+		V4L2SubdeviceFormat source_format;
 
 		if (source->entity() != sensor_->entity()) {
 			V4L2Subdevice *subdev = pipe->subdev(source->entity());
@@ -380,11 +381,22 @@ int SimpleCameraData::setupFormats(V4L2SubdeviceFormat *format,
 				return ret;
 		}
 
+		source_format = *format;
 		if (sink->entity()->function() != MEDIA_ENT_F_IO_V4L) {
 			V4L2Subdevice *subdev = pipe->subdev(sink->entity());
 			ret = subdev->setFormat(sink->index(), format, whence);
 			if (ret < 0)
 				return ret;
+
+			if (format->mbus_code != source_format.mbus_code
+			    || format->size != source_format.size) {
+				LOG(SimplePipeline, Debug)
+					<< "Source pad format isn't supported "
+					<< "by the sink pad of the link: "
+					<< "Source: " << source_format.toString()
+					<< "Sink: " << format->toString();
+				return -EINVAL;
+			}
 		}
 
 		LOG(SimplePipeline, Debug)
-- 
2.17.1



More information about the libcamera-devel mailing list