From patchwork Wed May 6 10:33:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 3689 Return-Path: Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EB51616A3 for ; Wed, 6 May 2020 12:33:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="NXP4yS/c"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=nvs/rjJ8PZxG296bnRiK0IggLde78s6PT5wz+vhKNtc=; b=NXP4yS/cWOzXxJvguvFRjddbJSp9oqKHUzreiS8zk3y3kks1jr9FwcDhA6hg5SnqrpVl lobjnDLPNWbBMIe3s/DLvGuWZzMfzV3ummqcPaGuK62Gm6AGi57dgJNCFQGoNYVxRwjxTT vLA7+hJMbIb9jdIALbAzmmjizCN0cm1RM= Received: by filter0084p3las1.sendgrid.net with SMTP id filter0084p3las1-1974-5EB2928F-DC 2020-05-06 10:33:52.129458492 +0000 UTC m=+1773124.266965506 Received: from mail.uajain.com (unknown) by ismtpd0004p1maa1.sendgrid.net (SG) with ESMTP id rc7wGKDQR6CxvN76n4JPTA for ; Wed, 06 May 2020 10:33:51.720 +0000 (UTC) From: Umang Jain 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 Subject: [libcamera-devel] [PATCH 1/4] libcamera: device_enumerator: Emit a signal when a new device is hotplugged 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: Wed, 06 May 2020 10:33:55 -0000 Emit a signal whenever is a new MediaDevice is added to the DeviceEnumerator. This will allow CameraManager to get notified about the new devices that have been hot-plugged. Signed-off-by: Umang Jain --- src/libcamera/camera_manager.cpp | 27 +++++++++++++++++++++-- src/libcamera/device_enumerator.cpp | 10 +++++++++ src/libcamera/include/device_enumerator.h | 3 +++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index fddf734..c75979a 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -54,6 +54,7 @@ protected: private: int init(); void cleanup(); + void enumerateNewDevices(DeviceEnumerator *enumerator); CameraManager *cm_; @@ -144,14 +145,36 @@ int CameraManager::Private::init() } } - /* TODO: register hot-plug callback here */ + enumerator_->newDevicesFound.connect(this, &CameraManager::Private::enumerateNewDevices); return 0; } +void CameraManager::Private::enumerateNewDevices(DeviceEnumerator *enumerator) +{ + std::vector &factories = PipelineHandlerFactory::factories(); + + for (PipelineHandlerFactory *factory : factories) { + /* + * Try each pipeline handler until it exhaust + * all pipelines it can provide. + */ + while (1) { + std::shared_ptr pipe = factory->create(cm_); + if (!pipe->match(enumerator_.get())) + break; + + LOG(Camera, Debug) + << "Pipeline handler \"" << factory->name() + << "\" matched"; + pipes_.push_back(std::move(pipe)); + } + } +} + void CameraManager::Private::cleanup() { - /* TODO: unregister hot-plug callback here */ + enumerator_->newDevicesFound.disconnect(this, &CameraManager::Private::enumerateNewDevices); /* * Release all references to cameras and pipeline handlers to ensure diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index dd17e3e..2721120 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -227,6 +227,15 @@ std::unique_ptr DeviceEnumerator::createDevice(const std::string &d return media; } +/** + * \var DeviceEnumerator::newDevicesFound + * \brief Signal emitted when a new MediaDevice is added to the DeviceEnumerator + * + * CameraManager connects to this signal to know about new MediaDevices being plugged-in, + * while it is running. CameraManager will then iterate over the DeviceEnumerator, to match + * their respective pipeline-handlers and prepare the newly plugged-in device for use. + */ + /** * \brief Add a media device to the enumerator * \param[in] media media device instance to add @@ -242,6 +251,7 @@ void DeviceEnumerator::addDevice(std::unique_ptr &&media) << "Added device " << media->deviceNode() << ": " << media->driver(); devices_.push_back(std::move(media)); + newDevicesFound.emit(this); } /** diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h index 433e357..6cc6ec2 100644 --- a/src/libcamera/include/device_enumerator.h +++ b/src/libcamera/include/device_enumerator.h @@ -11,6 +11,7 @@ #include #include +#include #include namespace libcamera { @@ -43,6 +44,8 @@ public: std::shared_ptr search(const DeviceMatch &dm); + Signal newDevicesFound; + protected: std::unique_ptr createDevice(const std::string &deviceNode); void addDevice(std::unique_ptr &&media);