Patch Detail
Show a patch.
GET /api/1.1/patches/17072/?format=api
{ "id": 17072, "url": "https://patchwork.libcamera.org/api/1.1/patches/17072/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17072/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20220810150349.414043-7-utkarsh02t@gmail.com>", "date": "2022-08-10T15:03:47", "name": "[libcamera-devel,v8,6/8] qcam: CamSelectDialog: Add capture script button", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "a781549f759d068f5809de3243568d147b40a2bb", "submitter": { "id": 114, "url": "https://patchwork.libcamera.org/api/1.1/people/114/?format=api", "name": "Utkarsh Tiwari", "email": "utkarsh02t@gmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17072/mbox/", "series": [ { "id": 3402, "url": "https://patchwork.libcamera.org/api/1.1/series/3402/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3402", "date": "2022-08-10T15:03:41", "name": "Introduce capture scripts to qcam", "version": 8, "mbox": "https://patchwork.libcamera.org/series/3402/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17072/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17072/checks/", "tags": {}, "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 D10EFC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Aug 2022 15:04:12 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9B25963339;\n\tWed, 10 Aug 2022 17:04:12 +0200 (CEST)", "from mail-pg1-x536.google.com (mail-pg1-x536.google.com\n\t[IPv6:2607:f8b0:4864:20::536])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A14BF6333A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Aug 2022 17:04:10 +0200 (CEST)", "by mail-pg1-x536.google.com with SMTP id f65so14568088pgc.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Aug 2022 08:04:10 -0700 (PDT)", "from localhost.localdomain ([2404:bd00:3:d2bc:2a55:4cae:bf8f:f4ed])\n\tby smtp.gmail.com with ESMTPSA id\n\tb3-20020a1709027e0300b0016f1319d2a7sm12882624plm.297.2022.08.10.08.04.07\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 10 Aug 2022 08:04:08 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660143852;\n\tbh=upCoIlKlT5qp5pF9zmX7F8MyEgG7EXGLGtXNIVPP4js=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=qxqbbJHQgZhZzOsZ5Ve3dfXJKCPcXNVYKY0zFz5WH5/1IKAINAAIgz5nG6O2Ks+fw\n\tNFBCbJDwDRrnnIiq9wmAyVz4zwQiv55IVbxWKCMsvYNY6B9A2Zr4sFrwVtxEttU0nA\n\tKCvlrNMXRK40TWL8LD/xHhgn4PScx9UpPshm7KESlR8VvMP4MtVePnTFk4WZuAMo9J\n\tVgJU8iH3Q4MTBxR0ooF6y261ftCWBklSK+Z8tDAAhjo5nw2n/hpP6iKLL/4FJEar/W\n\tuPZlmc8pEXHw2k6IJ+QdkcmchxlMnBrrKdJUYNjKQpP5D/KZuox5nqT0CvoHaUdaML\n\tRIHViC8qdi5kg==", "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc;\n\tbh=19kf8evk0yJiVwc4l+BQ3glXTE//vBYqtlQDA6iT9iQ=;\n\tb=Xcczk3j8do8Ouv1FnHaxf3LsrW8Jcy7R3ZfupUUWjA9yYUVPqbPd3c5EtPv/LSw8R6\n\ttp+sGuNu+/fjLUAfK8yNerXAAsWtqBByvN2BQ363g65PQ1R3R9g3FmLVeS5QNkKvOPm/\n\thl192LWtkNwp5UWsfD0Z2x1fL8DRNs0wut6453N9QL3C7cdwM/n8S2YZvRI58xmNOgxw\n\tr4ly9rKj3BfBYc11D+0XQ0MmA75QOHSFYGlKIk6t84fkWtzNgcl6W6ub/5tdp24ihz61\n\t8X4FpxoIsTNRTrdwO5hJ+mP8Enopz4r5ZdrqmJqokg8DGmyOl4FA25ZYcq8GvfNId+WA\n\tXxrg==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"Xcczk3j8\"; dkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc;\n\tbh=19kf8evk0yJiVwc4l+BQ3glXTE//vBYqtlQDA6iT9iQ=;\n\tb=dRgfqys8GerFXjPXEEyj3pumrlyU1hmfjnttIG29K75AOy3Z+wU5ISpLiA+vIknBR4\n\tvAXr2FYM4l71sPTJZLExcK02t//6jJG9mtVOGeYbSgg2Y1lkvh57xsyiO4lPI+q+4bBg\n\tXmVDNPxm1nSm5SN+Drns8R3ZiROMmN8cIqIZuPAcInQK0HO32qkmUbAfyAZ1cgyYfsL3\n\tptJzy+p7xvo9Jf3aL/EoGufFUklWFvFJX02CJwqXtPraL5xNA0miJ+bqC4YWjzWqabcQ\n\tuSeF/TkDXVTegNpbgHf6L6kHoSqkJFJLirlDLzAV69T2cEndf+kOP1oLgNYvzOZNtmDf\n\to8RQ==", "X-Gm-Message-State": "ACgBeo0QAKxPsN8EKnQqLT8GA2f80QE6teBWsgJjyfgWbKjgH06S2/mY\n\tqdcfJFjrS9w08NUGkFrYKBsdCD9Yo4U=", "X-Google-Smtp-Source": "AA6agR52dU11VAbKLtRtPpGW2DBb9AXIDCzFxOBrvShFsw5FhiMA87Z0bpS8SSzIFkRu01H8xnPPIg==", "X-Received": "by 2002:a62:1c04:0:b0:52e:d2b4:c029 with SMTP id\n\tc4-20020a621c04000000b0052ed2b4c029mr22847371pfc.60.1660143848887; \n\tWed, 10 Aug 2022 08:04:08 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 10 Aug 2022 20:33:47 +0530", "Message-Id": "<20220810150349.414043-7-utkarsh02t@gmail.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20220810150349.414043-1-utkarsh02t@gmail.com>", "References": "<20220810150349.414043-1-utkarsh02t@gmail.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v8 6/8] qcam: CamSelectDialog: Add capture\n\tscript button", "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>", "From": "Utkarsh Tiwari via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Utkarsh Tiwari <utkarsh02t@gmail.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Implement an Capture Script in CamSelectDialog button which would allow\nthe user to open a Capture Script (*.yaml).\nThis button has three states :\n - Open Capture Script\n - Loaded\n - Stop the execution of current capture script\n\nWhen clicked in an open state, present the user with a QFileDialog to\nallow selecting a single file. When the script is loaded the button\ndisplays \"Loaded\", the script has not been verified yet. Verifying the\nscript and executing it happens after user presses Ok.\n\nIntroduce a queueCount_ to keep track of the requests queued.\n\nWhen stopping the execution of the capture script the queueCount_ is not\nreset and the capture continues as it is (i.e it is not stopped or\nrestarted).\n\nRequests are queued with any controls the script matching the current\nqueueCount_.\n\nSigned-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>\n---\nDifference from v7:\n\t1. Fix grammetical errors in the commit message\n\t2. Intialize the cameraSelectorDialog_ to nullptr in Construct\n\t\tso we construct the CameraSelectorDialog just once\n src/qcam/cam_select_dialog.cpp | 69 ++++++++++++++++++++++++++++++++--\n src/qcam/cam_select_dialog.h | 20 +++++++++-\n src/qcam/main_window.cpp | 59 ++++++++++++++++++++++++++++-\n src/qcam/main_window.h | 7 ++++\n src/qcam/meson.build | 2 +\n 5 files changed, 152 insertions(+), 5 deletions(-)", "diff": "diff --git a/src/qcam/cam_select_dialog.cpp b/src/qcam/cam_select_dialog.cpp\nindex f97ad6eb..0db0a5bd 100644\n--- a/src/qcam/cam_select_dialog.cpp\n+++ b/src/qcam/cam_select_dialog.cpp\n@@ -16,12 +16,13 @@\n #include <QComboBox>\n #include <QDialog>\n #include <QDialogButtonBox>\n+#include <QFileDialog>\n #include <QFormLayout>\n #include <QString>\n \n CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManager,\n-\t\t\t\t\t QWidget *parent)\n-\t: QDialog(parent), cm_(cameraManager)\n+\t\t\t\t\t bool isScriptRunning, QWidget *parent)\n+\t: QDialog(parent), cm_(cameraManager), isScriptRunning_(isScriptRunning)\n {\n \t/* Use a QFormLayout for the dialog. */\n \tQFormLayout *layout = new QFormLayout(this);\n@@ -39,6 +40,16 @@ CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManag\n \tconnect(cameraIdComboBox_, &QComboBox::currentTextChanged,\n \t\tthis, &CameraSelectorDialog::handleCameraChange);\n \n+\tcaptureScriptButton_ = new QPushButton;\n+\tconnect(captureScriptButton_, &QPushButton::clicked,\n+\t\tthis, &CameraSelectorDialog::handleCaptureScriptButton);\n+\n+\t/* Display the action that would be performed when button is clicked. */\n+\tif (isScriptRunning_)\n+\t\tcaptureScriptButton_->setText(\"Stop\");\n+\telse\n+\t\tcaptureScriptButton_->setText(\"Open\");\n+\n \t/* Setup the QDialogButton Box */\n \tQDialogButtonBox *buttonBox =\n \t\tnew QDialogButtonBox(QDialogButtonBox::Ok |\n@@ -50,10 +61,10 @@ CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManag\n \t\tthis, &QDialog::reject);\n \n \t/* Set the layout. */\n-\n \tlayout->addRow(\"Camera:\", cameraIdComboBox_);\n \tlayout->addRow(\"Location:\", cameraLocation_);\n \tlayout->addRow(\"Model:\", cameraModel_);\n+\tlayout->addRow(\"Capture Script:\", captureScriptButton_);\n \tlayout->addWidget(buttonBox);\n }\n \n@@ -62,6 +73,11 @@ std::string CameraSelectorDialog::getCameraId()\n \treturn cameraIdComboBox_->currentText().toStdString();\n }\n \n+std::string CameraSelectorDialog::getCaptureScript()\n+{\n+\treturn scriptPath_;\n+}\n+\n /* Hotplug / Unplug Support. */\n void CameraSelectorDialog::cameraAdded(libcamera::Camera *camera)\n {\n@@ -115,3 +131,50 @@ void CameraSelectorDialog::updateCamInfo(const std::shared_ptr<libcamera::Camera\n \n \tcameraModel_->setText(QString::fromStdString(model));\n }\n+\n+/* Capture script support. */\n+void CameraSelectorDialog::handleCaptureScriptButton()\n+{\n+\tif (isScriptRunning_) {\n+\t\tQ_EMIT stopCaptureScript();\n+\t\tisScriptRunning_ = false;\n+\t\tcaptureScriptButton_->setText(\"Open\");\n+\t} else {\n+\t\tselectedScriptPath_ = QFileDialog::getOpenFileName(this,\n+\t\t\t\t\t\t\t\t \"Run Capture Script\", QDir::currentPath(),\n+\t\t\t\t\t\t\t\t \"Capture Script (*.yaml)\")\n+\t\t\t\t\t .toStdString();\n+\n+\t\tif (!selectedScriptPath_.empty())\n+\t\t\tcaptureScriptButton_->setText(\"Loaded\");\n+\t\telse\n+\t\t\tcaptureScriptButton_->setText(\"Open\");\n+\t}\n+}\n+\n+void CameraSelectorDialog::accept()\n+{\n+\tscriptPath_ = selectedScriptPath_;\n+\tQDialog::accept();\n+}\n+\n+void CameraSelectorDialog::reject()\n+{\n+\tif (isScriptRunning_)\n+\t\tselectedScriptPath_ = scriptPath_;\n+\tQDialog::reject();\n+}\n+\n+void CameraSelectorDialog::informScriptReset()\n+{\n+\tisScriptRunning_ = false;\n+\tscriptPath_.clear();\n+\tcaptureScriptButton_->setText(\"Open\");\n+}\n+\n+void CameraSelectorDialog::informScriptRunning(std::string scriptPath)\n+{\n+\tisScriptRunning_ = true;\n+\tscriptPath_ = scriptPath;\n+\tcaptureScriptButton_->setText(\"Stop\");\n+}\ndiff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h\nindex 16475af6..bbdf897e 100644\n--- a/src/qcam/cam_select_dialog.h\n+++ b/src/qcam/cam_select_dialog.h\n@@ -17,18 +17,21 @@\n #include <QComboBox>\n #include <QDialog>\n #include <QLabel>\n+#include <QPushButton>\n \n class CameraSelectorDialog : public QDialog\n {\n \tQ_OBJECT\n public:\n \tCameraSelectorDialog(libcamera::CameraManager *cameraManager,\n-\t\t\t QWidget *parent);\n+\t\t\t bool isScriptRunning, QWidget *parent);\n \n \t~CameraSelectorDialog() = default;\n \n \tstd::string getCameraId();\n \n+\tstd::string getCaptureScript();\n+\n \t/* Hotplug / Unplug Support. */\n \tvoid cameraAdded(libcamera::Camera *camera);\n \n@@ -38,11 +41,26 @@ public:\n \tvoid updateCamInfo(const std::shared_ptr<libcamera::Camera> &camera);\n \tvoid handleCameraChange();\n \n+\t/* Capture script support. */\n+\tvoid handleCaptureScriptButton();\n+\tvoid informScriptReset();\n+\tvoid informScriptRunning(std::string scriptPath);\n+\tvoid accept() override;\n+\tvoid reject() override;\n+\n+Q_SIGNALS:\n+\tvoid stopCaptureScript();\n+\n private:\n \tlibcamera::CameraManager *cm_;\n \n+\tbool isScriptRunning_;\n+\tstd::string scriptPath_;\n+\tstd::string selectedScriptPath_;\n+\n \t/* UI elements. */\n \tQComboBox *cameraIdComboBox_;\n \tQLabel *cameraLocation_;\n \tQLabel *cameraModel_;\n+\tQPushButton *captureScriptButton_;\n };\ndiff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex bf40572a..3c7c3173 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -9,6 +9,7 @@\n \n #include <assert.h>\n #include <iomanip>\n+#include <memory>\n #include <string>\n \n #include <libcamera/camera_manager.h>\n@@ -19,6 +20,7 @@\n #include <QFileDialog>\n #include <QImage>\n #include <QImageWriter>\n+#include <QMessageBox>\n #include <QMutexLocker>\n #include <QStandardPaths>\n #include <QStringList>\n@@ -152,6 +154,9 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n \t\treturn;\n \t}\n \n+\t/* Start capture script. */\n+\tloadCaptureScript();\n+\n \tstartStopAction_->setChecked(true);\n }\n \n@@ -290,11 +295,54 @@ void MainWindow::switchCamera()\n \tstartStopAction_->setChecked(true);\n }\n \n+void MainWindow::stopCaptureScript()\n+{\n+\tif (script_) {\n+\t\tscript_.reset();\n+\t\tcameraSelectorDialog_->informScriptReset();\n+\t}\n+}\n+\n+void MainWindow::loadCaptureScript()\n+{\n+\tif (scriptPath_.empty() || camera_ == nullptr)\n+\t\treturn;\n+\n+\tscript_ = std::make_unique<CaptureScript>(camera_, scriptPath_);\n+\n+\t/*\n+\t * If we are already capturing, stop so we don't have stuck image\n+\t * in viewfinder.\n+\t */\n+\tbool wasCapturing = isCapturing_;\n+\tif (isCapturing_)\n+\t\ttoggleCapture(false);\n+\n+\tif (!script_->valid()) {\n+\t\tscript_.reset();\n+\t\tcameraSelectorDialog_->informScriptReset();\n+\n+\t\tQMessageBox::critical(this, \"Invalid Script\",\n+\t\t\t\t \"Couldn't load the capture script\");\n+\n+\t} else\n+\t\tcameraSelectorDialog_->informScriptRunning(scriptPath_);\n+\n+\t/* Start capture again if we were capturing before. */\n+\tif (wasCapturing)\n+\t\ttoggleCapture(true);\n+}\n+\n std::string MainWindow::chooseCamera()\n {\n+\tbool scriptRunning = script_ != nullptr;\n+\n \t/* Construct the selection dialog, only the first time. */\n \tif (!cameraSelectorDialog_)\n-\t\tcameraSelectorDialog_ = new CameraSelectorDialog(cm_, this);\n+\t\tcameraSelectorDialog_ = new CameraSelectorDialog(cm_, scriptRunning, this);\n+\n+\tconnect(cameraSelectorDialog_, &CameraSelectorDialog::stopCaptureScript,\n+\t\tthis, &MainWindow::stopCaptureScript);\n \n \t/*\n \t * Use the camera specified on the command line, if any, or display the\n@@ -309,6 +357,9 @@ std::string MainWindow::chooseCamera()\n \t\tstd::string cameraId = cameraSelectorDialog_->getCameraId();\n \t\tcameraSelectButton_->setText(QString::fromStdString(cameraId));\n \n+\t\tscriptPath_ = cameraSelectorDialog_->getCaptureScript();\n+\t\tloadCaptureScript();\n+\n \t\treturn cameraId;\n \t} else\n \t\treturn std::string();\n@@ -506,6 +557,7 @@ int MainWindow::startCapture()\n \tpreviousFrames_ = 0;\n \tframesCaptured_ = 0;\n \tlastBufferTime_ = 0;\n+\tqueueCount_ = 0;\n \n \tret = camera_->start();\n \tif (ret) {\n@@ -783,5 +835,10 @@ void MainWindow::renderComplete(FrameBuffer *buffer)\n \n int MainWindow::queueRequest(Request *request)\n {\n+\tif (script_)\n+\t\trequest->controls() = script_->frameControls(queueCount_);\n+\n+\tqueueCount_++;\n+\n \treturn camera_->queueRequest(request);\n }\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex d161365a..10994b67 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -27,6 +27,7 @@\n #include <QQueue>\n #include <QTimer>\n \n+#include \"../cam/capture_script.h\"\n #include \"../cam/stream_options.h\"\n \n #include \"cam_select_dialog.h\"\n@@ -89,6 +90,9 @@ private:\n \tvoid processHotplug(HotplugEvent *e);\n \tvoid processViewfinder(libcamera::FrameBuffer *buffer);\n \n+\tvoid loadCaptureScript();\n+\tvoid stopCaptureScript();\n+\n \t/* UI elements */\n \tQToolBar *toolbar_;\n \tQAction *startStopAction_;\n@@ -130,6 +134,9 @@ private:\n \tQElapsedTimer frameRateInterval_;\n \tuint32_t previousFrames_;\n \tuint32_t framesCaptured_;\n+\tuint32_t queueCount_;\n \n \tstd::vector<std::unique_ptr<libcamera::Request>> requests_;\n+\tstd::unique_ptr<CaptureScript> script_;\n+\tstd::string scriptPath_;\n };\ndiff --git a/src/qcam/meson.build b/src/qcam/meson.build\nindex 61861ea6..70a18d7e 100644\n--- a/src/qcam/meson.build\n+++ b/src/qcam/meson.build\n@@ -15,6 +15,7 @@ endif\n qcam_enabled = true\n \n qcam_sources = files([\n+ '../cam/capture_script.cpp',\n '../cam/image.cpp',\n '../cam/options.cpp',\n '../cam/stream_options.cpp',\n@@ -39,6 +40,7 @@ qcam_resources = files([\n qcam_deps = [\n libatomic,\n libcamera_public,\n+ libyaml,\n qt5_dep,\n ]\n \n", "prefixes": [ "libcamera-devel", "v8", "6/8" ] }