{"id":3689,"url":"https://patchwork.libcamera.org/api/1.1/patches/3689/?format=json","web_url":"https://patchwork.libcamera.org/patch/3689/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200506103346.3433-2-email@uajain.com>","date":"2020-05-06T10:33:52","name":"[libcamera-devel,1/4] libcamera: device_enumerator: Emit a signal when a new device is hotplugged","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"23fdb632f3420d57980cc0ee9c08da379673acec","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/people/1/?format=json","name":"Umang Jain","email":"email@uajain.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3689/mbox/","series":[{"id":881,"url":"https://patchwork.libcamera.org/api/1.1/series/881/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=881","date":"2020-05-06T10:33:51","name":"Introduce UVC hotplug support","version":1,"mbox":"https://patchwork.libcamera.org/series/881/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3689/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3689/checks/","tags":{},"headers":{"Return-Path":"<bounces+15657259-5c31-libcamera-devel=lists.libcamera.org@em7280.uajain.com>","Received":["from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EB51616A3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  6 May 2020 12:33:54 +0200 (CEST)","by filter0084p3las1.sendgrid.net with SMTP id\n\tfilter0084p3las1-1974-5EB2928F-DC\n\t2020-05-06 10:33:52.129458492 +0000 UTC m=+1773124.266965506","from mail.uajain.com (unknown)\n\tby ismtpd0004p1maa1.sendgrid.net (SG) with ESMTP id\n\trc7wGKDQR6CxvN76n4JPTA for <libcamera-devel@lists.libcamera.org>;\n\tWed, 06 May 2020 10:33:51.720 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=uajain.com\n\theader.i=@uajain.com header.b=\"NXP4yS/c\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=from:subject:in-reply-to:references:mime-version:to:cc:\n\tcontent-transfer-encoding:content-type;\n\ts=s1; bh=nvs/rjJ8PZxG296bnRiK0IggLde78s6PT5wz+vhKNtc=;\n\tb=NXP4yS/cWOzXxJvguvFRjddbJSp9oqKHUzreiS8zk3y3kks1jr9FwcDhA6hg5SnqrpVl\n\tlobjnDLPNWbBMIe3s/DLvGuWZzMfzV3ummqcPaGuK62Gm6AGi57dgJNCFQGoNYVxRwjxTT\n\tvLA7+hJMbIb9jdIALbAzmmjizCN0cm1RM=","From":"Umang Jain <email@uajain.com>","Date":"Wed, 06 May 2020 10:33:52 +0000 (UTC)","Message-Id":"<20200506103346.3433-2-email@uajain.com>","In-Reply-To":"<20200506103346.3433-1-email@uajain.com>","References":"<20200506103346.3433-1-email@uajain.com>","Mime-Version":"1.0","X-SG-EID":"1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcIgOyDPOiX995eQdp4XFd3CIIppLN3xVP9fnjZAkHN9qdTnu2NWIgAXU39+5gdwjrGNoa+u8+5CJSOTjEjGwKmq5HFCWqqKeBYAIDPTUhZ47UQDjoNLx9V0JhD5RpQUMms6JvWpybQKsoQDJ5ST0GWNvXrRJiUWjHxPuvDlw/9d81eSSbGMF4p/cs/VDPzUxY","To":"libcamera-devel <libcamera-devel@lists.libcamera.org>","Content-Transfer-Encoding":"7bit","Content-Type":"text/plain; charset=us-ascii","Subject":"[libcamera-devel] [PATCH 1/4] libcamera: device_enumerator: Emit a\n\tsignal when a new device is hotplugged","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":"Wed, 06 May 2020 10:33:55 -0000"},"content":"Emit a signal whenever is a new MediaDevice is added to the\nDeviceEnumerator. This will allow CameraManager to get notified\nabout the new devices that have been hot-plugged.\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n src/libcamera/camera_manager.cpp          | 27 +++++++++++++++++++++--\n src/libcamera/device_enumerator.cpp       | 10 +++++++++\n src/libcamera/include/device_enumerator.h |  3 +++\n 3 files changed, 38 insertions(+), 2 deletions(-)","diff":"diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nindex fddf734..c75979a 100644\n--- a/src/libcamera/camera_manager.cpp\n+++ b/src/libcamera/camera_manager.cpp\n@@ -54,6 +54,7 @@ protected:\n private:\n \tint init();\n \tvoid cleanup();\n+\tvoid enumerateNewDevices(DeviceEnumerator *enumerator);\n \n \tCameraManager *cm_;\n \n@@ -144,14 +145,36 @@ int CameraManager::Private::init()\n \t\t}\n \t}\n \n-\t/* TODO: register hot-plug callback here */\n+\tenumerator_->newDevicesFound.connect(this, &CameraManager::Private::enumerateNewDevices);\n \n \treturn 0;\n }\n \n+void CameraManager::Private::enumerateNewDevices(DeviceEnumerator *enumerator)\n+{\n+\tstd::vector<PipelineHandlerFactory *> &factories = PipelineHandlerFactory::factories();\n+\n+\tfor (PipelineHandlerFactory *factory : factories) {\n+\t\t/*\n+\t\t * Try each pipeline handler until it exhaust\n+\t\t * all pipelines it can provide.\n+\t\t */\n+\t\twhile (1) {\n+\t\t\tstd::shared_ptr<PipelineHandler> pipe = factory->create(cm_);\n+\t\t\tif (!pipe->match(enumerator_.get()))\n+\t\t\t\tbreak;\n+\n+\t\t\tLOG(Camera, Debug)\n+\t\t\t\t<< \"Pipeline handler \\\"\" << factory->name()\n+\t\t\t\t<< \"\\\" matched\";\n+\t\t\tpipes_.push_back(std::move(pipe));\n+\t\t}\n+\t}\n+}\n+\n void CameraManager::Private::cleanup()\n {\n-\t/* TODO: unregister hot-plug callback here */\n+\tenumerator_->newDevicesFound.disconnect(this, &CameraManager::Private::enumerateNewDevices);\n \n \t/*\n \t * Release all references to cameras and pipeline handlers to ensure\ndiff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\nindex dd17e3e..2721120 100644\n--- a/src/libcamera/device_enumerator.cpp\n+++ b/src/libcamera/device_enumerator.cpp\n@@ -227,6 +227,15 @@ std::unique_ptr<MediaDevice> DeviceEnumerator::createDevice(const std::string &d\n \treturn media;\n }\n \n+/**\n+ * \\var DeviceEnumerator::newDevicesFound\n+ * \\brief Signal emitted when a new MediaDevice is added to the DeviceEnumerator\n+ *\n+ * CameraManager connects to this signal to know about new MediaDevices being plugged-in,\n+ * while it is running. CameraManager will then iterate over the DeviceEnumerator, to match\n+ * their respective pipeline-handlers and prepare the newly plugged-in device for use.\n+ */\n+\n /**\n  * \\brief Add a media device to the enumerator\n  * \\param[in] media media device instance to add\n@@ -242,6 +251,7 @@ void DeviceEnumerator::addDevice(std::unique_ptr<MediaDevice> &&media)\n \t\t<< \"Added device \" << media->deviceNode() << \": \" << media->driver();\n \n \tdevices_.push_back(std::move(media));\n+\tnewDevicesFound.emit(this);\n }\n \n /**\ndiff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h\nindex 433e357..6cc6ec2 100644\n--- a/src/libcamera/include/device_enumerator.h\n+++ b/src/libcamera/include/device_enumerator.h\n@@ -11,6 +11,7 @@\n #include <string>\n #include <vector>\n \n+#include <libcamera/signal.h>\n #include <linux/media.h>\n \n namespace libcamera {\n@@ -43,6 +44,8 @@ public:\n \n \tstd::shared_ptr<MediaDevice> search(const DeviceMatch &dm);\n \n+\tSignal<DeviceEnumerator *> newDevicesFound;\n+\n protected:\n \tstd::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);\n \tvoid addDevice(std::unique_ptr<MediaDevice> &&media);\n","prefixes":["libcamera-devel","1/4"]}