qcam: Automatically select the camera if only one is available
diff mbox series

Message ID 20241018142916.23578-1-stanislaw.gruszka@linux.intel.com
State Superseded
Headers show
Series
  • qcam: Automatically select the camera if only one is available
Related show

Commit Message

Stanislaw Gruszka Oct. 18, 2024, 2:29 p.m. UTC
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@linux.intel.com>
---
 src/apps/qcam/main_window.cpp | 2 ++
 1 file changed, 2 insertions(+)

Comments

Kieran Bingham Oct. 18, 2024, 2:31 p.m. UTC | #1
Quoting Stanislaw Gruszka (2024-10-18 15:29:16)
> 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@linux.intel.com>
> ---
>  src/apps/qcam/main_window.cpp | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
> index 5144c6b3..b0dfd850 100644
> --- a/src/apps/qcam/main_window.cpp
> +++ b/src/apps/qcam/main_window.cpp
> @@ -303,6 +303,8 @@ int MainWindow::openCamera()
>          */
>         if (options_.isSet(OptCamera))
>                 cameraName = static_cast<std::string>(options_[OptCamera]);
> +       else if (cm_->cameras().size() == 1)
> +               cameraName = cm_->cameras()[0]->id();

I'm sold on that. I've wanted to do the same for some time ;-)

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

>         else
>                 cameraName = chooseCamera();
>  
> -- 
> 2.43.0
>
Laurent Pinchart Oct. 18, 2024, 8:59 p.m. UTC | #2
On Fri, Oct 18, 2024 at 03:31:40PM +0100, Kieran Bingham wrote:
> Quoting Stanislaw Gruszka (2024-10-18 15:29:16)
> > 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@linux.intel.com>
> > ---
> >  src/apps/qcam/main_window.cpp | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
> > index 5144c6b3..b0dfd850 100644
> > --- a/src/apps/qcam/main_window.cpp
> > +++ b/src/apps/qcam/main_window.cpp
> > @@ -303,6 +303,8 @@ int MainWindow::openCamera()
> >          */
> >         if (options_.isSet(OptCamera))
> >                 cameraName = static_cast<std::string>(options_[OptCamera]);
> > +       else if (cm_->cameras().size() == 1)
> > +               cameraName = cm_->cameras()[0]->id();

There's a TOC-TOU race, this will crash if the camera is unplugged
between the check and use.

> 
> I'm sold on that. I've wanted to do the same for some time ;-)
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> >         else
> >                 cameraName = chooseCamera();
> >

Patch
diff mbox series

diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
index 5144c6b3..b0dfd850 100644
--- a/src/apps/qcam/main_window.cpp
+++ b/src/apps/qcam/main_window.cpp
@@ -303,6 +303,8 @@  int MainWindow::openCamera()
 	 */
 	if (options_.isSet(OptCamera))
 		cameraName = static_cast<std::string>(options_[OptCamera]);
+	else if (cm_->cameras().size() == 1)
+		cameraName = cm_->cameras()[0]->id();
 	else
 		cameraName = chooseCamera();