Patch Detail
Show a patch.
GET /api/patches/3835/?format=api
{ "id": 3835, "url": "https://patchwork.libcamera.org/api/patches/3835/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3835/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200521135416.13685-5-email@uajain.com>", "date": "2020-05-21T13:54:26", "name": "[libcamera-devel,v3,4/5] qcam: main_window: Introduce initial hotplug support", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "204f3a622275b80f650cea05c1a6318bddd976d3", "submitter": { "id": 1, "url": "https://patchwork.libcamera.org/api/people/1/?format=api", "name": "Umang Jain", "email": "email@uajain.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3835/mbox/", "series": [ { "id": 920, "url": "https://patchwork.libcamera.org/api/series/920/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=920", "date": "2020-05-21T13:54:23", "name": "Introduce UVC hotplugging support", "version": 3, "mbox": "https://patchwork.libcamera.org/series/920/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3835/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3835/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 66C55603D9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 May 2020 15:54:27 +0200 (CEST)", "by filterdrecv-p3iad2-8ddf98858-cq957 with SMTP id\n\tfilterdrecv-p3iad2-8ddf98858-cq957-19-5EC68811-81\n\t2020-05-21 13:54:26.061975347 +0000 UTC m=+4884416.209782124", "from mail.uajain.com (unknown)\n\tby ismtpd0007p1maa1.sendgrid.net (SG) with ESMTP id\n\t5VvgiGk5SgWFKPJ3int_xg for <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 May 2020 13:54:25.633 +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=\"j/P+5ob1\"; \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=YYVNSzVIGlkduleifeiQvrWjcbhYk9UxIf31QLYEb04=;\n\tb=j/P+5ob1hT3tJH3R907kkFMju1aknQOHepIqZCXXFEIo7GpfFJvdCgU4llVXN7kIkVEa\n\t2QmEX9mQ4Oxcjcbo8ztBkkk4N34Hn+52mTdGAsjJ7UmKQpr41boUj5WUl5DiJwf346NbSu\n\teLIWoijMtSweOUDVgYy28IjolkxO8Tmxc=", "From": "Umang Jain <email@uajain.com>", "Date": "Thu, 21 May 2020 13:54:26 +0000 (UTC)", "Message-Id": "<20200521135416.13685-5-email@uajain.com>", "In-Reply-To": "<20200521135416.13685-1-email@uajain.com>", "References": "<20200521135416.13685-1-email@uajain.com>", "Mime-Version": "1.0", "X-SG-EID": "1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcmGfnt8UlNcpPI7X/q8AWBmiCvDjcK63MedTb+DWhuglfIl0VxLKPKJ8e1utqNA6dzdMLM+G7vGPLRcZvCzrTV/R7kb3JKs5f5FGch+UpqGksv20rQzQG3iohTs+2dFc5LZTxrF8cgx4FbKV9gg2FwxLYn8ikNX7aHyNOqezsuvxM1Ofish+XnwDo2G/3E6AcUVmwUAiaN1IEbJhilnzzmQ==", "To": "libcamera-devel@lists.libcamera.org", "Content-Transfer-Encoding": "7bit", "Content-Type": "text/plain; charset=us-ascii", "Subject": "[libcamera-devel] [PATCH v3 4/5] qcam: main_window: Introduce\n\tinitial hotplug support", "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": "Thu, 21 May 2020 13:54:27 -0000" }, "content": "Hook up various QCam UI bits with hotplug support introduced\nin previous commits. This looks good-enough as first steps\nto see how the hotplugging functionality is turning out to be\nfrom application point-of-view.\n\nOne can still think of few edge case nuances not yet covered\nunder this implementation hence, those are intentionally\nkept out of scope for now. It might require some thinking\nand/or additional time on hand.\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n src/qcam/main_window.cpp | 83 ++++++++++++++++++++++++++++++++++++++++\n src/qcam/main_window.h | 6 +++\n 2 files changed, 89 insertions(+)", "diff": "diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 7de0895..ba96c27 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -49,6 +49,43 @@ public:\n \t}\n };\n \n+/**\n+ * \\brief Custom QEvent to signal hotplug or unplug\n+ */\n+class HotplugEvent : public QEvent\n+{\n+public:\n+\tenum PLUGEVENT {\n+\t\tHOTPLUG,\n+\t\tUNPLUG\n+\t};\n+\n+\tHotplugEvent(std::shared_ptr<Camera> camera, PLUGEVENT event)\n+\t\t: QEvent(type())\n+\t{\n+\t\tcamera_ = camera;\n+\t\tplugEvent_ = event;\n+\t}\n+\n+\t~HotplugEvent()\n+\t{\n+\t\tcamera_.reset();\n+\t}\n+\n+\tstatic Type type()\n+\t{\n+\t\tstatic int type = QEvent::registerEventType();\n+\t\treturn static_cast<Type>(type);\n+\t}\n+\n+\tPLUGEVENT getHotplugEvent() { return plugEvent_; }\n+\tCamera *getCamera() { return camera_.get(); }\n+\n+private:\n+\tstd::shared_ptr<Camera> camera_;\n+\tPLUGEVENT plugEvent_;\n+};\n+\n MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n \t: saveRaw_(nullptr), options_(options), cm_(cm), allocator_(nullptr),\n \t isCapturing_(false), captureRaw_(false)\n@@ -71,6 +108,10 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n \tsetCentralWidget(viewfinder_);\n \tadjustSize();\n \n+\t/* Hotplug/unplug support */\n+\tcm_->newCameraAdded.connect(this, &MainWindow::addNewCamera);\n+\tcm_->cameraRemoved.connect(this, &MainWindow::removeCamera);\n+\n \t/* Open the camera and start capture. */\n \tret = openCamera();\n \tif (ret < 0) {\n@@ -95,6 +136,9 @@ bool MainWindow::event(QEvent *e)\n \tif (e->type() == CaptureEvent::type()) {\n \t\tprocessCapture();\n \t\treturn true;\n+\t} else if (e->type() == HotplugEvent::type()) {\n+\t\tprocessHotplug(static_cast<HotplugEvent *>(e));\n+\t\treturn true;\n \t}\n \n \treturn QMainWindow::event(e);\n@@ -525,6 +569,45 @@ void MainWindow::stopCapture()\n \tsetWindowTitle(title_);\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Camera hotplugging support\n+ */\n+\n+void MainWindow::processHotplug(HotplugEvent *e)\n+{\n+\tCamera *camera = e->getCamera();\n+\tHotplugEvent::PLUGEVENT event = e->getHotplugEvent();\n+\n+\tif (event == HotplugEvent::PLUGEVENT::HOTPLUG) {\n+\t\tcameraCombo_->addItem(QString::fromStdString(camera->name()));\n+\t} else if (event == HotplugEvent::PLUGEVENT::UNPLUG) {\n+\t\tint camIndex = cameraCombo_->findText(QString::fromStdString(camera->name()));\n+\n+\t\t/* Check if the currently-streaming camera is removed. */\n+\t\tif (camera == camera_.get()) {\n+\t\t\ttoggleCapture(false);\n+\t\t\tcameraCombo_->setCurrentIndex(0);\n+\t\t}\n+\t\tcameraCombo_->removeItem(camIndex);\n+\t}\n+}\n+\n+void MainWindow::addNewCamera(std::shared_ptr<Camera> camera)\n+{\n+\tqInfo() << \"Adding new camera:\" << camera->name().c_str();\n+\tQCoreApplication::postEvent(this,\n+\t\t\t\t new HotplugEvent(std::move(camera),\n+\t\t\t\t\t\t HotplugEvent::PLUGEVENT::HOTPLUG));\n+}\n+\n+void MainWindow::removeCamera(std::shared_ptr<Camera> camera)\n+{\n+\tqInfo() << \"Removing camera:\" << camera->name().c_str();\n+\tQCoreApplication::postEvent(this,\n+\t\t\t\t new HotplugEvent(std::move(camera),\n+\t\t\t\t\t\t HotplugEvent::PLUGEVENT::UNPLUG));\n+}\n+\n /* -----------------------------------------------------------------------------\n * Image Save\n */\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 59fa2d9..9108780 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -32,6 +32,8 @@ using namespace libcamera;\n class QAction;\n class QComboBox;\n \n+class HotplugEvent;\n+\n enum {\n \tOptCamera = 'c',\n \tOptHelp = 'h',\n@@ -87,8 +89,12 @@ private:\n \tint startCapture();\n \tvoid stopCapture();\n \n+\tvoid addNewCamera(std::shared_ptr<Camera> camera);\n+\tvoid removeCamera(std::shared_ptr<Camera> camera);\n+\n \tvoid requestComplete(Request *request);\n \tvoid processCapture();\n+\tvoid processHotplug(HotplugEvent *e);\n \tvoid processViewfinder(FrameBuffer *buffer);\n \n \t/* UI elements */\n", "prefixes": [ "libcamera-devel", "v3", "4/5" ] }