Patch Detail
Show a patch.
GET /api/1.1/patches/2479/?format=api
{ "id": 2479, "url": "https://patchwork.libcamera.org/api/1.1/patches/2479/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2479/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20191231053314.20063-3-paul.elder@ideasonboard.com>", "date": "2019-12-31T05:33:12", "name": "[libcamera-devel,v4,2/4] libcamera: camera_manager, pipeline_handler: allow retrieving cameras by device numbers", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4494da99cb3333f442be61a3fa6e7b829372cfdb", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/2479/mbox/", "series": [ { "id": 595, "url": "https://patchwork.libcamera.org/api/1.1/series/595/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=595", "date": "2019-12-31T05:33:10", "name": "V4L2 compatibility layer", "version": 4, "mbox": "https://patchwork.libcamera.org/series/595/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2479/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2479/checks/", "tags": {}, "headers": { "Return-Path": "<paul.elder@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 77E4360465\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 31 Dec 2019 06:33:26 +0100 (CET)", "from neptunite.amanokami.net (173-16-160-11.client.mchsi.com\n\t[173.16.160.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 27787DF;\n\tTue, 31 Dec 2019 06:33:24 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1577770406;\n\tbh=09jD1Lyv4HyQcggTGVUBPjPiatMNZ4nb2uRlbWJEGws=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=rN9d9kCBVA+bgT3GWsRVW5IMSNs1IY/TZxB1HPNqAuafhuYSi+jmTP45a9j8l4Zch\n\tVNc/fxmj57o4qE5TP/fFwCUFO7GPfm+qIZ+WL73PrYYPv3vpRmhZkQly+/KM1T7Gh2\n\t8xjm0C1fvJCp0/51rBWcW8hscrZIe/2R+3cSO20I=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 30 Dec 2019 23:33:12 -0600", "Message-Id": "<20191231053314.20063-3-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.23.0", "In-Reply-To": "<20191231053314.20063-1-paul.elder@ideasonboard.com>", "References": "<20191231053314.20063-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 2/4] libcamera: camera_manager,\n\tpipeline_handler: allow retrieving cameras by device numbers", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "X-List-Received-Date": "Tue, 31 Dec 2019 05:33:27 -0000" }, "content": "The V4L2 compatibility layer will need a way to map device numbers to\nlibcamera Camera instances. Expose a method in the camera manager to\nretrieve Camera instances by devnum. The mapping from device numbers to\nCamera instances is optionally declared by pipeline handlers when they\nregister cameras with the camera manager.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\n---\nChanges in v4:\n- squashed 4/6 from v3\n- simplified registering devnum -> camera mappings\n - old (v3) system: pipeline handlers have their own map, that camera\n manager aggregates\n - new (v4) system: pipeline handlers, when they register the camera\n with the camera manager, (optionally) declare the devnum along with it\n\nNew in v3\n---\n include/libcamera/camera_manager.h | 5 +++-\n src/libcamera/camera_manager.cpp | 37 +++++++++++++++++++++++-\n src/libcamera/include/pipeline_handler.h | 3 +-\n src/libcamera/pipeline_handler.cpp | 13 +++++++--\n 4 files changed, 53 insertions(+), 5 deletions(-)", "diff": "diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h\nindex 8331898c..d2d6e443 100644\n--- a/include/libcamera/camera_manager.h\n+++ b/include/libcamera/camera_manager.h\n@@ -7,6 +7,7 @@\n #ifndef __LIBCAMERA_CAMERA_MANAGER_H__\n #define __LIBCAMERA_CAMERA_MANAGER_H__\n \n+#include <map>\n #include <memory>\n #include <string>\n #include <vector>\n@@ -33,8 +34,9 @@ public:\n \n \tconst std::vector<std::shared_ptr<Camera>> &cameras() const { return cameras_; }\n \tstd::shared_ptr<Camera> get(const std::string &name);\n+\tstd::shared_ptr<Camera> get(dev_t devnum);\n \n-\tvoid addCamera(std::shared_ptr<Camera> camera);\n+\tvoid addCamera(std::shared_ptr<Camera> camera, dev_t devnum);\n \tvoid removeCamera(Camera *camera);\n \n \tstatic const std::string &version() { return version_; }\n@@ -46,6 +48,7 @@ private:\n \tstd::unique_ptr<DeviceEnumerator> enumerator_;\n \tstd::vector<std::shared_ptr<PipelineHandler>> pipes_;\n \tstd::vector<std::shared_ptr<Camera>> cameras_;\n+\tstd::map<dev_t, std::weak_ptr<Camera>> camerasByDevnum_;\n \n \tstatic const std::string version_;\n \tstatic CameraManager *self_;\ndiff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nindex 7c6f72bb..b6204872 100644\n--- a/src/libcamera/camera_manager.cpp\n+++ b/src/libcamera/camera_manager.cpp\n@@ -180,15 +180,45 @@ std::shared_ptr<Camera> CameraManager::get(const std::string &name)\n \treturn nullptr;\n }\n \n+/**\n+ * \\brief Retrieve a camera based on device number\n+ * \\param[in] devnum Device number of camera to get\n+ *\n+ * Retrieving a camera based on device number is done by the V4L2 compatibility\n+ * layer to map device nodes to libcamera Camera instances.\n+ *\n+ * Regular applications are recommended to retrieve libcamera Camera instances\n+ * by name instead.\n+ *\n+ * Before calling this function the caller is responsible for ensuring that\n+ * the camera manager is running.\n+ *\n+ * \\return Shared pointer to Camera object, which is empty if the camera is\n+ * not found\n+ */\n+std::shared_ptr<Camera> CameraManager::get(dev_t devnum)\n+{\n+\tauto iter = camerasByDevnum_.find(devnum);\n+\n+\tif (iter == camerasByDevnum_.end())\n+\t\treturn nullptr;\n+\n+\treturn iter->second.lock();\n+}\n+\n /**\n * \\brief Add a camera to the camera manager\n * \\param[in] camera The camera to be added\n+ * \\param[in] devnum The device number to associate with \\a camera\n *\n * This function is called by pipeline handlers to register the cameras they\n * handle with the camera manager. Registered cameras are immediately made\n * available to the system.\n+ *\n+ * \\a devnum is used by the V4L2 compatibility layer to map V4L2 device nodes\n+ * to libcamera Camera instances.\n */\n-void CameraManager::addCamera(std::shared_ptr<Camera> camera)\n+void CameraManager::addCamera(std::shared_ptr<Camera> camera, dev_t devnum)\n {\n \tfor (std::shared_ptr<Camera> c : cameras_) {\n \t\tif (c->name() == camera->name()) {\n@@ -200,6 +230,11 @@ void CameraManager::addCamera(std::shared_ptr<Camera> camera)\n \t}\n \n \tcameras_.push_back(std::move(camera));\n+\n+\tif (devnum) {\n+\t\tunsigned int index = cameras_.size() - 1;\n+\t\tcamerasByDevnum_[devnum] = cameras_[index];\n+\t}\n }\n \n /**\ndiff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h\nindex f3622631..067baef5 100644\n--- a/src/libcamera/include/pipeline_handler.h\n+++ b/src/libcamera/include/pipeline_handler.h\n@@ -12,6 +12,7 @@\n #include <memory>\n #include <set>\n #include <string>\n+#include <sys/sysmacros.h>\n #include <vector>\n \n #include <ipa/ipa_interface.h>\n@@ -86,7 +87,7 @@ public:\n \n protected:\n \tvoid registerCamera(std::shared_ptr<Camera> camera,\n-\t\t\t std::unique_ptr<CameraData> data);\n+\t\t\t std::unique_ptr<CameraData> data, dev_t devnum = 0);\n \tvoid hotplugMediaDevice(MediaDevice *media);\n \n \tvirtual int queueRequestDevice(Camera *camera, Request *request) = 0;\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 5badf31c..942b1a30 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -7,6 +7,8 @@\n \n #include \"pipeline_handler.h\"\n \n+#include <sys/sysmacros.h>\n+\n #include <libcamera/buffer.h>\n #include <libcamera/camera.h>\n #include <libcamera/camera_manager.h>\n@@ -438,19 +440,26 @@ void PipelineHandler::completeRequest(Camera *camera, Request *request)\n * \\brief Register a camera to the camera manager and pipeline handler\n * \\param[in] camera The camera to be added\n * \\param[in] data Pipeline-specific data for the camera\n+ * \\param[in] devnum Device number of the camera (optional)\n *\n * This method is called by pipeline handlers to register the cameras they\n * handle with the camera manager. It associates the pipeline-specific \\a data\n * with the camera, for later retrieval with cameraData(). Ownership of \\a data\n * is transferred to the PipelineHandler.\n+ *\n+ * \\a devnum is the device number (as returned by makedev) that the \\a camera\n+ * is to be associated with. This is for the V4L2 compatibility layer to map\n+ * device nodes to libcamera Camera instances based on the device number\n+ * registered by this method in \\a devnum.\n */\n void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera,\n-\t\t\t\t std::unique_ptr<CameraData> data)\n+\t\t\t\t std::unique_ptr<CameraData> data,\n+\t\t\t\t dev_t devnum)\n {\n \tdata->camera_ = camera.get();\n \tcameraData_[camera.get()] = std::move(data);\n \tcameras_.push_back(camera);\n-\tmanager_->addCamera(std::move(camera));\n+\tmanager_->addCamera(std::move(camera), devnum);\n }\n \n /**\n", "prefixes": [ "libcamera-devel", "v4", "2/4" ] }