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

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Oct 18 22:59:55 CEST 2024


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 at 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 at ideasonboard.com>
> 
> >         else
> >                 cameraName = chooseCamera();
> >  

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list