From patchwork Wed Oct 30 07:17:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 21773 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 1ED19C3237 for ; Wed, 30 Oct 2024 07:17:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C521D65399; Wed, 30 Oct 2024 08:17:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Y5Fxy5iB"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 00F816039B for ; Wed, 30 Oct 2024 08:17:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730272665; x=1761808665; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=GdkHhxJ9pSwiYC8aUshBpjd13h+1QlYUdBnMv0VhIF4=; b=Y5Fxy5iBQP5eJ/PHG6XxcOxwlgLywgdP+/LJsCChkvd4NGRGwdIcku0V BcgD7uu9FrMpVgtc6FFmqzaaC6cJwzr5nm6nAxYdtfq0gW93R5+J0ERbS Dn3OBnRQ69kKAxsTvlVicEjlvfOGbBgKuNsKdyons5hx9JrJ3LMJmKagA Sw9pg+n9iAJjUr4ERElysc5n3BNG1M3spucfFBgUBY1jazOg7XGpmyiRg d4Ju33PwG+t4cbLLq99oZIoxczAYOPmcYUJiLrJkoRYBEAyfYZDVWeVDv FIExu+TBmMnuzQkb+4TtkEhhv/7kqkbKKcFjF9TeisYPk4r8gKMzE5jgJ A==; X-CSE-ConnectionGUID: DeMrAsRLSOqCnhU4k2c++w== X-CSE-MsgGUID: f/pRUTd2RfC+woa692aIMw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30104973" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30104973" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2024 00:17:42 -0700 X-CSE-ConnectionGUID: DjZ5dzNjRAC0NwOKsxQB/A== X-CSE-MsgGUID: SHoGEl5gQnettRZ+3Hrqyg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,244,1725346800"; d="scan'208";a="86780055" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.118.67]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2024 00:17:42 -0700 From: Stanislaw Gruszka To: libcamera-devel@lists.libcamera.org Subject: [PATCH] qcam: Use pointer when choosing camera Date: Wed, 30 Oct 2024 08:17:39 +0100 Message-Id: <20241030071739.271004-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 --- src/apps/qcam/main_window.cpp | 30 +++++++++++++----------------- src/apps/qcam/main_window.h | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp index de487672..e0bbcc75 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,20 +280,21 @@ 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; + std::string cameraName = ""; /* * If a camera is specified on the command line, get it. Otherwise, if @@ -304,24 +303,21 @@ int MainWindow::openCamera() */ if (options_.isSet(OptCamera)) { cameraName = static_cast(options_[OptCamera]); + camera_ = cm_->get(cameraName); } else { std::vector> cameras = cm_->cameras(); if (cameras.size() == 1) - cameraName = cameras[0]->id(); + camera_ = cameras[0]; else - cameraName = chooseCamera(); + camera_ = chooseCamera(); } - if (cameraName == "") - return -EINVAL; - - /* Get and acquire the camera. */ - camera_ = cm_->get(cameraName); if (!camera_) { qInfo() << "Camera" << cameraName.c_str() << "not found"; return -ENODEV; } + /* Acquire the camera. */ if (camera_->acquire()) { qInfo() << "Failed to acquire camera"; camera_.reset(); 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();