From patchwork Mon Dec 23 07:26:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 2447 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D2F36046D for ; Mon, 23 Dec 2019 08:26:51 +0100 (CET) Received: from neptunite.amanokami.net (173-16-160-11.client.mchsi.com [173.16.160.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6E187330; Mon, 23 Dec 2019 08:26:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1577086011; bh=4IEUMXY74vjJC71TPRtV2Nlq+V2SOF9HiN37jWgnzk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OvosLaZqbCMklTBBxELeY0WF+bc93HeDN2aBDCRPg3kohvJI+cxPAbrFH48KRkLhm /xNIFvQJvC5R3kYz9aEbh1CyeHHfgW/ov8Mx4nx73lj5Tix6LjpYDBcgcF549fAveC cbrHSC34cMSrvff1B+uP28xCvytK3MAhoftsG7Qo= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Dec 2019 01:26:18 -0600 Message-Id: <20191223072620.13022-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191223072620.13022-1-paul.elder@ideasonboard.com> References: <20191223072620.13022-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/6] libcamera: camera_manager: allow retrieving cameras by devnum 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-List-Received-Date: Mon, 23 Dec 2019 07:26:51 -0000 Expose a method to retrieve Cameras by devnum. The map of devnum to Camera is gathered from all PipelineHandlers. This method is mainly for the V4L2 compatibility layer, in order to match V4L2 devices to libcamera Cameras. Signed-off-by: Paul Elder Reviewed-by: Jacopo Mondi --- New in v3 --- include/libcamera/camera_manager.h | 3 +++ src/libcamera/camera_manager.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 8331898c..6ce63912 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_CAMERA_MANAGER_H__ #define __LIBCAMERA_CAMERA_MANAGER_H__ +#include #include #include #include @@ -33,6 +34,7 @@ public: const std::vector> &cameras() const { return cameras_; } std::shared_ptr get(const std::string &name); + std::shared_ptr get(dev_t devnum); void addCamera(std::shared_ptr camera); void removeCamera(Camera *camera); @@ -46,6 +48,7 @@ private: std::unique_ptr enumerator_; std::vector> pipes_; std::vector> cameras_; + std::map> camerasByDevnum_; static const std::string version_; static CameraManager *self_; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 7c6f72bb..1354df4c 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -121,6 +121,11 @@ int CameraManager::start() } } + for (std::shared_ptr pipe : pipes_) { + const std::map> devMap = pipe->camerasByDevnum(); + camerasByDevnum_.insert(devMap.begin(), devMap.end()); + } + /* TODO: register hot-plug callback here */ return 0; @@ -180,6 +185,25 @@ std::shared_ptr CameraManager::get(const std::string &name) return nullptr; } +/** + * \brief Get a camera based on devnum + * \param[in] devnum Device number of camera to get + * + * Before calling this function the caller is responsible for ensuring that + * the camera manager is running. + * + * \return Shared pointer to Camera object or nullptr if camera not found + */ +std::shared_ptr CameraManager::get(dev_t devnum) +{ + auto iter = camerasByDevnum_.find(devnum); + + if (iter == camerasByDevnum_.end()) + return nullptr; + + return iter->second; +} + /** * \brief Add a camera to the camera manager * \param[in] camera The camera to be added