From patchwork Thu Jun 15 17:26:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18738 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 58F00C322E for ; Thu, 15 Jun 2023 17:26:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1F53A628B6; Thu, 15 Jun 2023 19:26:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686849979; bh=UWg16aKjq9hZguPIsJUHsMnOeEtA2mQX06lQp7MG3yM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Z9Fu+swT2kHbYB7AHCUwagI8XmRCnNPJ7LI/ZRAPvoOAsDnrh8kVBMS06wnsIrQqC h+uwoli3QZGf1nWXiU/MJ8AtGNgJyP3tzJ4O5scuSpcCKDlM6Q1WlInzc3mQUbCoKq bnBSDaGAQL0Oz0pa8qwuNv4JYyZAnU+6XACxrLWbjVsuQZu9NrSAQ5IkpaUxqGpTFz 67Y3j3iJBM5HmIUD/LWutPgas+msDX4OLOSC8jvruVIvcY51Sys5YtK839ki1CV+iw ainAol6NWsItFK8ieeezkgwb44TDYHYgtg8PY1X0XObc7Gejd8jUMApQ5DpM5tGxWC sNbNKbE9SmwjQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E705614FE for ; Thu, 15 Jun 2023 19:26:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cro3J0hD"; 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 3F8ACDA8; Thu, 15 Jun 2023 19:25:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686849944; bh=UWg16aKjq9hZguPIsJUHsMnOeEtA2mQX06lQp7MG3yM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cro3J0hDPoeVGlnB/8Mdoy0kZ9EOySQUzPfY74+12Z6vikDhVx5LSIuCR+VYanR/q IMaTuzxGqeiGUEXnXpg4VYzpM/n/WPXwdm9NjHj2acHEe78MTbwBtqiTTPVLcp+gf1 LH/rqH6YJlOKG2YOtDMFIEyMd47QjFL1y78AVpPo= To: libcamera devel Date: Thu, 15 Jun 2023 18:26:04 +0100 Message-Id: <20230615172608.378258-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> References: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/5] libcamera: internal: request: convert to pragma once 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 Cc: Jacopo Mondi , Ashok Sidipotu Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Remove the verbose #ifndef/#define/#endif pattern for maintaining header idempotency, and replace it with a simple #pragma once. This simplifies the headers, and prevents redundant changes when header files get moved. The internal/request.h was missed at the time of the original conversion. Update it. Fixes: df131ad08893 ("libcamera: internal: Convert to pragma once") Tested-by: Ashok Sidipotu Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Signed-off-by: Kieran Bingham --- include/libcamera/internal/request.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/request.h b/include/libcamera/internal/request.h index 8c92a27a95e5..3454cf5a72f5 100644 --- a/include/libcamera/internal/request.h +++ b/include/libcamera/internal/request.h @@ -4,8 +4,8 @@ * * request.h - Request class private data */ -#ifndef __LIBCAMERA_INTERNAL_REQUEST_H__ -#define __LIBCAMERA_INTERNAL_REQUEST_H__ + +#pragma once #include #include @@ -62,5 +62,3 @@ private: }; } /* namespace libcamera */ - -#endif /* __LIBCAMERA_INTERNAL_REQUEST_H__ */ From patchwork Thu Jun 15 17:26:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18739 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 B6295C322E for ; Thu, 15 Jun 2023 17:26:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9AE82628C5; Thu, 15 Jun 2023 19:26:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686849979; bh=ILfgxCfABmcZN1IjyphsLSa4qnildleu7G4z01OhYdk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ngmUa0p6RBRcCNzMgJaE4jt3bsjHjmXc4m7W16Viu0K9pZIEXxmhJZeyVUNYmFTBS nMG1LUUdCid/8DSo7L0g1PA9cBPrI8GTTq4gAWPS+WyDZZXe+u5AU/Y7ErlKK9JcnI Gab5G5YVpXdp5SC8mcobkuzxkPLqQKPbT/GG8KTBhn5fvKUYIyJKcc14qOkP9nP6T3 yljvS597ktbz+JPtCz/3tedz8KtdInaj1UCHORVKhg1S042QdS5uMA4EX6N0a+kdv+ KejJd6AYiS05AyhWVOy8g40G3l2yZD7ZY7ruoWePHqhwxCw90LhIvEgsEJ4NF1MC6t 6Mubcw6itwCag== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4C34D61E4F for ; Thu, 15 Jun 2023 19:26:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="q6+ZvJ4v"; 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 A5ABF547; Thu, 15 Jun 2023 19:25:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686849944; bh=ILfgxCfABmcZN1IjyphsLSa4qnildleu7G4z01OhYdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q6+ZvJ4vLcRwlLbmBqDQSK1zS3G4g4UcmaHob/KYJmgsnKVYolhSi8OG7mz3E6xQ8 w4CX/1pcYXArNZ2L2B6qh/HtQ0jKA3giVjY/pvO/nFQL4YE1SS3vktRFC5i1MZ8VPp AMfteKKc6dvElZzXYSysatwEXCdI+4mol8HRLr3Y= To: libcamera devel Date: Thu, 15 Jun 2023 18:26:05 +0100 Message-Id: <20230615172608.378258-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> References: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/5] libcamera: camera_manager: Move private implementation to internal 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 Cc: Jacopo Mondi , Ashok Sidipotu Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraManager makes use of the Extensible pattern to provide an internal private implementation that is not exposed in the public API. Move the Private declaration to an internal header to make it available from other internal components in preperation for reducing the surface area of the public interface of the CameraManager. Reviewed-by: Jacopo Mondi Tested-by: Ashok Sidipotu Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- v4 - Fix includes - Fix sort order of header in meson.build - Fix doxygen file references Signed-off-by: Kieran Bingham --- include/libcamera/internal/camera_manager.h | 70 +++++++++++++++++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/camera_manager.cpp | 59 +++-------------- 3 files changed, 80 insertions(+), 50 deletions(-) create mode 100644 include/libcamera/internal/camera_manager.h diff --git a/include/libcamera/internal/camera_manager.h b/include/libcamera/internal/camera_manager.h new file mode 100644 index 000000000000..96a83bd7ef3c --- /dev/null +++ b/include/libcamera/internal/camera_manager.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Ideas on Board Oy. + * + * camera_manager.h - Camera manager private data + */ + +#pragma once + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "libcamera/internal/device_enumerator.h" +#include "libcamera/internal/ipa_manager.h" +#include "libcamera/internal/process.h" + +namespace libcamera { + +class Camera; + +class CameraManager::Private : public Extensible::Private, public Thread +{ + LIBCAMERA_DECLARE_PUBLIC(CameraManager) + +public: + Private(); + + int start(); + void addCamera(std::shared_ptr camera, + const std::vector &devnums) LIBCAMERA_TSA_EXCLUDES(mutex_); + void removeCamera(Camera *camera) LIBCAMERA_TSA_EXCLUDES(mutex_); + + /* + * This mutex protects + * + * - initialized_ and status_ during initialization + * - cameras_ and camerasByDevnum_ after initialization + */ + mutable Mutex mutex_; + std::vector> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + std::map> camerasByDevnum_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + +protected: + void run() override; + +private: + int init(); + void createPipelineHandlers(); + void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_); + + ConditionVariable cv_; + bool initialized_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + int status_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + + std::unique_ptr enumerator_; + + IPAManager ipaManager_; + ProcessManager processManager_; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index d75088059996..4b2756a4a251 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -15,6 +15,7 @@ libcamera_internal_headers = files([ 'camera.h', 'camera_controls.h', 'camera_lens.h', + 'camera_manager.h', 'camera_sensor.h', 'camera_sensor_properties.h', 'control_serializer.h', diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index c1edefdad160..882b2d4b234c 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -5,27 +5,26 @@ * camera_manager.h - Camera management */ -#include - -#include - -#include +#include "libcamera/internal/camera_manager.h" #include -#include -#include #include +#include + #include "libcamera/internal/device_enumerator.h" -#include "libcamera/internal/ipa_manager.h" #include "libcamera/internal/pipeline_handler.h" -#include "libcamera/internal/process.h" /** - * \file camera_manager.h + * \file libcamera/camera_manager.h * \brief The camera manager */ +/** + * \file libcamera/internal/camera_manager.h + * \brief Internal camera manager support + */ + /** * \brief Top-level libcamera namespace */ @@ -33,46 +32,6 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Camera) -class CameraManager::Private : public Extensible::Private, public Thread -{ - LIBCAMERA_DECLARE_PUBLIC(CameraManager) - -public: - Private(); - - int start(); - void addCamera(std::shared_ptr camera, - const std::vector &devnums) LIBCAMERA_TSA_EXCLUDES(mutex_); - void removeCamera(Camera *camera) LIBCAMERA_TSA_EXCLUDES(mutex_); - - /* - * This mutex protects - * - * - initialized_ and status_ during initialization - * - cameras_ and camerasByDevnum_ after initialization - */ - mutable Mutex mutex_; - std::vector> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_); - std::map> camerasByDevnum_ LIBCAMERA_TSA_GUARDED_BY(mutex_); - -protected: - void run() override; - -private: - int init(); - void createPipelineHandlers(); - void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_); - - ConditionVariable cv_; - bool initialized_ LIBCAMERA_TSA_GUARDED_BY(mutex_); - int status_ LIBCAMERA_TSA_GUARDED_BY(mutex_); - - std::unique_ptr enumerator_; - - IPAManager ipaManager_; - ProcessManager processManager_; -}; - CameraManager::Private::Private() : initialized_(false) { From patchwork Thu Jun 15 17:26:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18740 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 5C149C3291 for ; Thu, 15 Jun 2023 17:26:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3E986628C8; Thu, 15 Jun 2023 19:26:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686849980; bh=3uM+FQeNtAq1HBah6XYx6pdCz2blzMPIpWIOXkCd/xA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=XYY9sgNnsCwY0W8dTNGSP1dpC57VVHXzF1bmSBRXQg8ARTJ0U8kw1i9gtAvKzlHGW fBVLwgdMW17iQ90xBQvB8woRIS2FAmfh6gqD25B7v7qR9Zj9G09r4qo1EBpaixkobm mSRbe92TCjDzA6d8LOIM9SNYlT5hBHflBxxPsNDbZi3ZXDtQ42/0+ctSeGmoP1BM0k Ne/boADgfGStWtsdkWPIkF86Mighs9GIHXPs2FVOuS7B+Z6X1OrJ0XJTHqgPYEqUlj 59OEi8B2u8WA5ifUOTDdj7DDSi56xbPqAJSbJeR+G1vOFR6YXYppkcBL7IbofW+RuD dw1FJvb+XqqZw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B40AF628BB for ; Thu, 15 Jun 2023 19:26:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nxbTnZHv"; 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 0C902DFB; Thu, 15 Jun 2023 19:25:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686849945; bh=3uM+FQeNtAq1HBah6XYx6pdCz2blzMPIpWIOXkCd/xA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nxbTnZHvksaynXnjA6fJhZ+p8gV9n6Q4dTEPT645OKONdCbyGST7rlyYi6WMIhy6R EMsWgwvzYgDhxBTicraLfKOO99CmpEYY4DgJPye8P4AbaRnIHwsH/ciQa9IXMFOglx VvNj5HDCxb/AZmucdOluM6ipv0Dq+Mr+lj13eGNk= To: libcamera devel Date: Thu, 15 Jun 2023 18:26:06 +0100 Message-Id: <20230615172608.378258-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> References: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/5] libcamera: camera_manager: Move {add, remove}Camera to internal 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 Cc: Jacopo Mondi , Ashok Sidipotu Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraManager exposes addCamera and removeCamera as public API calls, while they should never be called from an application. These calls are only expected to be used by PipelineHandlers to update the CameraManager that a new Camera has been created and allow the Camera Manager to expose it to applications. Remove the public calls and update the private implementations such that they can be used directly by the PipelineHandler through the internal CameraManager::Private provided by the Extensible class. Reviewed-by: Jacopo Mondi Tested-by: Ashok Sidipotu Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- include/libcamera/camera_manager.h | 4 - include/libcamera/internal/camera_manager.h | 2 +- src/libcamera/camera_manager.cpp | 87 +++++++++------------ src/libcamera/pipeline_handler.cpp | 6 +- 4 files changed, 43 insertions(+), 56 deletions(-) diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 4b1fb7568e83..9767acc42c89 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -34,10 +34,6 @@ public: std::shared_ptr get(const std::string &id); std::shared_ptr get(dev_t devnum); - void addCamera(std::shared_ptr camera, - const std::vector &devnums); - void removeCamera(std::shared_ptr camera); - static const std::string &version() { return version_; } Signal> cameraAdded; diff --git a/include/libcamera/internal/camera_manager.h b/include/libcamera/internal/camera_manager.h index 96a83bd7ef3c..84aac499ea13 100644 --- a/include/libcamera/internal/camera_manager.h +++ b/include/libcamera/internal/camera_manager.h @@ -37,7 +37,7 @@ public: int start(); void addCamera(std::shared_ptr camera, const std::vector &devnums) LIBCAMERA_TSA_EXCLUDES(mutex_); - void removeCamera(Camera *camera) LIBCAMERA_TSA_EXCLUDES(mutex_); + void removeCamera(std::shared_ptr camera) LIBCAMERA_TSA_EXCLUDES(mutex_); /* * This mutex protects diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 882b2d4b234c..cafd7bce574e 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -148,9 +148,25 @@ void CameraManager::Private::cleanup() enumerator_.reset(nullptr); } +/** + * \brief Add a camera to the camera manager + * \param[in] camera The camera to be added + * \param[in] devnums The device numbers to associate with \a camera + * + * This function is called by pipeline handlers to register the cameras they + * handle with the camera manager. Registered cameras are immediately made + * available to the system. + * + * \a devnums are used by the V4L2 compatibility layer to map V4L2 device nodes + * to Camera instances. + * + * \context This function shall be called from the CameraManager thread. + */ void CameraManager::Private::addCamera(std::shared_ptr camera, const std::vector &devnums) { + ASSERT(Thread::current() == this); + MutexLocker locker(mutex_); for (const std::shared_ptr &c : cameras_) { @@ -167,15 +183,31 @@ void CameraManager::Private::addCamera(std::shared_ptr 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(); + o->cameraAdded.emit(cameras_[index]); } -void CameraManager::Private::removeCamera(Camera *camera) +/** + * \brief Remove a camera from the camera manager + * \param[in] camera The camera to be removed + * + * This function is called by pipeline handlers to unregister cameras from the + * camera manager. Unregistered cameras won't be reported anymore by the + * cameras() and get() calls, but references may still exist in applications. + * + * \context This function shall be called from the CameraManager thread. + */ +void CameraManager::Private::removeCamera(std::shared_ptr camera) { + ASSERT(Thread::current() == this); + MutexLocker locker(mutex_); auto iter = std::find_if(cameras_.begin(), cameras_.end(), [camera](std::shared_ptr &c) { - return c.get() == camera; + return c.get() == camera.get(); }); if (iter == cameras_.end()) return; @@ -185,12 +217,16 @@ void CameraManager::Private::removeCamera(Camera *camera) auto iter_d = std::find_if(camerasByDevnum_.begin(), camerasByDevnum_.end(), [camera](const std::pair> &p) { - return p.second.lock().get() == camera; + 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 */ + CameraManager *const o = LIBCAMERA_O_PTR(); + o->cameraRemoved.emit(camera); } /** @@ -383,51 +419,6 @@ std::shared_ptr CameraManager::get(dev_t devnum) * perform any blocking operation. */ -/** - * \brief Add a camera to the camera manager - * \param[in] camera The camera to be added - * \param[in] devnums The device numbers to associate with \a camera - * - * This function is called by pipeline handlers to register the cameras they - * handle with the camera manager. Registered cameras are immediately made - * available to the system. - * - * \a devnums are used by the V4L2 compatibility layer to map V4L2 device nodes - * to Camera instances. - * - * \context This function shall be called from the CameraManager thread. - */ -void CameraManager::addCamera(std::shared_ptr camera, - const std::vector &devnums) -{ - Private *const d = _d(); - - ASSERT(Thread::current() == d); - - d->addCamera(camera, devnums); - cameraAdded.emit(camera); -} - -/** - * \brief Remove a camera from the camera manager - * \param[in] camera The camera to be removed - * - * This function is called by pipeline handlers to unregister cameras from the - * camera manager. Unregistered cameras won't be reported anymore by the - * cameras() and get() calls, but references may still exist in applications. - * - * \context This function shall be called from the CameraManager thread. - */ -void CameraManager::removeCamera(std::shared_ptr camera) -{ - Private *const d = _d(); - - ASSERT(Thread::current() == d); - - d->removeCamera(camera.get()); - cameraRemoved.emit(camera); -} - /** * \fn const std::string &CameraManager::version() * \brief Retrieve the libcamera version string diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index f72613b8e515..49092ea88a58 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -16,10 +16,10 @@ #include #include -#include #include #include "libcamera/internal/camera.h" +#include "libcamera/internal/camera_manager.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/framebuffer.h" #include "libcamera/internal/media_device.h" @@ -624,7 +624,7 @@ void PipelineHandler::registerCamera(std::shared_ptr camera) } } - manager_->addCamera(std::move(camera), devnums); + manager_->_d()->addCamera(std::move(camera), devnums); } /** @@ -691,7 +691,7 @@ void PipelineHandler::disconnect() continue; camera->disconnect(); - manager_->removeCamera(camera); + manager_->_d()->removeCamera(camera); } } From patchwork Thu Jun 15 17:26:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18741 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 CAAB7C32AA for ; Thu, 15 Jun 2023 17:26:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1248F628C2; Thu, 15 Jun 2023 19:26:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686849981; bh=0R5YKzYC5n93O77+U5+2ee2mRlkQTCDfBakiwliYpfs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lmpvMS1kRWf3c7Ezbm6il4ztFwlGiTMW1x2xVn+00RFCIPCGnsStQC9wzDSd1co/7 yQFsLuwvJePxwoR57s6eGd0P8yWnwEcJDOHvCJDhLU5PZV2OL1Sjf2TmSbJ49rjt1k hmtKx5Ir3AmfKOwOAfceaK1+deGAdM5zjxg4XpOGhjK/khjm8o6JHfu8omIJJG9vb0 beFf2IYOCzVYoCjnN3+4ebanGnYOqr3sABVvZCAfq/mAiPWs046zv1/G4muIIqEg2L Y2glQO2D0u3MyMplNJ1a7FCuEhzrCHTedJ0y9Cq6B5s1nvkbIiY5ahwPNLYzIW48xd Z4hLkjpc/v7ww== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E351628B5 for ; Thu, 15 Jun 2023 19:26:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HAYBwW6f"; 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 74C58DA8; Thu, 15 Jun 2023 19:25:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686849945; bh=0R5YKzYC5n93O77+U5+2ee2mRlkQTCDfBakiwliYpfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HAYBwW6fPsah4T8Omdhi48ybmmp4aPe/5NGeMgGP1Vl/uZGzRnH/Q3VNX5BGWKtWo iufpY8oqmZlkbFbtZcrtaZN/3F/JCLf8QbUGGGoFliccryYXkLPQMwZQm1BU5xc/mR C/kP+gTzvYDozJmfRvx+dP6Wc9a3ZyyX1v2AT14c= To: libcamera devel Date: Thu, 15 Jun 2023 18:26:07 +0100 Message-Id: <20230615172608.378258-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> References: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 4/5] libcamera: properties: Provide a Devices camera property 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 Cc: Jacopo Mondi , Ashok Sidipotu Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide a new Camera property that allows pipeline handlers to list any kernel device used to operate the camera. This allows other frameworks and daemons such as PipeWire to better understand the resources consumed by a Camera and consider ignoring those resources when enumerating camera devices on a system. Tested-by: Ashok Sidipotu Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- v4: - Report that different cameras may report identical devices - Rename to SystemDevices Signed-off-by: Kieran Bingham --- src/libcamera/property_ids.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libcamera/property_ids.yaml b/src/libcamera/property_ids.yaml index cb55e0ed2283..ef1dfd322db1 100644 --- a/src/libcamera/property_ids.yaml +++ b/src/libcamera/property_ids.yaml @@ -690,6 +690,15 @@ controls: that is twice that of the full resolution mode. This value will be valid after the configure method has returned successfully. + - SystemDevices: + type: int64_t + size: [n] + description: | + A list of integer values of type dev_t denoting major and minor device + number of the underlying devices used in the operation of this camera. + + Different cameras may report identical devices. + # ---------------------------------------------------------------------------- # Draft properties section From patchwork Thu Jun 15 17:26:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18742 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 1E765C322E for ; Thu, 15 Jun 2023 17:26:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B6077628C3; Thu, 15 Jun 2023 19:26:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686849981; bh=Kym629P17wr79W0pAx4/QGQmk2VFgSNpYCF46Cg/OMk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=qJEqgDISuW44Z4TId2tkGK9FAUxqiC/xGztHrkk/zDuTAeXm6aL42sKr3u8kkTYkd NnVAqnu84Ydx2j7v7jBD3C/7ylFdBAhk6x7E0u3WlS78l2YS07RMkBK3DBm8xT3G8i +joebCpWPlKB2a11fel+gTLREw5TPlPxYiYtR8TDcEreQe0+XEq5zoFt7XLVt0Sttu gtPXtv0NDsrocyXrmEhErDEpq6eBHWkmhgp5D52N/fFCIsQTGCjz7lrA0aC09S6RMo MwNmVRTQh7252zPGqcgKxGa3IZ0V+lan/0eelO/EjIOAjgl7Xnf7EJjGdfWweznOvR SEyjs4qY2OAAA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 87E96628AC for ; Thu, 15 Jun 2023 19:26:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ib7+rZqn"; 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 D9D5F547; Thu, 15 Jun 2023 19:25:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686849946; bh=Kym629P17wr79W0pAx4/QGQmk2VFgSNpYCF46Cg/OMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ib7+rZqndENW9q9w4L+iUjoz0H9KLlGP0/zz4oT9R8YFHAJddzslEv+w8e7PCEnRc C4FWbKQXgXR51T3HOzvHAwEYCgIqGqxq69WiWxdOJppTRHVSwKwC7cPslhAI1JFNKd 3VZGeDzTWqNFFsfWcZGHIeqlrE14X5DdIL71uIP8= To: libcamera devel Date: Thu, 15 Jun 2023 18:26:08 +0100 Message-Id: <20230615172608.378258-6-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> References: <20230615172608.378258-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/5] libcamera: pipeline: Register device numbers with camera 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 Cc: Jacopo Mondi , Ashok Sidipotu Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Register the identified device numbers with each camera as the Devices property. This facilitates camera daemons or other systems to identify which devices are being managed by libcamera, and can prevent duplication of camera resources. As the Devices property now provides this list of devices, use it directly from within the CameraManager when adding a Camera rather than passing it through the internal API. Tested-by: Ashok Sidipotu Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Signed-off-by: Kieran Bingham --- v4 - Rename property Signed-off-by: Kieran Bingham --- include/libcamera/internal/camera_manager.h | 3 +-- src/libcamera/camera_manager.cpp | 14 +++++++++----- src/libcamera/pipeline_handler.cpp | 12 ++++++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/libcamera/internal/camera_manager.h b/include/libcamera/internal/camera_manager.h index 84aac499ea13..cdf009a9c626 100644 --- a/include/libcamera/internal/camera_manager.h +++ b/include/libcamera/internal/camera_manager.h @@ -35,8 +35,7 @@ public: Private(); int start(); - void addCamera(std::shared_ptr camera, - const std::vector &devnums) LIBCAMERA_TSA_EXCLUDES(mutex_); + void addCamera(std::shared_ptr camera) LIBCAMERA_TSA_EXCLUDES(mutex_); void removeCamera(std::shared_ptr camera) LIBCAMERA_TSA_EXCLUDES(mutex_); /* diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index cafd7bce574e..31d45c42fde0 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -11,7 +11,9 @@ #include #include +#include +#include "libcamera/internal/camera.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/pipeline_handler.h" @@ -151,19 +153,17 @@ void CameraManager::Private::cleanup() /** * \brief Add a camera to the camera manager * \param[in] camera The camera to be added - * \param[in] devnums The device numbers to associate with \a camera * * This function is called by pipeline handlers to register the cameras they * handle with the camera manager. Registered cameras are immediately made * available to the system. * - * \a devnums are used by the V4L2 compatibility layer to map V4L2 device nodes - * to Camera instances. + * Device numbers from the Devices property are used by the V4L2 compatibility + * layer to map V4L2 device nodes to Camera instances. * * \context This function shall be called from the CameraManager thread. */ -void CameraManager::Private::addCamera(std::shared_ptr camera, - const std::vector &devnums) +void CameraManager::Private::addCamera(std::shared_ptr camera) { ASSERT(Thread::current() == this); @@ -178,6 +178,10 @@ 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; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 49092ea88a58..9c74c6cfda70 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "libcamera/internal/camera.h" #include "libcamera/internal/camera_manager.h" @@ -612,7 +613,7 @@ void PipelineHandler::registerCamera(std::shared_ptr camera) * Walk the entity list and map the devnums of all capture video nodes * to the camera. */ - std::vector devnums; + std::vector devnums; for (const std::shared_ptr &media : mediaDevices_) { for (const MediaEntity *entity : media->entities()) { if (entity->pads().size() == 1 && @@ -624,7 +625,14 @@ void PipelineHandler::registerCamera(std::shared_ptr camera) } } - manager_->_d()->addCamera(std::move(camera), devnums); + /* + * Store the associated devices as a property of the camera to allow + * systems to identify which devices are managed by libcamera. + */ + Camera::Private *data = camera->_d(); + data->properties_.set(properties::SystemDevices, devnums); + + manager_->_d()->addCamera(std::move(camera)); } /**