[{"id":11373,"web_url":"https://patchwork.libcamera.org/comment/11373/","msgid":"<20200713140550.GN2866302@oden.dyn.berto.se>","date":"2020-07-13T14:05:50","subject":"Re: [libcamera-devel] [PATCH] cam: Add --monitor option","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Umang,\n\nThanks for your work.\n\nOn 2020-07-13 12:11:28 +0000, Umang Jain wrote:\n> Add --monitor to monitor new hotplug and unplug camera events from\n> the CameraManager.\n> \n> Signed-off-by: Umang Jain <email@uajain.com>\n\nFirst off, for this patch.\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nWhen testing this patch to discover how far hotplug support have come I \nnoticed some issues. I'm not aware if you know about them or not so I \nwill describe them here.\n\n1. Error message printed from cam\n\n   When I run cam --monitor and physically unplug and then replug a USB \n   UVC camera I get the following ERROR:\n\n   $ cam --monitor\n\n   * unplug camera *\n   Camera Removed: Logitech Webcam C930e\n   [465:45:06.515424906] [593092] ERROR V4L2 v4l2_videodevice.cpp:1117 /dev/video0[cap]: Unable to request 0 buffers: No such device\n\n   * plug camera *\n   Camera Added: Logitech Webcam C930e\n\n   Would it be possible to not print the error when unplugging? I \n   understand the IOCTL can never succeed as the vidoe device is gone \n   but maybe we could avoid logging the error.\n\n2. Qcam hits a delayed assert with hot-plug\n\n   Once more the USB UVC camera is used.\n\n   $ qcam\n   [465:59:29.856991110] [599647]  INFO IPAManager ipa_manager.cpp:136 libcamera is not installed. Adding '/home/neg/work/libcamera/libcamera/build/normal/src/ipa' to the IPA search path\n   [465:59:29.858010955] [599647]  INFO Camera camera_manager.cpp:283 libcamera v0.0.0+1602-7a13375c\n   [465:59:29.870436670] [599649]  INFO IPAProxy ipa_proxy.cpp:122 libcamera is not installed. Loading IPA configuration from '/home/neg/work/libcamera/libcamera/src/ipa/vimc/data'\n   [465:59:36.255358189] [599647]  INFO Camera camera.cpp:770 configuring streams: (0) 1920x1080-MJPEG\n   Using software format conversion from MJPEG\n   seq: 000000 bytesused: 151768 timestamp: 1677576692011000 fps: 0.00\n   seq: 000001 bytesused: 157570 timestamp: 1677576715997000 fps: 41.69\n   seq: 000002 bytesused: 158088 timestamp: 1677576751996000 fps: 27.78\n   seq: 000003 bytesused: 158089 timestamp: 1677576783994000 fps: 31.25\n   ....\n   seq: 000080 bytesused: 167393 timestamp: 1677579347940000 fps: 31.25\n   seq: 000081 bytesused: 167030 timestamp: 1677579383939000 fps: 27.78\n   seq: 000082 bytesused: 167221 timestamp: 1677579415938000 fps: 31.25\n   seq: 000083 bytesused: 166575 timestamp: 1677579447937000 fps: 31.25\n   seq: 000084 bytesused: 165611 timestamp: 1677579483936000 fps: 27.78\n   seq: 000085 bytesused: 166295 timestamp: 1677579515936000 fps: 31.25\n\n   * unplug camera *\n   Removing camera: Logitech Webcam C930e\n   Failed to stop capture\n\n   * wait a while *\n\n   * close qcam *\n   [465:59:47.587993893] [599647] ERROR V4L2 v4l2_videodevice.cpp:1117 /dev/video0[cap]: Unable to request 0 buffers: No such device\n   [465:59:47.588042533] [599649] FATAL default event_dispatcher_poll.cpp:258 assertion \"iter != notifiers_.end()\" failed\n   Backtrace:\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera19EventDispatcherPoll16processNotifiersERKSt6vectorI6pollfdSaIS2_EE+0x150) [0x7ffb28d9ae52]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera19EventDispatcherPoll13processEventsEv+0x2b9) [0x7ffb28d9a75f]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera6Thread4execEv+0x8a) [0x7ffb28de4396]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera13CameraManager7Private3runEv+0x104) [0x7ffb28d4c0d4]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera6Thread11startThreadEv+0xe5) [0x7ffb28de42ff]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZSt13__invoke_implIvMN9libcamera6ThreadEFvvEPS1_JEET_St21__invoke_memfun_derefOT0_OT1_DpOT2_+0x67) [0x7ffb28de8c2b]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZSt8__invokeIMN9libcamera6ThreadEFvvEJPS1_EENSt15__invoke_resultIT_JDpT0_EE4typeEOS6_DpOS7_+0x37) [0x7ffb28de8b6d]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS3_EEE9_M_invokeIJLm0ELm1EEEEvSt12_Index_tupleIJXspT_EEE+0x43) [0x7ffb28de8add]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS3_EEEclEv+0x18) [0x7ffb28de8a96]\n   /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS4_EEEEE6_M_runEv+0x1c) [0x7ffb28de8a7a]\n   /usr/lib/libstdc++.so.6(+0xcfb74) [0x7ffb27582b74]\n   /usr/lib/libpthread.so.0(+0x9422) [0x7ffb26f7d422]\n   /usr/lib/libc.so.6(clone+0x43) [0x7ffb273cfbf3]\n\n> ---\n>  src/cam/main.cpp | 24 ++++++++++++++++++++++++\n>  src/cam/main.h   |  1 +\n>  2 files changed, 25 insertions(+)\n> \n> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> index 2512fe9..3488315 100644\n> --- a/src/cam/main.cpp\n> +++ b/src/cam/main.cpp\n> @@ -36,6 +36,8 @@ public:\n>  \tvoid quit();\n>  \n>  private:\n> +\tvoid cameraAdded(std::shared_ptr<Camera> cam);\n> +\tvoid cameraRemoved(std::shared_ptr<Camera> cam);\n>  \tint parseOptions(int argc, char *argv[]);\n>  \tint prepareConfig();\n>  \tint listControls();\n> @@ -115,6 +117,10 @@ int CamApp::init(int argc, char **argv)\n>  \t\tret = prepareConfig();\n>  \t\tif (ret)\n>  \t\t\treturn ret;\n> +\t} else if (options_.isSet(OptMonitor)) {\n> +\t\tcm_->cameraAdded.connect(this, &CamApp::cameraAdded);\n> +\t\tcm_->cameraRemoved.connect(this, &CamApp::cameraRemoved);\n> +\t\tstd::cout << \"Monitoring new hotplug and unplug events...\" << std::endl;\n>  \t}\n>  \n>  \tloop_ = new EventLoop(cm_->eventDispatcher());\n> @@ -179,6 +185,8 @@ int CamApp::parseOptions(int argc, char *argv[])\n>  \t\t\t \"list-controls\");\n>  \tparser.addOption(OptListProperties, OptionNone, \"List cameras properties\",\n>  \t\t\t \"list-properties\");\n> +\tparser.addOption(OptMonitor, OptionNone, \"Monitor for hotplug and unplug camera events\",\n> +\t\t\t \"monitor\");\n>  \n>  \toptions_ = parser.parse(argc, argv);\n>  \tif (!options_.valid())\n> @@ -293,6 +301,16 @@ int CamApp::infoConfiguration()\n>  \treturn 0;\n>  }\n>  \n> +void CamApp::cameraAdded(std::shared_ptr<Camera> cam)\n> +{\n> +\tstd::cout << \"Camera Added: \" << cam->name() << std::endl;\n> +}\n> +\n> +void CamApp::cameraRemoved(std::shared_ptr<Camera> cam)\n> +{\n> +\tstd::cout << \"Camera Removed: \" << cam->name() << std::endl;\n> +}\n> +\n>  int CamApp::run()\n>  {\n>  \tint ret;\n> @@ -330,6 +348,12 @@ int CamApp::run()\n>  \t\treturn capture.run(loop_, options_);\n>  \t}\n>  \n> +\tif (options_.isSet(OptMonitor)) {\n> +\t\tret = loop_->exec();\n> +\t\tif (ret)\n> +\t\t\tstd::cout << \"Failed to run monitor loop\" << std::endl;\n> +\t}\n> +\n>  \treturn 0;\n>  }\n>  \n> diff --git a/src/cam/main.h b/src/cam/main.h\n> index 4a130d8..f61d288 100644\n> --- a/src/cam/main.h\n> +++ b/src/cam/main.h\n> @@ -15,6 +15,7 @@ enum {\n>  \tOptInfo = 'I',\n>  \tOptList = 'l',\n>  \tOptListProperties = 'p',\n> +\tOptMonitor = 'm',\n>  \tOptStream = 's',\n>  \tOptListControls = 256,\n>  };\n> -- \n> 2.26.2\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 20421BD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Jul 2020 14:05:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9035D605AE;\n\tMon, 13 Jul 2020 16:05:54 +0200 (CEST)","from mail-lj1-x244.google.com (mail-lj1-x244.google.com\n\t[IPv6:2a00:1450:4864:20::244])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 858AC60483\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jul 2020 16:05:52 +0200 (CEST)","by mail-lj1-x244.google.com with SMTP id e8so18016704ljb.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jul 2020 07:05:52 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tj17sm4648057lfk.31.2020.07.13.07.05.50\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 13 Jul 2020 07:05:51 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"FT0Ng4/0\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=142123l75+zgA9GXi166P8bCoeSN/LtSXiaB92Ug90M=;\n\tb=FT0Ng4/0cMZ6fr8tAw/fYe2RViXfvPCMeC/0YqUw6rLHYMcqWbmXSqSf3kYzVAEmHF\n\tAHe2ESe5BkdX3GTRxSnQ4Y+FL7bw7JpE3hV1WiT+L50Izjtq88U23vyZUsZi7B/lXLvJ\n\t26mkeReu56vIDxCwGERYLCwfwEb53cTITMHRr2vU7fDgFA7hwzyqe5E/HX5DFOAkBxfO\n\te+2jQrls1wXk6dh1xwxvqFKGsyBDa8pb82uYwfxJMFT4QFAQXNJoEknMdXTZ8lcp7fSR\n\tVI/IvdG23HXwP70nyBeSKHOL3gbtPmLH6k/1pXwdKZy0X1c3IlqUoxuK5cl455VN1AhC\n\tSHzQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=142123l75+zgA9GXi166P8bCoeSN/LtSXiaB92Ug90M=;\n\tb=Zor84ZmZehNHYpQnUPLHy6wwdV1WTH5HadzntiJvpOStLLa3DwI2ycdAg1x5AO3nqV\n\tHm9AuJouSPHXslY3hKao12QGYOyifc22lDoeW8FhwP3y+XRlXFBIXEreLY9KAXan24F+\n\thrYPd6ZR++IiJ+86snvizAVGneOnOLeNISISD/UMNeYsAa8HTzCJex+iRnTzwcUua0XO\n\tV6VRXIgmDayHtSNMTPURoCWGFGqanfI8SKUrtG8MW2Oh7sfCsKDgUMtgEzDby57fYaeI\n\tBs9+IzC4wfvDxJ4OG8qtjVu2axfl3x+HHUNvgfnRIr0UWMeqJ474zDT2xm8Q4KfCRrAs\n\tml4w==","X-Gm-Message-State":"AOAM533O43oZ5cv+vbXof72dNH/id9xALkuCVxouzS608vOr6kg0h4ud\n\tchQWfaEwGY4TDyj7CDaelPBj8CzLeYI=","X-Google-Smtp-Source":"ABdhPJwfiJbjy/qEwukX4wPnQKqq1UFFOn6vQ246F6sIiOYJlM1uZnKSToOf/40L0YaH+MOQHPVoiQ==","X-Received":"by 2002:a2e:87cf:: with SMTP id\n\tv15mr31884568ljj.231.1594649151800; \n\tMon, 13 Jul 2020 07:05:51 -0700 (PDT)","Date":"Mon, 13 Jul 2020 16:05:50 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Umang Jain <email@uajain.com>","Message-ID":"<20200713140550.GN2866302@oden.dyn.berto.se>","References":"<20200713121122.20000-1-email@uajain.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200713121122.20000-1-email@uajain.com>","Subject":"Re: [libcamera-devel] [PATCH] cam: Add --monitor option","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":11374,"web_url":"https://patchwork.libcamera.org/comment/11374/","msgid":"<33db4db6-3917-f8b2-c515-e0bfefd6e8e9@ideasonboard.com>","date":"2020-07-13T14:14:48","subject":"Re: [libcamera-devel] [PATCH] cam: Add --monitor option","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Umang,\n\nOn 13/07/2020 13:11, Umang Jain wrote:\n> Add --monitor to monitor new hotplug and unplug camera events from\n> the CameraManager.\n> \n> Signed-off-by: Umang Jain <email@uajain.com>\n> ---\n>  src/cam/main.cpp | 24 ++++++++++++++++++++++++\n>  src/cam/main.h   |  1 +\n>  2 files changed, 25 insertions(+)\n> \n> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> index 2512fe9..3488315 100644\n> --- a/src/cam/main.cpp\n> +++ b/src/cam/main.cpp\n> @@ -36,6 +36,8 @@ public:\n>  \tvoid quit();\n>  \n>  private:\n> +\tvoid cameraAdded(std::shared_ptr<Camera> cam);\n> +\tvoid cameraRemoved(std::shared_ptr<Camera> cam);\n>  \tint parseOptions(int argc, char *argv[]);\n>  \tint prepareConfig();\n>  \tint listControls();\n> @@ -115,6 +117,10 @@ int CamApp::init(int argc, char **argv)\n>  \t\tret = prepareConfig();\n>  \t\tif (ret)\n>  \t\t\treturn ret;\n> +\t} else if (options_.isSet(OptMonitor)) {\n> +\t\tcm_->cameraAdded.connect(this, &CamApp::cameraAdded);\n> +\t\tcm_->cameraRemoved.connect(this, &CamApp::cameraRemoved);\n\nShould we add these event notifiers unconditionally?\n\nI think if we are running any kind of event loop, or capture - if\nsomething gets unplugged it would be nice to know about it.\n\nWhat happens if we pull out a UVC camera while streaming with cam?\n\nStill, I think any graceful handling of hotplug in cam is separate to\nadding a monitor, which is useful on it's own, so:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n> +\t\tstd::cout << \"Monitoring new hotplug and unplug events...\" << std::endl;\n>  \t}\n>  \n>  \tloop_ = new EventLoop(cm_->eventDispatcher());\n> @@ -179,6 +185,8 @@ int CamApp::parseOptions(int argc, char *argv[])\n>  \t\t\t \"list-controls\");\n>  \tparser.addOption(OptListProperties, OptionNone, \"List cameras properties\",\n>  \t\t\t \"list-properties\");\n> +\tparser.addOption(OptMonitor, OptionNone, \"Monitor for hotplug and unplug camera events\",\n> +\t\t\t \"monitor\");\n>  \n>  \toptions_ = parser.parse(argc, argv);\n>  \tif (!options_.valid())\n> @@ -293,6 +301,16 @@ int CamApp::infoConfiguration()\n>  \treturn 0;\n>  }\n>  \n> +void CamApp::cameraAdded(std::shared_ptr<Camera> cam)\n> +{\n> +\tstd::cout << \"Camera Added: \" << cam->name() << std::endl;\n> +}\n> +\n> +void CamApp::cameraRemoved(std::shared_ptr<Camera> cam)\n> +{\n> +\tstd::cout << \"Camera Removed: \" << cam->name() << std::endl;\n> +}\n> +\n>  int CamApp::run()\n>  {\n>  \tint ret;\n> @@ -330,6 +348,12 @@ int CamApp::run()\n>  \t\treturn capture.run(loop_, options_);\n>  \t}\n>  \n> +\tif (options_.isSet(OptMonitor)) {\n> +\t\tret = loop_->exec();\n> +\t\tif (ret)\n> +\t\t\tstd::cout << \"Failed to run monitor loop\" << std::endl;\n> +\t}\n> +\n>  \treturn 0;\n>  }\n>  \n> diff --git a/src/cam/main.h b/src/cam/main.h\n> index 4a130d8..f61d288 100644\n> --- a/src/cam/main.h\n> +++ b/src/cam/main.h\n> @@ -15,6 +15,7 @@ enum {\n>  \tOptInfo = 'I',\n>  \tOptList = 'l',\n>  \tOptListProperties = 'p',\n> +\tOptMonitor = 'm',\n>  \tOptStream = 's',\n>  \tOptListControls = 256,\n>  };\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 355ECBD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Jul 2020 14:14:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A737760733;\n\tMon, 13 Jul 2020 16:14:57 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 957AC60485\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jul 2020 16:14:56 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A8A1BC9;\n\tMon, 13 Jul 2020 16:14:51 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IOfwPq3f\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594649691;\n\tbh=A2/pUV2GIIwq2VX0kmGEqaoZUF6/k536LNrNz7OlJns=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=IOfwPq3fPvRgFo5tTZM3L/zFKMvDooXtKK1CONLF18ZPnLhKBL05Q6IbMc/rIKDbx\n\tctT6+RTKrIGMLfIqZ1CWd+8fvXGK+TWV3UyEW3reBO8HFVeuvNo0V7ViIr4h+3mER0\n\tFTAdP8VZYOqj8tPBMlxZ/hwE/01rfV4+c+zVqdos=","To":"Umang Jain <email@uajain.com>, libcamera-devel@lists.libcamera.org","References":"<20200713121122.20000-1-email@uajain.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\t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\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<33db4db6-3917-f8b2-c515-e0bfefd6e8e9@ideasonboard.com>","Date":"Mon, 13 Jul 2020 15:14:48 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.8.0","MIME-Version":"1.0","In-Reply-To":"<20200713121122.20000-1-email@uajain.com>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH] cam: Add --monitor option","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>","Reply-To":"kieran.bingham@ideasonboard.com","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":11375,"web_url":"https://patchwork.libcamera.org/comment/11375/","msgid":"<8d61736c-51e2-c78b-de10-699b2e2620f5@uajain.com>","date":"2020-07-13T15:53:15","subject":"Re: [libcamera-devel] [PATCH] cam: Add --monitor option","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/","name":"Umang Jain","email":"email@uajain.com"},"content":"Hi Niklas,\n\nThanks for the review.\n\nOn 7/13/20 7:35 PM, Niklas Söderlund wrote:\n> Hi Umang,\n>\n> Thanks for your work.\n>\n> On 2020-07-13 12:11:28 +0000, Umang Jain wrote:\n>> Add --monitor to monitor new hotplug and unplug camera events from\n>> the CameraManager.\n>>\n>> Signed-off-by: Umang Jain <email@uajain.com>\n> First off, for this patch.\n>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n>\n> When testing this patch to discover how far hotplug support have come I\n> noticed some issues. I'm not aware if you know about them or not so I\n> will describe them here.\n>\n> 1. Error message printed from cam\n>\n>     When I run cam --monitor and physically unplug and then replug a USB\n>     UVC camera I get the following ERROR:\n>\n>     $ cam --monitor\n>\n>     * unplug camera *\n>     Camera Removed: Logitech Webcam C930e\n>     [465:45:06.515424906] [593092] ERROR V4L2 v4l2_videodevice.cpp:1117 /dev/video0[cap]: Unable to request 0 buffers: No such device\n>\n>     * plug camera *\n>     Camera Added: Logitech Webcam C930e\n>\n>     Would it be possible to not print the error when unplugging? I\n>     understand the IOCTL can never succeed as the vidoe device is gone\n>     but maybe we could avoid logging the error.\nhmm, I am not sure if we can suppress logging that error without much \ninvasive changes.\nOn looking around, I noticed there couple of places where \nV4L2VideoDevice::requestBuffers()\nis called, with request buffer count = 0. This particular one, is being \ncalled from releaseBuffers.\n>\n> 2. Qcam hits a delayed assert with hot-plug\n>\n>     Once more the USB UVC camera is used.\n>\n>     $ qcam\n>     [465:59:29.856991110] [599647]  INFO IPAManager ipa_manager.cpp:136 libcamera is not installed. Adding '/home/neg/work/libcamera/libcamera/build/normal/src/ipa' to the IPA search path\n>     [465:59:29.858010955] [599647]  INFO Camera camera_manager.cpp:283 libcamera v0.0.0+1602-7a13375c\n>     [465:59:29.870436670] [599649]  INFO IPAProxy ipa_proxy.cpp:122 libcamera is not installed. Loading IPA configuration from '/home/neg/work/libcamera/libcamera/src/ipa/vimc/data'\n>     [465:59:36.255358189] [599647]  INFO Camera camera.cpp:770 configuring streams: (0) 1920x1080-MJPEG\n>     Using software format conversion from MJPEG\n>     seq: 000000 bytesused: 151768 timestamp: 1677576692011000 fps: 0.00\n>     seq: 000001 bytesused: 157570 timestamp: 1677576715997000 fps: 41.69\n>     seq: 000002 bytesused: 158088 timestamp: 1677576751996000 fps: 27.78\n>     seq: 000003 bytesused: 158089 timestamp: 1677576783994000 fps: 31.25\n>     ....\n>     seq: 000080 bytesused: 167393 timestamp: 1677579347940000 fps: 31.25\n>     seq: 000081 bytesused: 167030 timestamp: 1677579383939000 fps: 27.78\n>     seq: 000082 bytesused: 167221 timestamp: 1677579415938000 fps: 31.25\n>     seq: 000083 bytesused: 166575 timestamp: 1677579447937000 fps: 31.25\n>     seq: 000084 bytesused: 165611 timestamp: 1677579483936000 fps: 27.78\n>     seq: 000085 bytesused: 166295 timestamp: 1677579515936000 fps: 31.25\n>\n>     * unplug camera *\n>     Removing camera: Logitech Webcam C930e\n>     Failed to stop capture\n>\n>     * wait a while *\n>\n>     * close qcam *\n>     [465:59:47.587993893] [599647] ERROR V4L2 v4l2_videodevice.cpp:1117 /dev/video0[cap]: Unable to request 0 buffers: No such device\n>     [465:59:47.588042533] [599649] FATAL default event_dispatcher_poll.cpp:258 assertion \"iter != notifiers_.end()\" failed\n>     Backtrace:\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera19EventDispatcherPoll16processNotifiersERKSt6vectorI6pollfdSaIS2_EE+0x150) [0x7ffb28d9ae52]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera19EventDispatcherPoll13processEventsEv+0x2b9) [0x7ffb28d9a75f]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera6Thread4execEv+0x8a) [0x7ffb28de4396]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera13CameraManager7Private3runEv+0x104) [0x7ffb28d4c0d4]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera6Thread11startThreadEv+0xe5) [0x7ffb28de42ff]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZSt13__invoke_implIvMN9libcamera6ThreadEFvvEPS1_JEET_St21__invoke_memfun_derefOT0_OT1_DpOT2_+0x67) [0x7ffb28de8c2b]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZSt8__invokeIMN9libcamera6ThreadEFvvEJPS1_EENSt15__invoke_resultIT_JDpT0_EE4typeEOS6_DpOS7_+0x37) [0x7ffb28de8b6d]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS3_EEE9_M_invokeIJLm0ELm1EEEEvSt12_Index_tupleIJXspT_EEE+0x43) [0x7ffb28de8add]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS3_EEEclEv+0x18) [0x7ffb28de8a96]\n>     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS4_EEEEE6_M_runEv+0x1c) [0x7ffb28de8a7a]\n>     /usr/lib/libstdc++.so.6(+0xcfb74) [0x7ffb27582b74]\n>     /usr/lib/libpthread.so.0(+0x9422) [0x7ffb26f7d422]\n>     /usr/lib/libc.so.6(clone+0x43) [0x7ffb273cfbf3]\nYes, I am aware of QCam issue. I suppose you only had one camera(i.e. \nUVC) on the system and trying to plug/unplug that?\nOr did you have multiple ?\n\nQCam still has some corners cases with one camera attached to the system \nwhen I looked at it last time.\n>\n>> ---\n>>   src/cam/main.cpp | 24 ++++++++++++++++++++++++\n>>   src/cam/main.h   |  1 +\n>>   2 files changed, 25 insertions(+)\n>>\n>> diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n>> index 2512fe9..3488315 100644\n>> --- a/src/cam/main.cpp\n>> +++ b/src/cam/main.cpp\n>> @@ -36,6 +36,8 @@ public:\n>>   \tvoid quit();\n>>   \n>>   private:\n>> +\tvoid cameraAdded(std::shared_ptr<Camera> cam);\n>> +\tvoid cameraRemoved(std::shared_ptr<Camera> cam);\n>>   \tint parseOptions(int argc, char *argv[]);\n>>   \tint prepareConfig();\n>>   \tint listControls();\n>> @@ -115,6 +117,10 @@ int CamApp::init(int argc, char **argv)\n>>   \t\tret = prepareConfig();\n>>   \t\tif (ret)\n>>   \t\t\treturn ret;\n>> +\t} else if (options_.isSet(OptMonitor)) {\n>> +\t\tcm_->cameraAdded.connect(this, &CamApp::cameraAdded);\n>> +\t\tcm_->cameraRemoved.connect(this, &CamApp::cameraRemoved);\n>> +\t\tstd::cout << \"Monitoring new hotplug and unplug events...\" << std::endl;\n>>   \t}\n>>   \n>>   \tloop_ = new EventLoop(cm_->eventDispatcher());\n>> @@ -179,6 +185,8 @@ int CamApp::parseOptions(int argc, char *argv[])\n>>   \t\t\t \"list-controls\");\n>>   \tparser.addOption(OptListProperties, OptionNone, \"List cameras properties\",\n>>   \t\t\t \"list-properties\");\n>> +\tparser.addOption(OptMonitor, OptionNone, \"Monitor for hotplug and unplug camera events\",\n>> +\t\t\t \"monitor\");\n>>   \n>>   \toptions_ = parser.parse(argc, argv);\n>>   \tif (!options_.valid())\n>> @@ -293,6 +301,16 @@ int CamApp::infoConfiguration()\n>>   \treturn 0;\n>>   }\n>>   \n>> +void CamApp::cameraAdded(std::shared_ptr<Camera> cam)\n>> +{\n>> +\tstd::cout << \"Camera Added: \" << cam->name() << std::endl;\n>> +}\n>> +\n>> +void CamApp::cameraRemoved(std::shared_ptr<Camera> cam)\n>> +{\n>> +\tstd::cout << \"Camera Removed: \" << cam->name() << std::endl;\n>> +}\n>> +\n>>   int CamApp::run()\n>>   {\n>>   \tint ret;\n>> @@ -330,6 +348,12 @@ int CamApp::run()\n>>   \t\treturn capture.run(loop_, options_);\n>>   \t}\n>>   \n>> +\tif (options_.isSet(OptMonitor)) {\n>> +\t\tret = loop_->exec();\n>> +\t\tif (ret)\n>> +\t\t\tstd::cout << \"Failed to run monitor loop\" << std::endl;\n>> +\t}\n>> +\n>>   \treturn 0;\n>>   }\n>>   \n>> diff --git a/src/cam/main.h b/src/cam/main.h\n>> index 4a130d8..f61d288 100644\n>> --- a/src/cam/main.h\n>> +++ b/src/cam/main.h\n>> @@ -15,6 +15,7 @@ enum {\n>>   \tOptInfo = 'I',\n>>   \tOptList = 'l',\n>>   \tOptListProperties = 'p',\n>> +\tOptMonitor = 'm',\n>>   \tOptStream = 's',\n>>   \tOptListControls = 256,\n>>   };\n>> -- \n>> 2.26.2\n>>\n>> _______________________________________________\n>> libcamera-devel mailing list\n>> libcamera-devel@lists.libcamera.org\n>> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id E7057BD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Jul 2020 15:53:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 693356048D;\n\tMon, 13 Jul 2020 17:53:19 +0200 (CEST)","from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2AA0C603AE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jul 2020 17:53:16 +0200 (CEST)","by filterdrecv-p3las1-7754f7d4cc-l8z88 with SMTP id\n\tfilterdrecv-p3las1-7754f7d4cc-l8z88-20-5F0C836A-A2\n\t2020-07-13 15:53:15.035827334 +0000 UTC m=+1546777.296821613","from mail.uajain.com (unknown)\n\tby ismtpd0001p1hnd1.sendgrid.net (SG) with ESMTP\n\tid 8GfOvh6KQTeFwus8IOMvzw Mon, 13 Jul 2020 15:53:14.540 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"Ppqsef2e\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=subject:references:from:mime-version:in-reply-to:to:cc:content-type:\n\tcontent-transfer-encoding;\n\ts=s1; bh=KBUFg43cVmNTFKkSy8gnXC0we0KjOvKuV02p4fUnh+E=;\n\tb=Ppqsef2eL/68xYrVdqSYwwHaKaqoqJHtYqTTvRdLv4LiwXKwGA75uWIIl8tiuGQGXYOV\n\tjbgPSwu36LDceJMipAvgQw5H8bWIcgNiqbtUAKgTlXf21jn5IVlRzK4tqepvoOke2Go53u\n\tarZHbpXbDpZUfDuM6m2oJLNVKLoudL3fw=","References":"<20200713121122.20000-1-email@uajain.com>\n\t<20200713140550.GN2866302@oden.dyn.berto.se>","From":"Umang Jain <email@uajain.com>","Message-ID":"<8d61736c-51e2-c78b-de10-699b2e2620f5@uajain.com>","Date":"Mon, 13 Jul 2020 15:53:15 +0000 (UTC)","Mime-Version":"1.0","In-Reply-To":"<20200713140550.GN2866302@oden.dyn.berto.se>","X-SG-EID":"1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcZj5z9XHfwy1Ge6f/0y1LY3ALsduPBXx6gkDmVJqlfwzusNuSx8w9fQDQqbKFVYlPpbRjCVYNQEUICrVnjj/BStZLILDNW2tt1jK9H0TpLl+O3pYe00qxNSRMe919LF/d7LL2AZ1gbooi8JW4gN2crUX7vjeKo1hKLhOUBvHEy96wjZPUdnSPAF2ynkTpADViPSAdO0M8qHKLVZkbe16iow==","To":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH] cam: Add --monitor option","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Transfer-Encoding":"quoted-printable","Content-Type":"text/plain; charset=\"iso-8859-1\"; Format=\"flowed\"","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":11376,"web_url":"https://patchwork.libcamera.org/comment/11376/","msgid":"<20200713182154.GP2866302@oden.dyn.berto.se>","date":"2020-07-13T18:21:54","subject":"Re: [libcamera-devel] [PATCH] cam: Add --monitor option","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Umang,\n\nOn 2020-07-13 15:53:15 +0000, Umang Jain wrote:\n> Hi Niklas,\n> \n> Thanks for the review.\n> \n> On 7/13/20 7:35 PM, Niklas Söderlund wrote:\n> > Hi Umang,\n> > \n> > Thanks for your work.\n> > \n> > On 2020-07-13 12:11:28 +0000, Umang Jain wrote:\n> > > Add --monitor to monitor new hotplug and unplug camera events from\n> > > the CameraManager.\n> > > \n> > > Signed-off-by: Umang Jain <email@uajain.com>\n> > First off, for this patch.\n> > \n> > Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > \n> > When testing this patch to discover how far hotplug support have come I\n> > noticed some issues. I'm not aware if you know about them or not so I\n> > will describe them here.\n> > \n> > 1. Error message printed from cam\n> > \n> >     When I run cam --monitor and physically unplug and then replug a USB\n> >     UVC camera I get the following ERROR:\n> > \n> >     $ cam --monitor\n> > \n> >     * unplug camera *\n> >     Camera Removed: Logitech Webcam C930e\n> >     [465:45:06.515424906] [593092] ERROR V4L2 v4l2_videodevice.cpp:1117 /dev/video0[cap]: Unable to request 0 buffers: No such device\n> > \n> >     * plug camera *\n> >     Camera Added: Logitech Webcam C930e\n> > \n> >     Would it be possible to not print the error when unplugging? I\n> >     understand the IOCTL can never succeed as the vidoe device is gone\n> >     but maybe we could avoid logging the error.\n> hmm, I am not sure if we can suppress logging that error without much\n> invasive changes.\n> On looking around, I noticed there couple of places where\n> V4L2VideoDevice::requestBuffers()\n> is called, with request buffer count = 0. This particular one, is being\n> called from releaseBuffers.\n> > \n> > 2. Qcam hits a delayed assert with hot-plug\n> > \n> >     Once more the USB UVC camera is used.\n> > \n> >     $ qcam\n> >     [465:59:29.856991110] [599647]  INFO IPAManager ipa_manager.cpp:136 libcamera is not installed. Adding '/home/neg/work/libcamera/libcamera/build/normal/src/ipa' to the IPA search path\n> >     [465:59:29.858010955] [599647]  INFO Camera camera_manager.cpp:283 libcamera v0.0.0+1602-7a13375c\n> >     [465:59:29.870436670] [599649]  INFO IPAProxy ipa_proxy.cpp:122 libcamera is not installed. Loading IPA configuration from '/home/neg/work/libcamera/libcamera/src/ipa/vimc/data'\n> >     [465:59:36.255358189] [599647]  INFO Camera camera.cpp:770 configuring streams: (0) 1920x1080-MJPEG\n> >     Using software format conversion from MJPEG\n> >     seq: 000000 bytesused: 151768 timestamp: 1677576692011000 fps: 0.00\n> >     seq: 000001 bytesused: 157570 timestamp: 1677576715997000 fps: 41.69\n> >     seq: 000002 bytesused: 158088 timestamp: 1677576751996000 fps: 27.78\n> >     seq: 000003 bytesused: 158089 timestamp: 1677576783994000 fps: 31.25\n> >     ....\n> >     seq: 000080 bytesused: 167393 timestamp: 1677579347940000 fps: 31.25\n> >     seq: 000081 bytesused: 167030 timestamp: 1677579383939000 fps: 27.78\n> >     seq: 000082 bytesused: 167221 timestamp: 1677579415938000 fps: 31.25\n> >     seq: 000083 bytesused: 166575 timestamp: 1677579447937000 fps: 31.25\n> >     seq: 000084 bytesused: 165611 timestamp: 1677579483936000 fps: 27.78\n> >     seq: 000085 bytesused: 166295 timestamp: 1677579515936000 fps: 31.25\n> > \n> >     * unplug camera *\n> >     Removing camera: Logitech Webcam C930e\n> >     Failed to stop capture\n> > \n> >     * wait a while *\n> > \n> >     * close qcam *\n> >     [465:59:47.587993893] [599647] ERROR V4L2 v4l2_videodevice.cpp:1117 /dev/video0[cap]: Unable to request 0 buffers: No such device\n> >     [465:59:47.588042533] [599649] FATAL default event_dispatcher_poll.cpp:258 assertion \"iter != notifiers_.end()\" failed\n> >     Backtrace:\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera19EventDispatcherPoll16processNotifiersERKSt6vectorI6pollfdSaIS2_EE+0x150) [0x7ffb28d9ae52]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera19EventDispatcherPoll13processEventsEv+0x2b9) [0x7ffb28d9a75f]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera6Thread4execEv+0x8a) [0x7ffb28de4396]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera13CameraManager7Private3runEv+0x104) [0x7ffb28d4c0d4]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZN9libcamera6Thread11startThreadEv+0xe5) [0x7ffb28de42ff]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZSt13__invoke_implIvMN9libcamera6ThreadEFvvEPS1_JEET_St21__invoke_memfun_derefOT0_OT1_DpOT2_+0x67) [0x7ffb28de8c2b]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZSt8__invokeIMN9libcamera6ThreadEFvvEJPS1_EENSt15__invoke_resultIT_JDpT0_EE4typeEOS6_DpOS7_+0x37) [0x7ffb28de8b6d]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS3_EEE9_M_invokeIJLm0ELm1EEEEvSt12_Index_tupleIJXspT_EEE+0x43) [0x7ffb28de8add]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS3_EEEclEv+0x18) [0x7ffb28de8a96]\n> >     /home/neg/work/libcamera/libcamera/build/normal/src/qcam/../libcamera/libcamera.so(_ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJMN9libcamera6ThreadEFvvEPS4_EEEEE6_M_runEv+0x1c) [0x7ffb28de8a7a]\n> >     /usr/lib/libstdc++.so.6(+0xcfb74) [0x7ffb27582b74]\n> >     /usr/lib/libpthread.so.0(+0x9422) [0x7ffb26f7d422]\n> >     /usr/lib/libc.so.6(clone+0x43) [0x7ffb273cfbf3]\n> Yes, I am aware of QCam issue. I suppose you only had one camera(i.e. UVC)\n> on the system and trying to plug/unplug that?\n> Or did you have multiple ?\n\nI have two cameras in my system for this test a uvc and vimc pipeline.\n\n$ cam -l\nAvailable cameras:\n1: Logitech Webcam C930e\n2: VIMC Sensor B\n\nIf I remove the vimc kernel driver and thus only have one (uvc) camera \nand run the test described above I get the same result.\n\n> \n> QCam still has some corners cases with one camera attached to the system\n> when I looked at it last time.\n> > \n> > > ---\n> > >   src/cam/main.cpp | 24 ++++++++++++++++++++++++\n> > >   src/cam/main.h   |  1 +\n> > >   2 files changed, 25 insertions(+)\n> > > \n> > > diff --git a/src/cam/main.cpp b/src/cam/main.cpp\n> > > index 2512fe9..3488315 100644\n> > > --- a/src/cam/main.cpp\n> > > +++ b/src/cam/main.cpp\n> > > @@ -36,6 +36,8 @@ public:\n> > >   \tvoid quit();\n> > >   private:\n> > > +\tvoid cameraAdded(std::shared_ptr<Camera> cam);\n> > > +\tvoid cameraRemoved(std::shared_ptr<Camera> cam);\n> > >   \tint parseOptions(int argc, char *argv[]);\n> > >   \tint prepareConfig();\n> > >   \tint listControls();\n> > > @@ -115,6 +117,10 @@ int CamApp::init(int argc, char **argv)\n> > >   \t\tret = prepareConfig();\n> > >   \t\tif (ret)\n> > >   \t\t\treturn ret;\n> > > +\t} else if (options_.isSet(OptMonitor)) {\n> > > +\t\tcm_->cameraAdded.connect(this, &CamApp::cameraAdded);\n> > > +\t\tcm_->cameraRemoved.connect(this, &CamApp::cameraRemoved);\n> > > +\t\tstd::cout << \"Monitoring new hotplug and unplug events...\" << std::endl;\n> > >   \t}\n> > >   \tloop_ = new EventLoop(cm_->eventDispatcher());\n> > > @@ -179,6 +185,8 @@ int CamApp::parseOptions(int argc, char *argv[])\n> > >   \t\t\t \"list-controls\");\n> > >   \tparser.addOption(OptListProperties, OptionNone, \"List cameras properties\",\n> > >   \t\t\t \"list-properties\");\n> > > +\tparser.addOption(OptMonitor, OptionNone, \"Monitor for hotplug and unplug camera events\",\n> > > +\t\t\t \"monitor\");\n> > >   \toptions_ = parser.parse(argc, argv);\n> > >   \tif (!options_.valid())\n> > > @@ -293,6 +301,16 @@ int CamApp::infoConfiguration()\n> > >   \treturn 0;\n> > >   }\n> > > +void CamApp::cameraAdded(std::shared_ptr<Camera> cam)\n> > > +{\n> > > +\tstd::cout << \"Camera Added: \" << cam->name() << std::endl;\n> > > +}\n> > > +\n> > > +void CamApp::cameraRemoved(std::shared_ptr<Camera> cam)\n> > > +{\n> > > +\tstd::cout << \"Camera Removed: \" << cam->name() << std::endl;\n> > > +}\n> > > +\n> > >   int CamApp::run()\n> > >   {\n> > >   \tint ret;\n> > > @@ -330,6 +348,12 @@ int CamApp::run()\n> > >   \t\treturn capture.run(loop_, options_);\n> > >   \t}\n> > > +\tif (options_.isSet(OptMonitor)) {\n> > > +\t\tret = loop_->exec();\n> > > +\t\tif (ret)\n> > > +\t\t\tstd::cout << \"Failed to run monitor loop\" << std::endl;\n> > > +\t}\n> > > +\n> > >   \treturn 0;\n> > >   }\n> > > diff --git a/src/cam/main.h b/src/cam/main.h\n> > > index 4a130d8..f61d288 100644\n> > > --- a/src/cam/main.h\n> > > +++ b/src/cam/main.h\n> > > @@ -15,6 +15,7 @@ enum {\n> > >   \tOptInfo = 'I',\n> > >   \tOptList = 'l',\n> > >   \tOptListProperties = 'p',\n> > > +\tOptMonitor = 'm',\n> > >   \tOptStream = 's',\n> > >   \tOptListControls = 256,\n> > >   };\n> > > -- \n> > > 2.26.2\n> > > \n> > > _______________________________________________\n> > > libcamera-devel mailing list\n> > > libcamera-devel@lists.libcamera.org\n> > > https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 28D50BD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Jul 2020 18:21:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9CBE760726;\n\tMon, 13 Jul 2020 20:21:58 +0200 (CEST)","from mail-lj1-x233.google.com (mail-lj1-x233.google.com\n\t[IPv6:2a00:1450:4864:20::233])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ED7AD6054E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jul 2020 20:21:56 +0200 (CEST)","by mail-lj1-x233.google.com with SMTP id e4so19099876ljn.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jul 2020 11:21:56 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\ts7sm4191927ljc.86.2020.07.13.11.21.55\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 13 Jul 2020 11:21:55 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"dLwUSzJM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=fmfZVxtT86jAkQ+RSTxlUaefZOG6iDp/oHzsttdrFoo=;\n\tb=dLwUSzJMnYYlmrzkyDl9sYfY8EOW7RyC1caJ5vBx5nkPOk1AqPrGtgOsgDfDUSPLgu\n\tMUsBIyHcQs9WGwChtTofYi+3QZML6Rm/6S39YZ9uIiQN6poyAT8exknErje77ys5TqVn\n\t0gbgBB6m1ubfBpqgQ4ZhqFDVTyA+YRqy5z1jxyZWpFzXlcbrtRYOIPnfCwqy/PckQeb5\n\tggA4SQ9oVgN4tSOYbvPHTlJuc6g44fFnxCExHN2tPzWZ2//joDr3oUnHkzD5Upv/Hzpg\n\tXFOBy4X+eVt49qH6Bzk7OVSXm/vhS7KZf0DjIUx8bcKQwDPyHT4oHyDdygrHYmzm1Lll\n\tpGUw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=fmfZVxtT86jAkQ+RSTxlUaefZOG6iDp/oHzsttdrFoo=;\n\tb=L3utZvg33p6Go614V1AlZAOvxv1j55w9DTeGiPWMgCYUbDl0RR4uTGMgBVc+6O2TtD\n\tKzufOwnGZaEBWB4/x0OdULjGzWLIUIaPyR05JGe7O/NDuBpKePhPoOD76Ch28R7U36sl\n\tPO8ON+wchED1nRgPfotubUzBg14taEw0JjsLcAyt52READy9P9Yv5ywo4hmwLtpLiny2\n\tbwJvDekCLzjh9Vf4jBC2OULHgPhKOVrPq2ctQAyMdbck/Nr/vY2Cu0GykUk6vpcFUbrZ\n\th73VLdFqO35m+h2bqQ0j3SV8ltV3GmB5DnQ3hsyN5xZUrO9kEROSAQraYrBNlYgcYR97\n\t7EUw==","X-Gm-Message-State":"AOAM533OaQxBerIlrJ7CFkfRXU/1SACJmHULBLOrerRfKb+Je/uJ61g3\n\tWjq0xMVT6skwtld1Iv5cv5gelg==","X-Google-Smtp-Source":"ABdhPJyEMdVUzVOuQbXBrORWtUqfZzVC99xLkbhZAthGWcv0mXfLPJl6SKUocWiv1Pyk73n0KjmJ/A==","X-Received":"by 2002:a2e:a552:: with SMTP id e18mr442408ljn.162.1594664515883;\n\tMon, 13 Jul 2020 11:21:55 -0700 (PDT)","Date":"Mon, 13 Jul 2020 20:21:54 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Umang Jain <email@uajain.com>","Message-ID":"<20200713182154.GP2866302@oden.dyn.berto.se>","References":"<20200713121122.20000-1-email@uajain.com>\n\t<20200713140550.GN2866302@oden.dyn.berto.se>\n\t<8d61736c-51e2-c78b-de10-699b2e2620f5@uajain.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<8d61736c-51e2-c78b-de10-699b2e2620f5@uajain.com>","Subject":"Re: [libcamera-devel] [PATCH] cam: Add --monitor option","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]