[PATCH v2] qcam: Automatically select the camera if only one is available

Kieran Bingham kieran.bingham at ideasonboard.com
Sun Oct 20 13:03:30 CEST 2024


Quoting Stanislaw Gruszka (2024-10-19 11:09:25)
> When only a single camera is available, showing the camera selection
> dialog is unnecessary. It's better to automatically select the available
> camera without prompting the user for input.
> 
> Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka at linux.intel.com>
> ---
> v2:
> - Avoid cameras().size() vs cameras()[0] race condition
> - Update in code comment
> 
>  src/apps/qcam/main_window.cpp | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
> index 5144c6b3..86ffa205 100644
> --- a/src/apps/qcam/main_window.cpp
> +++ b/src/apps/qcam/main_window.cpp
> @@ -296,14 +296,23 @@ std::string MainWindow::chooseCamera()
>  int MainWindow::openCamera()
>  {
>         std::string cameraName;
> +       int num = 0;
>  
>         /*
> -        * Use the camera specified on the command line, if any, or display the
> -        * camera selection dialog box otherwise.
> +        * Use the camera specified on the command line, if any, or select the
> +        * only one available, otherwise display the camera selection dialog box.
>          */
> -       if (options_.isSet(OptCamera))
> +       if (options_.isSet(OptCamera)) {
>                 cameraName = static_cast<std::string>(options_[OptCamera]);
> -       else
> +       } else {
> +               for (const auto &cam : cm_->cameras()) {
> +                       num++;
> +                       if (num > 1)

Really trivial nit but I would have probably put 'if (++num > 1)' here
to remove a line.

But that's no reason to worry.

The fact that we make it so easy for Laurent to worry about TOCTOU here
means that's probably just unfriendly in the libcamera API. I don't know
how to make it easier at the moment though ... so


Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> +                               break;
> +                       cameraName = cam->id();
> +               }
> +       }
> +       if (num > 1)
>                 cameraName = chooseCamera();
>  
>         if (cameraName == "")
> -- 
> 2.43.0
>


More information about the libcamera-devel mailing list