[libcamera-devel,8/8,POC] cam: add hack option to staticly configure a pipeline

Message ID 20190122234505.32634-9-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • libcamera: add basic support for Streams and format configuration
Related show

Commit Message

Niklas Söderlund Jan. 22, 2019, 11:45 p.m. UTC
This is a hack prof of concept to try out the application API to query a
camera about its streams and then proceed to use that information to
configure a static resolution of 640x480.

Not-yet-Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/cam/main.cpp | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Patch

diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 22211670c6250887..6ff6dc978d91d323 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -21,6 +21,7 @@  enum {
 	OptCamera = 'c',
 	OptHelp = 'h',
 	OptList = 'l',
+	OptStreamsConfig = 'C',
 };
 
 static int parseOptions(int argc, char *argv[])
@@ -32,6 +33,7 @@  static int parseOptions(int argc, char *argv[])
 			 "camera");
 	parser.addOption(OptHelp, "Display this help message", "help");
 	parser.addOption(OptList, "List all cameras", "list");
+	parser.addOption(OptStreamsConfig, "Configure the first stream to 640x480", "hack-config");
 
 	options = std::move(parser.parse(argc, argv));
 	if (!options.valid())
@@ -79,6 +81,42 @@  int main(int argc, char **argv)
 		}
 	}
 
+	if (options.isSet(OptStreamsConfig)) {
+		if (!options.isSet(OptCamera)) {
+			std::cout << "Can't configure stream, no camera selected" << std::endl;
+			goto out;
+		}
+
+		std::shared_ptr<Camera> cam = cm->get(options[OptCamera]);
+		if (!cam) {
+			std::cout << "Camera " << options[OptCamera]
+				  << " not found" << std::endl;
+			goto out;
+		}
+
+		std::vector<Stream> streams = cam->streams();
+		if (streams.size() != 1) {
+			std::cout << "Camera have " << streams.size() <<
+				" streams, I only know how to work with 1" << std::endl;
+			goto out;
+		}
+
+		StreamConfiguration config = StreamConfiguration(streams.front());
+		config.setDimension(640, 480);
+
+		std::vector<StreamConfiguration *> configs;
+		configs.push_back(&config);
+
+		if (cam->acquire()) {
+			std::cout << "Failed to acquire camera" << std::endl;
+			goto out;
+		}
+
+		if (cam->configure(configs))
+			std::cout << "Failed to configure camera" << std::endl;
+	}
+
+out:
 	cm->stop();
 
 	return 0;