From patchwork Thu Oct 31 11:02:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 21789 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C04D6C3237 for ; Thu, 31 Oct 2024 11:03:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B480B653A1; Thu, 31 Oct 2024 12:03:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="R2Jpz7qH"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9284160360 for ; Thu, 31 Oct 2024 12:03:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730372582; x=1761908582; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=r71tY1kky7c7QUn7paALy5OYGwmTrBBySp7QGVGFxh8=; b=R2Jpz7qHPSqZOmKw8mUleMy7Fb5jS0+S+oDWjoTMWs9rMa4/+W89Sb40 Guk+B3kUduUyMMvZoj3RoJaP0uZpFIZfaIXm/NSAvi8DzWsiEWrugQyzU 806AP7AdVa6tUE/Zfg17YVanSrSssxNnH0n+lnEoHwZToPn4EvUVXLA4x uMLXSLYkdRq46zlN+xt/qMfvq/I8h/1gyZzBX3+9tZg+qIGJlcft1nDrs iz9w8TbWPtd/dOdLU57CSHhKho18mRwcF+aP3pPM1mOc3Uemy+uZqR0fm w+te9gc5nM3vkGPGHR9X//EPys1NedSl9RnpKGVex9dv7pju2/zT0Asd2 Q==; X-CSE-ConnectionGUID: 96n/gjIPSLyrGfJi26JAhQ== X-CSE-MsgGUID: APVkSIx1QOW4LgkuCH5PYQ== X-IronPort-AV: E=McAfee;i="6700,10204,11241"; a="34033954" X-IronPort-AV: E=Sophos;i="6.11,247,1725346800"; d="scan'208";a="34033954" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2024 04:03:00 -0700 X-CSE-ConnectionGUID: cDWUeBNzSbmYPUCcpcGkow== X-CSE-MsgGUID: ncxumKjySnGl9PNBTJwMLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,247,1725346800"; d="scan'208";a="113446130" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.83.36]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2024 04:02:59 -0700 From: Stanislaw Gruszka To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2] qcam: Use pointer when choosing camera Date: Thu, 31 Oct 2024 12:02:56 +0100 Message-Id: <20241031110256.415079-1-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Signed-off-by: Laurent Pinchart Signed-off-by: Stanislaw Gruszka Tested-by: Kieran Bingham Reviewed-by: Kieran Bingham --- v2: - better error message when no cameras are present - use camera_->id() is switch button, missed in previous patch src/apps/qcam/main_window.cpp | 43 +++++++++++++++-------------------- 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 cam = chooseCamera(); - if (newCameraId.empty()) + if (!cam) return; - if (camera_ && newCameraId == camera_->id()) + if (camera_ && cam == camera_) return; - const std::shared_ptr &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 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(options_[OptCamera]); + std::string cameraName = static_cast(options_[OptCamera]); + camera_ = cm_->get(cameraName); + if (!camera_) + qInfo() << "Camera" << cameraName.c_str() << "not found"; } else { std::vector> 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 chooseCamera(); int openCamera(); int startCapture();