summaryrefslogtreecommitdiff
path: root/src/cam/main.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-07 03:45:05 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-22 17:14:05 +0300
commite0704e97ea8907b13c769e0d2958829f94e65a96 (patch)
tree72fa1062eafda388bf7b52258098a2571a2c872a /src/cam/main.cpp
parent721f4b03d80fc7b65cfb4c7ecebe545ef1fe0565 (diff)
cam: Support using multiple cameras concurrently
To allow testing capture from multiple cameras concurrently, turn the --camera option into an array option, and create one CameraSession per specified camera. The code is adapted to iterate over the sessions vector instead of handling a single session. Thanks to all the refactoring previously performed, changes are minimal. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/cam/main.cpp')
-rw-r--r--src/cam/main.cpp65
1 files changed, 38 insertions, 27 deletions
diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 96f55831..f9a90672 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -112,7 +112,7 @@ int CamApp::parseOptions(int argc, char *argv[])
OptionsParser parser;
parser.addOption(OptCamera, OptionString,
"Specify which camera to operate on, by id or by index", "camera",
- ArgumentRequired, "camera");
+ ArgumentRequired, "camera", true);
parser.addOption(OptHelp, OptionNone, "Display this help message",
"help");
parser.addOption(OptInfo, OptionNone,
@@ -195,45 +195,52 @@ int CamApp::run()
}
}
- /* 2. Create the camera session. */
- std::unique_ptr<CameraSession> session;
+ /* 2. Create the camera sessions. */
+ std::vector<std::unique_ptr<CameraSession>> sessions;
if (options_.isSet(OptCamera)) {
- const OptionValue &camera = options_[OptCamera];
- session = std::make_unique<CameraSession>(cm_.get(),
- camera.toString(), 0,
- camera.children());
- if (!session->isValid()) {
- std::cout << "Failed to create camera session" << std::endl;
- return -EINVAL;
- }
+ unsigned int index = 0;
+
+ for (const OptionValue &camera : options_[OptCamera].toArray()) {
+ std::unique_ptr<CameraSession> session =
+ std::make_unique<CameraSession>(cm_.get(),
+ camera.toString(),
+ index,
+ camera.children());
+ if (!session->isValid()) {
+ std::cout << "Failed to create camera session" << std::endl;
+ return -EINVAL;
+ }
+
+ std::cout << "Using camera " << session->camera()->id()
+ << " as cam" << index << std::endl;
- std::cout << "Using camera " << session->camera()->id()
- << std::endl;
+ session->captureDone.connect(this, &CamApp::captureDone);
- session->captureDone.connect(this, &CamApp::captureDone);
+ sessions.push_back(std::move(session));
+ index++;
+ }
}
/* 3. Print camera information. */
if (options_.isSet(OptListControls) ||
options_.isSet(OptListProperties) ||
options_.isSet(OptInfo)) {
- if (!session) {
- std::cout << "Cannot print camera information without a camera"
- << std::endl;
- return -EINVAL;
+ for (const auto &session : sessions) {
+ if (options_.isSet(OptListControls))
+ session->listControls();
+ if (options_.isSet(OptListProperties))
+ session->listProperties();
+ if (options_.isSet(OptInfo))
+ session->infoConfiguration();
}
-
- if (options_.isSet(OptListControls))
- session->listControls();
- if (options_.isSet(OptListProperties))
- session->listProperties();
- if (options_.isSet(OptInfo))
- session->infoConfiguration();
}
/* 4. Start capture. */
- if (session && session->options().isSet(OptCapture)) {
+ for (const auto &session : sessions) {
+ if (!session->options().isSet(OptCapture))
+ continue;
+
ret = session->start();
if (ret) {
std::cout << "Failed to start camera session" << std::endl;
@@ -258,8 +265,12 @@ int CamApp::run()
loop_.exec();
/* 6. Stop capture. */
- if (session && session->options().isSet(OptCapture))
+ for (const auto &session : sessions) {
+ if (!session->options().isSet(OptCapture))
+ continue;
+
session->stop();
+ }
return 0;
}