[libcamera-devel] [PATCH v7 8/8] qcam: Add --script to load capture script

Utkarsh Tiwari utkarsh02t at gmail.com
Wed Aug 10 06:34:36 CEST 2022


On Wed, Aug 10, 2022 at 2:23 AM Utkarsh Tiwari <utkarsh02t at gmail.com> wrote:

> Add --script as an individual option to load capture scripts.
> Load the capture script before starting the capture.
>
> If an invalid capture script has been given, display an critical error
> QMessageBox and close the application.
>
> Signed-off-by: Utkarsh Tiwari <utkarsh02t at gmail.com>
> ---
> Difference:
>         1. firstCameraSelect_  newly introduced to keep track if its the
>                 first time dialog is been opened.
>

The firstCameraSelect_ should be done in the patch 3/8


>  src/qcam/main.cpp        |  3 +++
>  src/qcam/main_window.cpp | 16 ++++++++++++++--
>  src/qcam/main_window.h   |  2 ++
>  3 files changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp
> index d3f01a85..91166be5 100644
> --- a/src/qcam/main.cpp
> +++ b/src/qcam/main.cpp
> @@ -43,6 +43,9 @@ OptionsParser::Options parseOptions(int argc, char
> *argv[])
>                          "Set configuration of a camera stream", "stream",
> true);
>         parser.addOption(OptVerbose, OptionNone,
>                          "Print verbose log messages", "verbose");
> +       parser.addOption(OptCaptureScript, OptionString,
> +                        "Load a capture session configuration script from
> a file",
> +                        "script", ArgumentRequired, "script");
>
>         OptionsParser::Options options = parser.parse(argc, argv);
>         if (options.isSet(OptHelp))
> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
> index f2e3c576..d6ad0083 100644
> --- a/src/qcam/main_window.cpp
> +++ b/src/qcam/main_window.cpp
> @@ -100,7 +100,7 @@ private:
>
>  MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options
> &options)
>         : saveRaw_(nullptr), options_(options), cm_(cm),
> allocator_(nullptr),
> -         isCapturing_(false), captureRaw_(false)
> +         isCapturing_(false), captureRaw_(false), firstCameraSelect_(true)
>  {
>         int ret;
>
> @@ -146,6 +146,9 @@ MainWindow::MainWindow(CameraManager *cm, const
> OptionsParser::Options &options)
>         cm_->cameraAdded.connect(this, &MainWindow::addCamera);
>         cm_->cameraRemoved.connect(this, &MainWindow::removeCamera);
>
> +       if (options_.isSet(OptCaptureScript))
> +               scriptPath_ = options_[OptCaptureScript].toString();
> +
>         /* Open the camera and start capture. */
>         ret = openCamera();
>         if (ret < 0) {
> @@ -324,6 +327,13 @@ void MainWindow::loadCaptureScript()
>                 QMessageBox::critical(this, "Invalid Script",
>                                       "Couldn't load the capture script");
>
> +               /*
> +                * Close the camera if started by command line and its the
> first capture
> +                * script.
> +                */
> +               if (firstCameraSelect_ && options_.isSet(OptCaptureScript))
> +                       quit();
> +
>         } else
>                 cameraSelectorDialog_->informScriptRunning(scriptPath_);
>
> @@ -347,8 +357,10 @@ std::string MainWindow::chooseCamera()
>          * Use the camera specified on the command line, if any, or
> display the
>          * camera selection dialog box otherwise.
>          */
> -       if (options_.isSet(OptCamera))
> +       if (firstCameraSelect_ && options_.isSet(OptCamera)) {
> +               firstCameraSelect_ = false;
>                 return static_cast<std::string>(options_[OptCamera]);
> +       }
>
>         if (cameraSelectorDialog_->exec() == QDialog::Accepted) {
>                 std::string cameraId =
> cameraSelectorDialog_->getCameraId();
> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
> index 887f1db1..3a264f96 100644
> --- a/src/qcam/main_window.h
> +++ b/src/qcam/main_window.h
> @@ -46,6 +46,7 @@ enum {
>         OptRenderer = 'r',
>         OptStream = 's',
>         OptVerbose = 'v',
> +       OptCaptureScript = 256,
>  };
>
>  class MainWindow : public QMainWindow
> @@ -123,6 +124,7 @@ private:
>         /* Capture state, buffers queue and statistics */
>         bool isCapturing_;
>         bool captureRaw_;
> +       bool firstCameraSelect_;
>         libcamera::Stream *vfStream_;
>         libcamera::Stream *rawStream_;
>         std::map<const libcamera::Stream *, QQueue<libcamera::FrameBuffer
> *>> freeBuffers_;
> --
> 2.25.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20220810/fd4ee016/attachment.htm>


More information about the libcamera-devel mailing list