diff options
author | Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> | 2024-10-31 12:02:56 +0100 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2024-11-29 22:13:20 +0000 |
commit | a43ea7ff70e332ffe6b852a0aaeeb9aa877663cf (patch) | |
tree | ea4d2cc38870d0565469e50db9a92a11e10f16af /src/apps | |
parent | 1a2be886c08aea0e97da9b44bda639b59a2cd036 (diff) |
qcam: Use pointer when choosing camera
In order to remove redundant camera ID lookups and comparisons switch
to pointer-based checks when choosing and switching cameras.
Co-developed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/apps')
-rw-r--r-- | src/apps/qcam/main_window.cpp | 43 | ||||
-rw-r--r-- | src/apps/qcam/main_window.h | 2 |
2 files changed, 19 insertions, 26 deletions
diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp index de487672..3880a846 100644 --- a/src/apps/qcam/main_window.cpp +++ b/src/apps/qcam/main_window.cpp @@ -251,16 +251,14 @@ void MainWindow::updateTitle() void MainWindow::switchCamera() { /* Get and acquire the new camera. */ - std::string newCameraId = chooseCamera(); + std::shared_ptr<Camera> cam = chooseCamera(); - if (newCameraId.empty()) + if (!cam) return; - if (camera_ && newCameraId == camera_->id()) + if (camera_ && cam == camera_) return; - const std::shared_ptr<Camera> &cam = cm_->get(newCameraId); - if (cam->acquire()) { qInfo() << "Failed to acquire camera" << cam->id().c_str(); return; @@ -282,46 +280,41 @@ void MainWindow::switchCamera() startStopAction_->setChecked(true); /* Display the current cameraId in the toolbar .*/ - cameraSelectButton_->setText(QString::fromStdString(newCameraId)); + cameraSelectButton_->setText(QString::fromStdString(cam->id())); } -std::string MainWindow::chooseCamera() +std::shared_ptr<Camera> MainWindow::chooseCamera() { if (cameraSelectorDialog_->exec() != QDialog::Accepted) - return std::string(); + return {}; - return cameraSelectorDialog_->getCameraId(); + std::string id = cameraSelectorDialog_->getCameraId(); + return cm_->get(id); } int MainWindow::openCamera() { - std::string cameraName; - /* * If a camera is specified on the command line, get it. Otherwise, if * only one camera is available, pick it automatically, else, display * the selector dialog box. */ if (options_.isSet(OptCamera)) { - cameraName = static_cast<std::string>(options_[OptCamera]); + std::string cameraName = static_cast<std::string>(options_[OptCamera]); + camera_ = cm_->get(cameraName); + if (!camera_) + qInfo() << "Camera" << cameraName.c_str() << "not found"; } else { std::vector<std::shared_ptr<Camera>> cameras = cm_->cameras(); - if (cameras.size() == 1) - cameraName = cameras[0]->id(); - else - cameraName = chooseCamera(); + camera_ = (cameras.size() == 1) ? cameras[0] : chooseCamera(); + if (!camera_) + qInfo() << "No camera detected"; } - if (cameraName == "") - return -EINVAL; - - /* Get and acquire the camera. */ - camera_ = cm_->get(cameraName); - if (!camera_) { - qInfo() << "Camera" << cameraName.c_str() << "not found"; + if (!camera_) return -ENODEV; - } + /* Acquire the camera. */ if (camera_->acquire()) { qInfo() << "Failed to acquire camera"; camera_.reset(); @@ -329,7 +322,7 @@ int MainWindow::openCamera() } /* Set the camera switch button with the currently selected Camera id. */ - cameraSelectButton_->setText(QString::fromStdString(cameraName)); + cameraSelectButton_->setText(QString::fromStdString(camera_->id())); return 0; } diff --git a/src/apps/qcam/main_window.h b/src/apps/qcam/main_window.h index 4cead734..81fcf915 100644 --- a/src/apps/qcam/main_window.h +++ b/src/apps/qcam/main_window.h @@ -73,7 +73,7 @@ private Q_SLOTS: private: int createToolbars(); - std::string chooseCamera(); + std::shared_ptr<libcamera::Camera> chooseCamera(); int openCamera(); int startCapture(); |