From patchwork Mon Dec 23 07:26:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 2445 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 11D2B605D6 for ; Mon, 23 Dec 2019 08:26:49 +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 D98C5330; Mon, 23 Dec 2019 08:26:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1577086008; bh=s/apEtM2B5nIXIB1dh4v42bvpo2N+ga36ZE6MG2S6xM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QE/feDWFTWVDyXyInJsGLQyi5oc9ig1fwxhZr0NCOOW91OKzutELvJyKnvp1d0Fv/ A9BVp/00q9piWWpGX1HADPoVHY3kg//EzTipxjx16WkVBC9agyMyFpaeExFGjk8yel G12JbrTmyrvpCFUAJGYH8n7OZ5kF+UdTf/PaNKSQ= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Dec 2019 01:26:16 -0600 Message-Id: <20191223072620.13022-3-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 2/6] libcamera: pipeline_handler: Add map from devnum to 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-List-Received-Date: Mon, 23 Dec 2019 07:26:49 -0000 The V4L2 compatibility layer will need a way to map device numbers to libcamera Cameras. As a first step, we add a map from devnum to Cameras to PipelineHandler, as well as an overloaded registerCamera() method to add to this map. Signed-off-by: Paul Elder Reviewed-by: Jacopo Mondi --- New in v3 --- src/libcamera/include/pipeline_handler.h | 6 +++++ src/libcamera/pipeline_handler.cpp | 30 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index f3622631..563de72a 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -84,9 +85,13 @@ public: const char *name() const { return name_; } + const std::map> &camerasByDevnum() const { return camerasByDevnum_; } + protected: void registerCamera(std::shared_ptr camera, std::unique_ptr data); + void registerCamera(std::shared_ptr camera, + std::unique_ptr data, dev_t devnum); void hotplugMediaDevice(MediaDevice *media); virtual int queueRequestDevice(Camera *camera, Request *request) = 0; @@ -102,6 +107,7 @@ private: std::vector> mediaDevices_; std::vector> cameras_; std::map> cameraData_; + std::map> camerasByDevnum_; const char *name_; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 5badf31c..90211f12 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -7,6 +7,8 @@ #include "pipeline_handler.h" +#include + #include #include #include @@ -453,6 +455,28 @@ void PipelineHandler::registerCamera(std::shared_ptr camera, manager_->addCamera(std::move(camera)); } +/** + * \brief Register a camera to the camera manager and pipeline handler + * \param[in] camera The camera to be added + * \param[in] data Pipeline-specific data for the camera + * \param[in] devnum Device number of the camera + * + * This method is called by pipeline handlers to register the cameras they + * handle with the camera manager. It associates the pipeline-specific \a data + * with the camera, for later retrieval with cameraData(). Ownership of \a data + * is transferred to the PipelineHandler. + * + * \a devnum is the device number (as returned by makedev) that the \a camera + * is to be associated with. + */ +void PipelineHandler::registerCamera(std::shared_ptr camera, + std::unique_ptr data, + dev_t devnum) +{ + registerCamera(camera, std::move(data)); + camerasByDevnum_[devnum] = camera; +} + /** * \brief Enable hotplug handling for a media device * \param[in] media The media device @@ -538,6 +562,12 @@ CameraData *PipelineHandler::cameraData(const Camera *camera) * \return The pipeline handler name */ +/** + * \fn PipelineHandler::camerasByDevnum() + * \brief Retrieve the map of devnums to cameras + * \return The map of devnums to cameras + */ + /** * \class PipelineHandlerFactory * \brief Registration of PipelineHandler classes and creation of instances