From patchwork Tue Oct 22 10:24:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 21735 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 49F6EC3274 for ; Tue, 22 Oct 2024 10:24:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2BF3165395; Tue, 22 Oct 2024 12:24:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Rhddeevs"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D8368633C8 for ; Tue, 22 Oct 2024 12:24:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729592693; x=1761128693; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=N0KmeFd/c0JG2UcTnQx/jooqGI3qzlGqZFTWQdNB7nc=; b=RhddeevsiWNprIkcavdG/x8t7r954IHZ9q/4zSrFtMtEyprBD4UmmTCC mZGndhrdfe2k6TSzdxR6IemTU6utT5NkoNswihe2mYJ1Mlf9IFizk5c4L yfUeiSttgzWleBjXH7TBRwrFWDyJZTy3tqdQ+xZBbXpxo/O1qB0U9UDp9 hoKxXOYv4qn1AzuQQe+mtpe/AE2nmACtLBtdVqVG0dmAQVuYAzLku+dWh 9Z2R0SCFhgZMMAEdAMSKlck6UEch82rbMa/Ybhljafs+oed7NWUnwb8n4 weKP05Iph1+kmJsUs4Hh8v38IVg7TO76qFijHBsLLh6G14gPUbWqQmKTU A==; X-CSE-ConnectionGUID: P+WyvlgbSj27xb7McJ3QiQ== X-CSE-MsgGUID: SWlBIiXWQbKutjis2O8iSA== X-IronPort-AV: E=McAfee;i="6700,10204,11232"; a="29220511" X-IronPort-AV: E=Sophos;i="6.11,222,1725346800"; d="scan'208";a="29220511" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Oct 2024 03:24:51 -0700 X-CSE-ConnectionGUID: yRc7MSNdQ6qIe16rAQm2ig== X-CSE-MsgGUID: nD1UBkz9Q/6aksrMzFymeQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,222,1725346800"; d="scan'208";a="79765308" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.97.183]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Oct 2024 03:24:50 -0700 From: Stanislaw Gruszka To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3] qcam: Automatically select the camera if only one is available Date: Tue, 22 Oct 2024 12:24:48 +0200 Message-Id: <20241022102448.229381-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" 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. Co-developed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart Signed-off-by: Stanislaw Gruszka Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- v2: - Avoid cm_->cameras().size() vs cm_->cameras()[0] race condition using custom loop. - Update in code comment v3: - Avoid TOCTOU race using shared_ptr vector copy - Use Laurent comment wording src/apps/qcam/main_window.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp index 5144c6b3..de487672 100644 --- a/src/apps/qcam/main_window.cpp +++ b/src/apps/qcam/main_window.cpp @@ -298,13 +298,19 @@ int MainWindow::openCamera() std::string cameraName; /* - * Use the camera specified on the command line, if any, or display the - * camera selection dialog box otherwise. + * 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)) + if (options_.isSet(OptCamera)) { cameraName = static_cast(options_[OptCamera]); - else - cameraName = chooseCamera(); + } else { + std::vector> cameras = cm_->cameras(); + if (cameras.size() == 1) + cameraName = cameras[0]->id(); + else + cameraName = chooseCamera(); + } if (cameraName == "") return -EINVAL;