[libcamera-devel] [PATCH v4 31/31] HACK: cam: Add options to select the stream to use

Jacopo Mondi jacopo at jmondi.org
Wed Mar 20 17:30:55 CET 2019


Add -o and -v options switches to the cam application to select which
streams to capture from.

Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/cam/main.cpp | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 28ea0b7d76b2..8c5d55d11bbe 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -31,6 +31,8 @@ enum {
 	OptFormat = 'f',
 	OptHelp = 'h',
 	OptList = 'l',
+	OptOutput = 'o',
+	OptViefinder = 'v',
 };
 
 void signalHandler(int signal)
@@ -65,6 +67,12 @@ static int parseOptions(int argc, char *argv[])
 	parser.addOption(OptHelp, OptionNone, "Display this help message",
 			 "help");
 	parser.addOption(OptList, OptionNone, "List all cameras", "list");
+	parser.addOption(OptOutput, OptionNone, "Use output stream\n"
+			 "If no '-o' or '-v' options are specified, use viewfinder stream only",
+			 "list");
+	parser.addOption(OptViefinder, OptionNone, "Use viewfinder stream\n"
+			 "If no '-o' or '-v' options are specified, use viewfinder stream only",
+			 "list");
 
 	options = parser.parse(argc, argv);
 	if (!options.valid() || options.isSet(OptHelp)) {
@@ -103,11 +111,15 @@ static int configureStreams(Camera *camera, std::set<Stream *> &streams,
 	defaultConfig[viewfinder].height = 480;
 
 	/*
-	 * HACK: add output/viewfinder to 'config'
-	 * to play with stream combinations.
+	 * HACK: Select which stream to capture: use output if required,
+	 * use viewfinder if required or if no option has been specified
+	 * from the command line.
 	 */
-	config[output] = defaultConfig[output];
-	config[viewfinder] = defaultConfig[viewfinder];
+	if (options.isSet(OptOutput))
+		config[output] = defaultConfig[output];
+	if (options.isSet(OptViefinder) ||
+	    (!options.isSet(OptViefinder) && !options.isSet(OptOutput)))
+		config[viewfinder] = defaultConfig[viewfinder];
 
 	return camera->configureStreams(config);
 }
-- 
2.21.0



More information about the libcamera-devel mailing list