From patchwork Mon Aug 3 12:48:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 9137 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C6200BD86F for ; Mon, 3 Aug 2020 12:48:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4FB4561826; Mon, 3 Aug 2020 14:48:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QXcV2IPI"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6265C60536 for ; Mon, 3 Aug 2020 14:48:30 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 809D6543; Mon, 3 Aug 2020 14:48:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1596458909; bh=sMw1FwRUK3xxaF1nG0k0EsM4hOwf39/FtEvT6FQZJP8=; h=From:To:Cc:Subject:Date:From; b=QXcV2IPI7ChDO2e3PXTRnrW7Hfjiv8wgAK4UUDHvqfrv8CMPyMmu01DaoIRKB3YRn u6J+xSljdo6Xf16g7jdxs06puh4J6eRrjw8zroh7sPhl/Vvlnn1hBnzrvJXAuMIFYa YAQXxjAPLpSe5DogxWDzoGrZGgeirhZ047ATNq2w= From: Kieran Bingham To: libcamera devel Date: Mon, 3 Aug 2020 13:48:23 +0100 Message-Id: <20200803124823.82691-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] cam: Add --monitor option 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Umang Jain Add --monitor to monitor new hotplug and unplug camera events from the CameraManager. Signed-off-by: Umang Jain Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/cam/main.cpp | 27 +++++++++++++++++++++++++++ src/cam/main.h | 1 + 2 files changed, 28 insertions(+) v3: - V1 rebased, and slightly modified to update the conditional connection of the signals during CamApp::init() - Adjust formatting of parser.addOption Hi all, I am aiming to merge Umang's patch, but because I have ended up making a more than superficial change to the code path in CamApp::init() I'm reposting as v3. This is essentially v1 of Umangs patch (thanks, and sorry for incorrectly leading you to make a v2) with the small line adjustment to the parser addition, but a more impacting adjustment to the conditional which enables the signals. If there are no objections, I can merge this patch. Testing with the two options combined shows: ./build/src/cam/cam -m -c 1 -C fps: 25.64 stream0 seq: 000052 bytesused: 36000 fps: 25.00 stream0 seq: 000053 bytesused: 36024 fps: 25.00 stream0 seq: 000054 bytesused: 36784 fps: 25.64 stream0 seq: 000055 bytesused: 36968 fps: 25.64 stream0 seq: 000056 bytesused: 36792 fps: 25.00 stream0 seq: 000057 bytesused: 37040 fps: 25.64 stream0 seq: 000058 bytesused: 36808 fps: 25.00 stream0 seq: 000059 bytesused: 36848 fps: 25.00 stream0 seq: 000060 bytesused: 37480 Camera Removed: VF0520 Live! Cam Sync: VF0520 L Camera Added: VF0520 Live! Cam Sync: VF0520 L Camera Removed: VF0520 Live! Cam Sync: VF0520 L So the stream doesn't continue, but no crashing - so we're fine ;-) -- Kieran diff --git a/src/cam/main.cpp b/src/cam/main.cpp index f5aba041d7c4..3ceb6576960e 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -36,6 +36,8 @@ public: void quit(); private: + void cameraAdded(std::shared_ptr cam); + void cameraRemoved(std::shared_ptr cam); int parseOptions(int argc, char *argv[]); int prepareConfig(); int listControls(); @@ -123,6 +125,12 @@ int CamApp::init(int argc, char **argv) return ret; } + if (options_.isSet(OptMonitor)) { + cm_->cameraAdded.connect(this, &CamApp::cameraAdded); + cm_->cameraRemoved.connect(this, &CamApp::cameraRemoved); + std::cout << "Monitoring new hotplug and unplug events..." << std::endl; + } + loop_ = new EventLoop(cm_->eventDispatcher()); return 0; @@ -186,6 +194,9 @@ int CamApp::parseOptions(int argc, char *argv[]) "list-controls"); parser.addOption(OptListProperties, OptionNone, "List cameras properties", "list-properties"); + parser.addOption(OptMonitor, OptionNone, + "Monitor for hotplug and unplug camera events", + "monitor"); parser.addOption(OptStrictFormats, OptionNone, "Do not allow requested stream format(s) to be adjusted", "strict-formats"); @@ -309,6 +320,16 @@ int CamApp::infoConfiguration() return 0; } +void CamApp::cameraAdded(std::shared_ptr cam) +{ + std::cout << "Camera Added: " << cam->name() << std::endl; +} + +void CamApp::cameraRemoved(std::shared_ptr cam) +{ + std::cout << "Camera Removed: " << cam->name() << std::endl; +} + int CamApp::run() { int ret; @@ -346,6 +367,12 @@ int CamApp::run() return capture.run(options_); } + if (options_.isSet(OptMonitor)) { + ret = loop_->exec(); + if (ret) + std::cout << "Failed to run monitor loop" << std::endl; + } + return 0; } diff --git a/src/cam/main.h b/src/cam/main.h index 6f95add31a63..ea8dfd330830 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -15,6 +15,7 @@ enum { OptInfo = 'I', OptList = 'l', OptListProperties = 'p', + OptMonitor = 'm', OptStream = 's', OptListControls = 256, OptStrictFormats = 257,