[RFC PATCH 5/7] apps: cam: Report error on multiple default sinks

Milan Zamazal mzamazal at redhat.com
Fri Mar 14 21:29:33 CET 2025


Multiple default sinks are not really supported, if more than one sink
is present then the last one wins and the other ones are just created
but not used actually.  Let's check for this and report an error in such
a case.

Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
---
 src/apps/cam/camera_session.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp
index 54073cdf..b1f5209d 100644
--- a/src/apps/cam/camera_session.cpp
+++ b/src/apps/cam/camera_session.cpp
@@ -265,11 +265,21 @@ int CameraSession::start()
 #endif
 
 #ifdef HAVE_SDL
-	if (options_.isSet(OptSDL))
+	if (options_.isSet(OptSDL)) {
+		if (defaultSink) {
+			std::cerr << "Multiple default sinks not allowed" << std::endl;
+			return -EINVAL;
+		}
 		defaultSink = std::make_unique<SDLSink>();
+	}
 #endif
 
 	if (options_.isSet(OptFile)) {
+		if (defaultSink) {
+			std::cerr << "Multiple default sinks not allowed" << std::endl;
+			return -EINVAL;
+		}
+
 		std::unique_ptr<FileSink> sink =
 			std::make_unique<FileSink>(camera_.get(), streamNames_);
 
-- 
2.48.1



More information about the libcamera-devel mailing list