<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 26 Jul, 2022, 00:14 Umang Jain, <<a href="mailto:umang.jain@ideasonboard.com">umang.jain@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Utkarsh,<br>
<br>
On 7/3/22 10:07, Utkarsh Tiwari via libcamera-devel wrote:<br>
> 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>
<br>
So there are two states of stop(s) ? One would stop the capture script <br>
and other one would stop the camera? Is my understanding correct?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">No, the two states of the button are </div><div dir="auto">- Open Capture Script</div><div dir="auto">- Stop the current capture script</div><div dir="auto"><br></div><div dir="auto">The open state allows the user to select a capture script to execute.</div><div dir="auto"><br></div><div dir="auto">The stop state is visible when the user has loaded a capture script either </div><div dir="auto">through cmdline or through the button. This state allows to stop the</div><div dir="auto">current script.</div><div dir="auto"><br></div><div dir="auto">Should reword the commit message ? </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><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" rel="noreferrer">utkarsh02t@gmail.com</a>><br>
> Reviewed-by: Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank" rel="noreferrer">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>
> + 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>
</blockquote></div></div></div>