From patchwork Mon May 15 12:45:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18634 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 C5855C32A5 for ; Mon, 15 May 2023 12:46:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CDC5862861; Mon, 15 May 2023 14:45:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1684154759; bh=NAHs9FK9AVfQThDyoQpZ9B+QTH6lGyz46GyQML1npQk=; 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=SRKdkizuacsuZezajvJSBh9S0A0LvYcV5oanbQcgcAoapEU9vFSgoLO0IAsJ0d0d6 1EMweegIOYhzrsGIaPNH21fFfjAmUPG6n0w2JRaejhIFAWrkc4n6pSi4MTYKTAF0+s znlgTDSL2IK9y9kKmKEdfnVoDFt7eLdc0ArTlzgjUZOSClY/h2zDgtZTXIDF0P269Z YNK8CQRrORjWIGVpJl/kNPVamnJX7PRrMU2EjJPSoLQiDtRk+3ljfhTmUfYVb5YqVN BgG2Plvgjgn84fShhpwbKfTfKUKhxBTyv8gFuGMk+EccEQY+awBt5bw3WPM9hjlFOH P8UcAKICSCXPg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 36E58627DE for ; Mon, 15 May 2023 14:45:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OE5LmTpu"; 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 8316B4DB; Mon, 15 May 2023 14:45:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1684154744; bh=NAHs9FK9AVfQThDyoQpZ9B+QTH6lGyz46GyQML1npQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OE5LmTpun/B/RtF9RndIh07JG5regN/iLOfEzLOAkQarQCbIO+uP4ydyutvCXwxIR 5XchaAFex0rysNLIbWVjfXD0YfUC/L7RmdjPr+w78jkbs0d8Q0/LJeeDCjSZoncsLb iOwk+pZsMFooUrhrty05ST8FIz88/GUij4QzFOso= To: libcamera devel Date: Mon, 15 May 2023 13:45:50 +0100 Message-Id: <20230515124550.3601128-6-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230515124550.3601128-1-kieran.bingham@ideasonboard.com> References: <20230515124550.3601128-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 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 Tested-by: Ashok Sidipotu Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- 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 885bb2825687..680e1f58cb02 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 70eb4e455e54..7e499def9ddc 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/device_enumerator.h" #include "libcamera/internal/pipeline_handler.h" @@ -150,19 +152,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); @@ -177,6 +177,10 @@ void CameraManager::Private::addCamera(std::shared_ptr camera, } } + auto devnums = camera->properties() + .get(properties::Devices) + .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..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)); } /**