From patchwork Thu May 11 22:48:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18619 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 4F9BDC32A5 for ; Thu, 11 May 2023 22:48:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8FF60633CE; Fri, 12 May 2023 00:48:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1683845321; bh=Xg9QLFlM9LIiUN/2yhjh8ehnqdh9TxE4uobTVMhhvZU=; 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=IeEpXdO8GJwifufKspv7nI+nXTSF9JxsYSbT10O1TxtzaHpeNwfqkqkU2b2rkaxEn z45McuBY7V3G5Q0DH1/ghHUlp1TDc/vra7Wqv2gGRA2OzTyGUGd8jrPGtgPiTpasFI Mb9WR3diI6FIQMCQD9JBJvr3L0CjCS/6cJ+1gHvdV44qVE7ZHqAsUUCS5A7EssGvqU uXzE17L76ussAsbhKQWBTwxauHh+INvILay5Lel4MvIjUghO3jKhXawich26yNOX8J qkJz9vKTr4uLMQNgLMxbh0XMxtpSKQvkIjegqS+g9ZL1GmSaT7qZXlDpCatZS/9Jh0 S4Keh6UhJNf3w== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E7539633BD for ; Fri, 12 May 2023 00:48:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZSrfl8e1"; 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 7C9B41583; Fri, 12 May 2023 00:48:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1683845309; bh=Xg9QLFlM9LIiUN/2yhjh8ehnqdh9TxE4uobTVMhhvZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZSrfl8e1sSaXbBIcUK7sldyNj4kfunmHGv/PfKkJ2rsBK3dUbWPSTuycW3gHayr1A tiovwtfQy99Y2C5y/cZKIsathS0N1yNhfOFug+29UuEtWgO17I692imQJpz4N8ZSEd NXTqv4cnn4UXXPl1+nhrch+HjuAJBc1g14JoPpHY= To: libcamera devel Date: Thu, 11 May 2023 23:48:30 +0100 Message-Id: <20230511224830.356416-8-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511224830.356416-1-kieran.bingham@ideasonboard.com> References: <20230511224830.356416-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/4] 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: George Kiagiadakis , Robert Mader , Wim Taymans 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. Signed-off-by: Kieran Bingham --- include/libcamera/internal/camera_manager.h | 3 +-- src/libcamera/camera_manager.cpp | 13 ++++++++----- src/libcamera/pipeline_handler.cpp | 12 ++++++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/libcamera/internal/camera_manager.h b/include/libcamera/internal/camera_manager.h index 8386e90e0f60..061d2c5083b0 100644 --- a/include/libcamera/internal/camera_manager.h +++ b/include/libcamera/internal/camera_manager.h @@ -29,8 +29,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 34f09a4d181b..df5fdede85da 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -15,7 +15,9 @@ #include #include +#include +#include "libcamera/internal/camera.h" #include "libcamera/internal/camera_manager.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,9 @@ void CameraManager::Private::addCamera(std::shared_ptr camera, } } + Camera::Private *data = camera->_d(); + auto devnums = data->properties_.get(properties::Devices).value_or(std::vector{}); + 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..0b5fac7ad113 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::Devices, devnums); + + manager_->_d()->addCamera(std::move(camera)); } /**