<div dir="ltr"><div dir="ltr" class="gmail_attr">On Sun, Jul 3, 2022 at 12:37 PM Utkarsh Tiwari <<a href="mailto:utkarsh02t@gmail.com" target="_blank">utkarsh02t@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Implement an Open Capture Script button which would allow the user<br>
to open a Capture Script (*.yaml).<br>
This button has two states Open and Stop.<br>
<br>
Open state allows user to load a capture script.<br>
When clicked in open state present them with a QFileDialog<br>
to allow user to select a single file.<br>
<br>
Stop state stops the execution of the current capture script.<br>
<br>
Introduce a queueCount_ to keep track of the requests queued.<br>
<br>
When stopping the execution no count is reset and the<br>
capture continues as it is.<br>
<br>
Requests are queued with any controls the script matching<br>
the current queueCount_<br>
<br>
Signed-off-by: Utkarsh Tiwari <<a href="mailto:utkarsh02t@gmail.com" target="_blank">utkarsh02t@gmail.com</a>><br>
Reviewed-by: Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank">kieran.bingham@ideasonboard.com</a>><br>
---<br>
 src/qcam/assets/feathericons/feathericons.qrc |  2 +<br>
 src/qcam/main_window.cpp                      | 68 +++++++++++++++++++<br>
 src/qcam/main_window.h                        |  6 ++<br>
 src/qcam/meson.build                          |  2 +<br>
 4 files changed, 78 insertions(+)<br>
<br>
diff --git a/src/qcam/assets/feathericons/feathericons.qrc b/src/qcam/assets/feathericons/feathericons.qrc<br>
index c5302040..6b08395a 100644<br>
--- a/src/qcam/assets/feathericons/feathericons.qrc<br>
+++ b/src/qcam/assets/feathericons/feathericons.qrc<br>
@@ -3,9 +3,11 @@<br>
 <qresource><br>
        <file>aperture.svg</file><br>
        <file>camera-off.svg</file><br>
+       <file>file.svg</file><br>
        <file>play-circle.svg</file><br>
        <file>save.svg</file><br>
        <file>stop-circle.svg</file><br>
        <file>x-circle.svg</file><br>
+       <file>x-square.svg</file><br>
 </qresource><br>
 </RCC><br>
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp<br>
index adeb3181..4fbaeccc 100644<br>
--- a/src/qcam/main_window.cpp<br>
+++ b/src/qcam/main_window.cpp<br>
@@ -20,6 +20,7 @@<br>
 #include <QImage><br>
 #include <QImageWriter><br>
 #include <QInputDialog><br>
+#include <QMessageBox><br>
 #include <QMutexLocker><br>
 #include <QStandardPaths><br>
 #include <QStringList><br>
@@ -232,6 +233,13 @@ int MainWindow::createToolbars()<br>
        saveRaw_ = action;<br>
 #endif<br>
<br>
+       /* Open Script... action. */<br>
+       action = toolbar_->addAction(QIcon::fromTheme("document-open",<br>
+                                                     QIcon(":file.svg")),<br>
+                                    "Open Capture Script");<br>
+       connect(action, &QAction::triggered, this, &MainWindow::chooseScript);<br>
+       scriptExecAction_ = action;<br>
+<br>
        return 0;<br>
 }<br>
<br>
@@ -255,6 +263,60 @@ void MainWindow::updateTitle()<br>
        setWindowTitle(title_ + " : " + QString::number(fps, 'f', 2) + " fps");<br>
 }<br>
<br>
+/**<br>
+ * \brief Load a capture script for handling the capture session.<br>
+ *<br>
+ * If already capturing, it would restart the capture.<br>
+ */<br>
+void MainWindow::chooseScript()<br>
+{<br>
+       if (script_) {<br>
+               /*<br>
+                * This is the second valid press of load script button,<br>
+                * It indicates stopping, Stop and set button for new script.<br>
+                */<br>
+               script_.reset();<br>
+               scriptExecAction_->setIcon(QIcon::fromTheme("document-open",<br>
+                                                           QIcon(":file.svg")));<br>
+               scriptExecAction_->setText("Open Capture Script");<br>
+               return;<br>
+       }<br>
+<br>
+       QString scriptFile = QFileDialog::getOpenFileName(this, "Open Capture Script", QDir::currentPath(),<br>
+                                                         "Capture Script (*.yaml)");<br>
+       if (scriptFile.isEmpty())<br>
+               return;<br>
+<br>
+       /*<br>
+        * If we are already capturing,<br>
+        * stop so we don't have stuck image in viewfinder.<br>
+        */<br>
+       bool wasCapturing = isCapturing_;<br>
+       if (isCapturing_)<br>
+               toggleCapture(false);<br>
+<br>
+       script_ = std::make_unique<CaptureScript>(camera_, scriptFile.toStdString());<br>
+       if (!script_->valid()) {<br>
+               script_.reset();<br>
+               QMessageBox::critical(this, "Invalid Script",<br>
+                                             "Couldn't load the capture script");<br></blockquote><div><br></div><div>This is wrongly indented  and should be</div><div><pre style="color:rgb(0,0,0);background:rgb(255,255,255) none repeat scroll 0% 0%">              <span style="color:rgb(96,48,0)">QMessageBox</span><span style="color:rgb(128,0,128)">::</span>critical<span style="color:rgb(128,128,48)">(</span><span style="color:rgb(128,0,0);font-weight:bold">this</span><span style="color:rgb(128,128,48)">,</span> <span style="color:rgb(128,0,0)">"</span><span style="color:rgb(0,0,230)">Invalid Script</span><span style="color:rgb(128,0,0)">"</span><span style="color:rgb(128,128,48)">,</span>
                                      <span style="color:rgb(128,0,0)">"</span><span style="color:rgb(0,0,230)">Couldn't load the capture script</span><span style="color:rgb(128,0,0)">"</span><span style="color:rgb(128,128,48)">)</span><span style="color:rgb(128,0,128)">;</span> </pre></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+               if (wasCapturing)<br>
+                       toggleCapture(true);<br>
+               return;<br>
+       }<br>
+<br>
+       /*<br>
+        * Valid script verified<br>
+        * Set the button to indicate stopping availibility.<br>
+        */<br>
+       scriptExecAction_->setIcon(QIcon(":x-square.svg"));<br>
+       scriptExecAction_->setText("Stop Script execution");<br>
+<br>
+       /* Start capture again if we were capturing before. */<br>
+       if (wasCapturing)<br>
+               toggleCapture(true);<br>
+}<br>
+<br>
 /* -----------------------------------------------------------------------------<br>
  * Camera Selection<br>
  */<br>
@@ -510,6 +572,7 @@ int MainWindow::startCapture()<br>
        previousFrames_ = 0;<br>
        framesCaptured_ = 0;<br>
        lastBufferTime_ = 0;<br>
+       queueCount_ = 0;<br>
<br>
        ret = camera_->start();<br>
        if (ret) {<br>
@@ -789,5 +852,10 @@ void MainWindow::renderComplete(FrameBuffer *buffer)<br>
<br>
 int MainWindow::queueRequest(Request *request)<br>
 {<br>
+       if (script_)<br>
+               request->controls() = script_->frameControls(queueCount_);<br>
+<br>
+       queueCount_++;<br>
+<br>
        return camera_->queueRequest(request);<br>
 }<br>
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h<br>
index c3e4b665..2cdf7169 100644<br>
--- a/src/qcam/main_window.h<br>
+++ b/src/qcam/main_window.h<br>
@@ -26,6 +26,7 @@<br>
 #include <libcamera/request.h><br>
 #include <libcamera/stream.h><br>
<br>
+#include "../cam/capture_script.h"<br>
 #include "../cam/stream_options.h"<br>
 #include "viewfinder.h"<br>
<br>
@@ -86,11 +87,14 @@ private:<br>
        void processHotplug(HotplugEvent *e);<br>
        void processViewfinder(libcamera::FrameBuffer *buffer);<br>
<br>
+       void chooseScript();<br>
+<br>
        /* UI elements */<br>
        QToolBar *toolbar_;<br>
        QAction *startStopAction_;<br>
        QComboBox *cameraCombo_;<br>
        QAction *saveRaw_;<br>
+       QAction *scriptExecAction_;<br>
        ViewFinder *viewfinder_;<br>
<br>
        QIcon iconPlay_;<br>
@@ -124,6 +128,8 @@ private:<br>
        QElapsedTimer frameRateInterval_;<br>
        uint32_t previousFrames_;<br>
        uint32_t framesCaptured_;<br>
+       uint32_t queueCount_;<br>
<br>
        std::vector<std::unique_ptr<libcamera::Request>> requests_;<br>
+       std::unique_ptr<CaptureScript> script_;<br>
 };<br>
diff --git a/src/qcam/meson.build b/src/qcam/meson.build<br>
index c46f4631..67074252 100644<br>
--- a/src/qcam/meson.build<br>
+++ b/src/qcam/meson.build<br>
@@ -15,6 +15,7 @@ endif<br>
 qcam_enabled = true<br>
<br>
 qcam_sources = files([<br>
+    '../cam/capture_script.cpp',<br>
     '../cam/image.cpp',<br>
     '../cam/options.cpp',<br>
     '../cam/stream_options.cpp',<br>
@@ -37,6 +38,7 @@ qcam_resources = files([<br>
 qcam_deps = [<br>
     libatomic,<br>
     libcamera_public,<br>
+    libyaml,<br>
     qt5_dep,<br>
 ]<br>
<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div></div>