From patchwork Tue Jul 4 22:57:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18785 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 BFEABC3240 for ; Tue, 4 Jul 2023 22:58:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6E899628BD; Wed, 5 Jul 2023 00:58:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1688511529; bh=kV4tfNggj3HKOynGd/A+ySk8XG12Kz098H+dD3UmRJw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=cxj1QlEJL/pCnSGJF1l6uqwMjk3x80NAmihlM1Td9Q3uzBSPHIbpQRyYRoRDNQH2J MLhShU0BqIBYZMUOt1bEX8UbgC92JL8r398RVMa5aN+rzrCnqgolcaS0x3pUyg9e6l seEgmENYEPHgr4gelLk0nY0j4phPFhtkjQ8ZDPAdzrQaY2wCQVMUSXVo9dGZL+iqxm uGb4OR/6jjGjXmCfBfzSROo4DDczx/rZnbEoj+CMsFt2egozib6RNbArMfA3blFG5w 4jMcQVROfj0eehuy50imwEDa1CadN/C7ek1JFXwl+NBL/d5qYvDhpHYQS97fowi73P gkgFYj+TWrqJw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E6B99628BB for ; Wed, 5 Jul 2023 00:58:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MStTEzH/"; dkim-atps=neutral Received: from Monstersaurus.local (aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net [82.37.23.78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 37A0C1B6D; Wed, 5 Jul 2023 00:58:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1688511482; bh=kV4tfNggj3HKOynGd/A+ySk8XG12Kz098H+dD3UmRJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MStTEzH/rKEjSX7IeEPo6fJaO5DSeWe11EzBeG1FReRMCcijMJPMTx80+ALnWSeKi s0uuDDrOUarn505yMprmdDXHoW8p1BWYKIdiDVc3unt5Q38+jDkkp2fG8Nd5eads+/ 1rL6Elpj/X05GJIMVSWHpoi7cnAKh16aw8KKhoTE= To: libcamera devel Date: Tue, 4 Jul 2023 23:57:45 +0100 Message-Id: <20230704225746.3838484-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230704225746.3838484-1-kieran.bingham@ideasonboard.com> References: <20230704225746.3838484-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] v4l2: Use SystemDevices properties to identify cameras 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: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraManager->get(dev_t) helper was implemented only to support the V4L2 Adaptation layer, and has been deprecated now that a new camera property - SystemDevices has been introduced. Rework the implementation of getCameraIndex() to use the SystemDevices property and remove reliance on the now deprecated call. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/v4l2/v4l2_compat_manager.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index 0f7575c54b22..948dadad646d 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "v4l2_camera_file.h" @@ -113,14 +114,32 @@ int V4L2CompatManager::getCameraIndex(int fd) if (ret < 0) return -1; - std::shared_ptr target = cm_->get(statbuf.st_rdev); - if (!target) - return -1; + const dev_t devnum = statbuf.st_rdev; + /* + * Iterate each known camera and identify if it reports this nodes + * device number in its list of SystemDevices. + */ auto cameras = cm_->cameras(); for (auto [index, camera] : utils::enumerate(cameras)) { - if (camera == target) - return index; + Span devices = camera->properties() + .get(properties::SystemDevices) + .value_or(Span{}); + + /* + * While there may be multiple Cameras that could reference the + * same device node, we take a first match as a best effort for + * now. + * + * \todo Consider reworking the V4L2 adaptation layer to stop + * trying to map video nodes directly to a camera and instead + * hide all devices that may be used by libcamera and expose a + * consistent 1:1 mapping with each Camera instance. + */ + for (const int64_t dev : devices) { + if (dev == static_cast(devnum)) + return index; + } } return -1; From patchwork Tue Jul 4 22:57:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18786 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 EF95CBE175 for ; Tue, 4 Jul 2023 22:58:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E66A761E38; Wed, 5 Jul 2023 00:58:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1688511529; bh=vTK6gpR6kJ2fmaNAiZ3z+mcXUv32gnNmX7YfQzHNW3Y=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=vikdgP9Lxc7fjXp7wAfx/dSmFF2xYafqBtM6VF0nGpvnTmu07PQl7taTUuJWkhTCp sRgJ7TQasX/DCQZrxchtonlBwXcdMXImEzV5CkKY0R5gMNv/XOn+6+GoQ5jTvSyiF4 gQGi5EyuOUlbsplgthPSLsjWne0Voc1ySsdfwmHZmGoJFFP8rAyVPJCEwHsYeQyklM n/1ysUjZixe4ioI1fnfsGq1MsDfEThuc2Bftppp8D+DM2Lfc6G81l+SNG5DrSSRDPp kSBuPnlv6comDDoyweQAXVmXNAMBwp58d+Rtdjg8ZImo6Fd2pxDKo0zftXi3lEkivd 7Bf3v//l6eonA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06FC5628C0 for ; Wed, 5 Jul 2023 00:58:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GPadJYxG"; dkim-atps=neutral Received: from Monstersaurus.local (aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net [82.37.23.78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7A7442098; Wed, 5 Jul 2023 00:58:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1688511482; bh=vTK6gpR6kJ2fmaNAiZ3z+mcXUv32gnNmX7YfQzHNW3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GPadJYxG9tDByQYeteG7c+R07x3KkDS45GDv/DDKX1gLfHCHE60YQl0x/hqyvh/xX 1tiyzzPZdfduK/Ga9oLRKvcH5NE/gLd6cm2N27ODCh3uYou63lMXVXKUvjYXkgRQAK G4TfaiqdkUQ8YiQrG+B5GHMT81K9Qh7fa1MCVg3I= To: libcamera devel Date: Tue, 4 Jul 2023 23:57:46 +0100 Message-Id: <20230704225746.3838484-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230704225746.3838484-1-kieran.bingham@ideasonboard.com> References: <20230704225746.3838484-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] libcamera: CameraManager: Remove ::get(dev_t) 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: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraManager::get(dev_t) implementation was provided only for the V4L2 Adaptation layer. This has now been replaced with the use of the public SystemDevices property. Remove the deprecated function entirely, along with the camerasByDevnum_ map which was only used to support this functionality. This is a clear (and intentional) breakage in both the API and ABI. Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- include/libcamera/camera_manager.h | 1 - include/libcamera/internal/camera_manager.h | 3 +- src/libcamera/camera_manager.cpp | 42 --------------------- 3 files changed, 1 insertion(+), 45 deletions(-) diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 9767acc42c89..1a891cacf26a 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -32,7 +32,6 @@ public: std::vector> cameras() const; std::shared_ptr get(const std::string &id); - std::shared_ptr get(dev_t devnum); static const std::string &version() { return version_; } diff --git a/include/libcamera/internal/camera_manager.h b/include/libcamera/internal/camera_manager.h index e4f5aaf4ec6d..33ebe0699fdf 100644 --- a/include/libcamera/internal/camera_manager.h +++ b/include/libcamera/internal/camera_manager.h @@ -50,11 +50,10 @@ private: * This mutex protects * * - initialized_ and status_ during initialization - * - cameras_ and camerasByDevnum_ after initialization + * - cameras_ after initialization */ mutable Mutex mutex_; std::vector> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_); - std::map> camerasByDevnum_ LIBCAMERA_TSA_GUARDED_BY(mutex_); ConditionVariable cv_; bool initialized_ LIBCAMERA_TSA_GUARDED_BY(mutex_); diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 7c65bb99e797..355f3adad68f 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -178,15 +178,9 @@ void CameraManager::Private::addCamera(std::shared_ptr camera) } } - auto devnums = camera->properties() - .get(properties::SystemDevices) - .value_or(Span{}); - cameras_.push_back(std::move(camera)); unsigned int index = cameras_.size() - 1; - for (dev_t devnum : devnums) - camerasByDevnum_[devnum] = cameras_[index]; /* Report the addition to the public signal */ CameraManager *const o = LIBCAMERA_O_PTR(); @@ -219,13 +213,6 @@ void CameraManager::Private::removeCamera(std::shared_ptr camera) LOG(Camera, Debug) << "Unregistering camera '" << camera->id() << "'"; - auto iter_d = std::find_if(camerasByDevnum_.begin(), camerasByDevnum_.end(), - [camera](const std::pair> &p) { - return p.second.lock().get() == camera.get(); - }); - if (iter_d != camerasByDevnum_.end()) - camerasByDevnum_.erase(iter_d); - cameras_.erase(iter); /* Report the removal to the public signal */ @@ -366,35 +353,6 @@ std::shared_ptr CameraManager::get(const std::string &id) return nullptr; } -/** - * \brief Retrieve a camera based on device number - * \param[in] devnum Device number of camera to get - * - * This function is meant solely for the use of the V4L2 compatibility - * layer, to map device nodes to Camera instances. Applications shall - * not use it and shall instead retrieve cameras by name. - * - * Before calling this function the caller is responsible for ensuring that - * the camera manager is running. - * - * \context This function is \threadsafe. - * - * \return Shared pointer to Camera object, which is empty if the camera is - * not found - */ -std::shared_ptr CameraManager::get(dev_t devnum) -{ - Private *const d = _d(); - - MutexLocker locker(d->mutex_); - - auto iter = d->camerasByDevnum_.find(devnum); - if (iter == d->camerasByDevnum_.end()) - return nullptr; - - return iter->second.lock(); -} - /** * \var CameraManager::cameraAdded * \brief Notify of a new camera added to the system