Show a patch.

GET /api/1.1/patches/17020/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 17020,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17020/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17020/",
    "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": "<20220807203204.152358-3-utkarsh02t@gmail.com>",
    "date": "2022-08-07T20:32:02",
    "name": "[libcamera-devel,v6,2/4] qcam: CamSelectDialog: Add capture script button",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "fdae3454ea9a10150172822b4f9fd1d052ff03f4",
    "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/17020/mbox/",
    "series": [
        {
            "id": 3385,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3385/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3385",
            "date": "2022-08-07T20:32:00",
            "name": "Introduce capture scripts to qcam",
            "version": 6,
            "mbox": "https://patchwork.libcamera.org/series/3385/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17020/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17020/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 8F029BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  7 Aug 2022 20:32:25 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4D57763331;\n\tSun,  7 Aug 2022 22:32:25 +0200 (CEST)",
            "from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com\n\t[IPv6:2607:f8b0:4864:20::42b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8142E63327\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  7 Aug 2022 22:32:24 +0200 (CEST)",
            "by mail-pf1-x42b.google.com with SMTP id z187so6495598pfb.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 07 Aug 2022 13:32:24 -0700 (PDT)",
            "from localhost.localdomain ([2404:bd00:3:d2bc:8eec:115d:8ea8:b700])\n\tby smtp.gmail.com with ESMTPSA id\n\tx29-20020aa7941d000000b0052d194a6602sm7006334pfo.102.2022.08.07.13.32.21\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 07 Aug 2022 13:32:22 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659904345;\n\tbh=ZKxp1KsJ4mvRmllU7wUk04TZnWO1Vjh4fMSlg/VQkw0=;\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=AhrUfwKldXWKqzsyg7YqszkMcAiQy5O+/L8Yt3OtIl96+/YoeIkUhzm7MlSPIY0Sn\n\tsJzQJDfjF+ho6ycmMNCaUmfc9Gn290GeFQOURqeH8tdfXoOA1QviJfi69h75yx8tql\n\tnBn84MsrI1xNRc0YXU0utuNdEXzjmkjx0csplY/3UtdKbvqFpX8YXVyDIMJyYdJO4j\n\trKUlKILooCwPk1oRxq7bQxV7Vv+ZhPU2uN6AisAUIiJGDD5cLFJ/dIV4+/xyn/ILWe\n\t71/xiPhhyK0AuLzOG0up7lB0CBb+M9l0/u2gWP3raKJtD2qImYjGAekUttKXlkOub2\n\tq0FHMK08F15xQ==",
            "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=qavyrCFTP++VA/WS4m58ciqEI9ghwGad3JE3DUvPKRk=;\n\tb=ZIjgJjPmRVpz78lKANhJu9O9VZf/0K8TBWx+SQUVnstNrLo2vOn6lKnki5+ZkebhLO\n\tUbwLF8M9cHBwsYUGmfnXhOsgrJ2auxqsjhQ2z/gqb5EkcUEVFIW5sJTMAmRYVOHrr4hi\n\t/dH8hkZsng63nZ0UdzE3ET63UQDhHNHx0BN4WUzMryrwUCVc7npSByAFpQFVstIEpIBJ\n\t2ajOZ6gJDjGDkRvRGCTJjhLK+frm5R9YhKVZnkQQBLyALG7XncddJHk+CFNT31EkzSFg\n\tSR5Brw565s39iUbjmdEbgj3JI4XVYH6zevs3BDPAnXqVI3G1otHQcDB8MIp294B5tIL2\n\tMtlA=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"ZIjgJjPm\"; 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=qavyrCFTP++VA/WS4m58ciqEI9ghwGad3JE3DUvPKRk=;\n\tb=HsP2sl/Crfp6sSpk5MgCfKx0b/Plutv0hpEJigdwCpisS6oO7vT6H/SSOmLppVD60G\n\tpLHPYBBDc9Ypev/rPSjBaVfzF9bh/6U8GKKBLd8q67+Eycd1y8ij4CwGE5OuaXMrj95P\n\tg0CIphwD6FIkP84PKXLw7pGDvMvYxz6c+9sy+Tx/nMYl603js+eRPKwaXAf8TO0TT/YF\n\tYSgyL2foJ2acDgLcNWsrArX7JdB5oxiP4cLGYVc3qBFv8ENzXTTewogwGt6Hjv9I0Tq3\n\t2K9XI8sy49YA/YbumSj3twa0t1Dlz6Kse/n0968MDrPbwhmT4xZNav/RSPnQ+55KxImP\n\t97Jw==",
        "X-Gm-Message-State": "ACgBeo2CIBf3DOCntFiP6SjYh0VQ/7VK1v1tDk0+Aa12BPxELrwvuO88\n\td4wzwdFt4FAGxviPdtybulP6PICK8GM=",
        "X-Google-Smtp-Source": "AA6agR7wP3liw94tKGm/JtfTr4zmW9+9Gj15nyUQiLlylKHFt+4/U54Ak3aJJM+fqQL7/GuGn8LCZQ==",
        "X-Received": "by 2002:a63:bd49:0:b0:41b:8a07:a6ed with SMTP id\n\td9-20020a63bd49000000b0041b8a07a6edmr12826181pgp.124.1659904342804; \n\tSun, 07 Aug 2022 13:32:22 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  8 Aug 2022 02:02:02 +0530",
        "Message-Id": "<20220807203204.152358-3-utkarsh02t@gmail.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20220807203204.152358-1-utkarsh02t@gmail.com>",
        "References": "<20220807203204.152358-1-utkarsh02t@gmail.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v6 2/4] 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 being clicked in open state, present them with a QFileDialog to\nallow user to select 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\nreseted and the capture is 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 V1:\n\tNo button on toolbar now it resides in CamSelectDialog\n src/qcam/cam_select_dialog.h | 47 +++++++++++++++++++++++++++++--\n src/qcam/main_window.cpp     | 54 +++++++++++++++++++++++++++++++++++-\n src/qcam/main_window.h       |  7 +++++\n src/qcam/meson.build         |  2 ++\n 4 files changed, 107 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h\nindex 6ba61cff..fc29b46a 100644\n--- a/src/qcam/cam_select_dialog.h\n+++ b/src/qcam/cam_select_dialog.h\n@@ -18,16 +18,19 @@\n #include <QComboBox>\n #include <QDialog>\n #include <QDialogButtonBox>\n+#include <QFileDialog>\n #include <QFormLayout>\n #include <QLabel>\n+#include <QPushButton>\n #include <QString>\n \n class CamSelectDialog : public QDialog\n {\n \tQ_OBJECT\n public:\n-\tCamSelectDialog(libcamera::CameraManager *cameraManager, QWidget *parent)\n-\t\t: QDialog(parent), cm_(cameraManager)\n+\tCamSelectDialog(libcamera::CameraManager *cameraManager,\n+\t\t\tbool isScriptRunning, QWidget *parent)\n+\t\t: QDialog(parent), cm_(cameraManager), isScriptRunning_(isScriptRunning)\n \t{\n \t\t/* Use a QFormLayout for the dialog. */\n \t\tQFormLayout *camSelectDialogLayout = new QFormLayout(this);\n@@ -48,6 +51,16 @@ public:\n \t\t\t\t\tcameraIdComboBox_->currentText().toStdString()));\n \t\t\t});\n \n+\t\tcaptureScriptButton_ = new QPushButton;\n+\t\tconnect(captureScriptButton_, &QPushButton::clicked,\n+\t\t\tthis, &CamSelectDialog::handleCaptureScriptButton);\n+\n+\t\t/* Display the action that would be performed when button is clicked. */\n+\t\tif (isScriptRunning_)\n+\t\t\tcaptureScriptButton_->setText(\"Stop\");\n+\t\telse\n+\t\t\tcaptureScriptButton_->setText(\"Open\");\n+\n \t\t/* Setup the QDialogButton Box */\n \t\tQDialogButtonBox *dialogButtonBox =\n \t\t\tnew QDialogButtonBox(QDialogButtonBox::Ok |\n@@ -62,6 +75,7 @@ public:\n \t\tcamSelectDialogLayout->addRow(\"Camera: \", cameraIdComboBox_);\n \t\tcamSelectDialogLayout->addRow(\"Location: \", cameraLocation_);\n \t\tcamSelectDialogLayout->addRow(\"Model: \", cameraModel_);\n+\t\tcamSelectDialogLayout->addRow(\"Capture Script: \", captureScriptButton_);\n \t\tcamSelectDialogLayout->addWidget(dialogButtonBox);\n \t}\n \n@@ -72,6 +86,11 @@ public:\n \t\treturn cameraIdComboBox_->currentText().toStdString();\n \t}\n \n+\tstd::string getCaptureScript()\n+\t{\n+\t\treturn scriptPath_;\n+\t}\n+\n \t/* Hotplug / Unplug Support. */\n \tvoid cameraAdded(libcamera::Camera *camera)\n \t{\n@@ -122,11 +141,35 @@ public:\n \t\t\tcameraModel_->setText(QString());\n \t}\n \n+\t/* Capture script support. */\n+\tvoid handleCaptureScriptButton()\n+\t{\n+\t\tif (isScriptRunning_) {\n+\t\t\tQ_EMIT stopCaptureScript();\n+\t\t\tisScriptRunning_ = false;\n+\t\t\tcaptureScriptButton_->setText(\"Open\");\n+\t\t} else {\n+\t\t\tscriptPath_ = QFileDialog::getOpenFileName(this, \"Run Capture Script\",\n+\t\t\t\t\t\t\t\t   QDir::currentPath(), \"Capture Script (*.yaml)\")\n+\t\t\t\t\t      .toStdString();\n+\n+\t\t\tif (!scriptPath_.empty())\n+\t\t\t\tcaptureScriptButton_->setText(\"Loaded\");\n+\t\t}\n+\t}\n+\n+Q_SIGNALS:\n+\tvoid stopCaptureScript();\n+\n private:\n \tlibcamera::CameraManager *cm_;\n \n+\tbool isScriptRunning_;\n+\tstd::string scriptPath_;\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 549af024..e0219e5e 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@@ -151,6 +153,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,14 +295,55 @@ void MainWindow::switchCamera()\n \tstartStopAction_->setChecked(true);\n }\n \n+void MainWindow::stopCaptureScript()\n+{\n+\tif (script_) {\n+\t\tscript_.reset();\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+\n+\t\tQMessageBox::critical(this, \"Invalid Script\",\n+\t\t\t\t      \"Couldn't load the capture script\");\n+\t}\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-\tcamSelectDialog_ = new CamSelectDialog(cm_, this);\n+\tbool scriptRunning = script_ != nullptr;\n+\tcamSelectDialog_ = new CamSelectDialog(cm_, scriptRunning, this);\n+\n+\tconnect(camSelectDialog_, &CamSelectDialog::stopCaptureScript,\n+\t\tthis, &MainWindow::stopCaptureScript);\n \n \tif (camSelectDialog_->exec() == QDialog::Accepted) {\n \t\tstd::string cameraId = camSelectDialog_->getCameraId();\n \t\tcameraSwitchButton_->setText(QString::fromStdString(cameraId));\n \n+\t\tscriptPath_ = camSelectDialog_->getCaptureScript();\n+\t\tloadCaptureScript();\n+\n \t\treturn cameraId;\n \t} else\n \t\treturn std::string();\n@@ -504,6 +550,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 +830,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 7982939e..01466e28 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -28,6 +28,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@@ -90,6 +91,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 70615e92..80c97cc5 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@@ -38,6 +39,7 @@ qcam_resources = files([\n qcam_deps = [\n     libatomic,\n     libcamera_public,\n+    libyaml,\n     qt5_dep,\n ]\n \n",
    "prefixes": [
        "libcamera-devel",
        "v6",
        "2/4"
    ]
}