From patchwork Thu Jun 11 17:16:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 4027 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 952D961027 for ; Thu, 11 Jun 2020 19:16:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="n+xRptwD"; 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=hy9kPHlRcNDPV9xcmzuBcY0diH6AD2OeqkMd1R7orls=; b=n+xRptwDuTQTuFp1LzmiK1A+id2reV4JR1AsZFdwiq0D6omMgytXLjR76gtnz03joT84 gR/E+8ZVv9IEB5kL+sVCLiOcbPAmoxIEEr8dCE2GfDqr5xl00JYauPtbjHA2+nTS/t4gnu fqRALGGuBGYrVyxgzlIdtI+LU833MS/Nc= Received: by filterdrecv-p3iad2-784dbb6bd8-jftzh with SMTP id filterdrecv-p3iad2-784dbb6bd8-jftzh-17-5EE266D5-23 2020-06-11 17:16:05.310937936 +0000 UTC m=+680954.236033796 Received: from mail.uajain.com (unknown) by ismtpd0001p1hnd1.sendgrid.net (SG) with ESMTP id BQmhn86PQSKaruCQddJE9A Thu, 11 Jun 2020 17:16:04.923 +0000 (UTC) From: Umang Jain Date: Thu, 11 Jun 2020 17:16:05 +0000 (UTC) Message-Id: <20200611171528.9381-4-email@uajain.com> In-Reply-To: <20200611171528.9381-1-email@uajain.com> References: <20200611171528.9381-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcofpXQ1KwJPJayd5tGsU1eP6ax03JDjPaDSEaSM2mPEVoxIECu4EqLbxhCzPjDh7ubXCNxFCfLoNsveqR5JoGf3wpL7FfNtcTyZfgF33X8BDEhnu1AYYqNBgD7T5GUmG0ZuArQebzDv0ZCAunIpmQrVE612Ua9baS7/uKDeFuqjGQbNxZPoPLF1z5fDP/g/P2JDC0J+AhF+wzTK/+5XHImQ== To: laurent.pinchart@ideasonboard.com, libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v4 3/6] libcamera: device_enumerator: Emit a signal when a new devices are added 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: Thu, 11 Jun 2020 17:16:07 -0000 Emit a signal whenever a new MediaDevices are added to the DeviceEnumerator. This will allow CameraManager to be notified about the new devices and it can re-emumerate all the devices currently present on the system. Device enumeration by the CameraManger is a expensive operation hence, we want one signal emission per 'x' milliseconds to notify multiple devices additions as a single batch, by the DeviceEnumerator. Add a \todo to investigate the support for that. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/internal/device_enumerator.h | 4 ++++ src/libcamera/camera_manager.cpp | 4 ++-- src/libcamera/device_enumerator.cpp | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h index 25a3630..a985040 100644 --- a/include/libcamera/internal/device_enumerator.h +++ b/include/libcamera/internal/device_enumerator.h @@ -13,6 +13,8 @@ #include +#include + namespace libcamera { class MediaDevice; @@ -43,6 +45,8 @@ public: std::shared_ptr search(const DeviceMatch &dm); + Signal<> devicesAdded; + protected: std::unique_ptr createDevice(const std::string &deviceNode); void addDevice(std::unique_ptr &&media); diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index aba5a0c..17a4afb 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -155,12 +155,12 @@ void CameraManager::Private::createPipelineHandlers() } } - /* \todo Register hot-plug callback here */ + enumerator_->devicesAdded.connect(this, &Private::createPipelineHandlers); } void CameraManager::Private::cleanup() { - /* \todo Unregister hot-plug callback here */ + enumerator_->devicesAdded.disconnect(this, &Private::createPipelineHandlers); /* * 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 e21a2a7..e3264a5 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -227,6 +227,16 @@ std::unique_ptr DeviceEnumerator::createDevice(const std::string &d return media; } +/** +* \var DeviceEnumerator::devicesAdded +* \brief Notify of new media devices being found +* +* This signal is emitted when the device enumerator finds new media devices in +* the system. It may be emitted for every newly detected device, or once for +* multiple of devices, at the discretion of the device enumerator. Not all +* device enumerator types may support dynamic detection of new devices. +*/ + /** * \brief Add a media device to the enumerator * \param[in] media media device instance to add @@ -242,6 +252,9 @@ void DeviceEnumerator::addDevice(std::unique_ptr &&media) << "Added device " << media->deviceNode() << ": " << media->driver(); devices_.push_back(std::move(media)); + + /* \todo To batch multiple additions, emit with a small delay here. */ + devicesAdded.emit(); } /**