[PATCH v2] qcam: Automatically select the camera if only one is available

Stanislaw Gruszka stanislaw.gruszka at linux.intel.com
Sat Oct 19 12:09:25 CEST 2024


When only a single camera is available, showing the camera selection
dialog is unnecessary. It's better to automatically select the available
camera without prompting the user for input.

Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka at linux.intel.com>
---
v2:
- Avoid cameras().size() vs cameras()[0] race condition
- Update in code comment

 src/apps/qcam/main_window.cpp | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
index 5144c6b3..86ffa205 100644
--- a/src/apps/qcam/main_window.cpp
+++ b/src/apps/qcam/main_window.cpp
@@ -296,14 +296,23 @@ std::string MainWindow::chooseCamera()
 int MainWindow::openCamera()
 {
 	std::string cameraName;
+	int num = 0;
 
 	/*
-	 * Use the camera specified on the command line, if any, or display the
-	 * camera selection dialog box otherwise.
+	 * Use the camera specified on the command line, if any, or select the
+	 * only one available, otherwise display the camera selection dialog box.
 	 */
-	if (options_.isSet(OptCamera))
+	if (options_.isSet(OptCamera)) {
 		cameraName = static_cast<std::string>(options_[OptCamera]);
-	else
+	} else {
+		for (const auto &cam : cm_->cameras()) {
+			num++;
+			if (num > 1)
+				break;
+			cameraName = cam->id();
+		}
+	}
+	if (num > 1)
 		cameraName = chooseCamera();
 
 	if (cameraName == "")
-- 
2.43.0



More information about the libcamera-devel mailing list