[libcamera-devel,2/2] qcam: main_window: Prefer stream formats that don't require conversion

Message ID 20200324103012.9678-2-laurent.pinchart@ideasonboard.com
State Accepted
Commit e74885c870a8d13736b422f8faadec3339cc588d
Headers show
Series
  • [libcamera-devel,1/2] qcam: viewfinder: Report the natively supported pixel formats
Related show

Commit Message

Laurent Pinchart March 24, 2020, 10:30 a.m. UTC
Query the viewfinder for the formats it supports natively, and select
one of them for the stream if possible.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/qcam/main_window.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Kieran Bingham March 24, 2020, 12:41 p.m. UTC | #1
Hi Laurent,

On 24/03/2020 10:30, Laurent Pinchart wrote:
> Query the viewfinder for the formats it supports natively, and select
> one of them for the stream if possible.

This should help improve performances indeed!

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

> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/qcam/main_window.cpp | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
> index b13660bccb25..565732698a5e 100644
> --- a/src/qcam/main_window.cpp
> +++ b/src/qcam/main_window.cpp
> @@ -297,6 +297,19 @@ int MainWindow::startCapture()
>  		}
>  	}
>  
> +	/* Use a format supported by the viewfinder if available. */
> +	std::vector<PixelFormat> formats = cfg.formats().pixelformats();

That's just a reference right? Not a full copy of the pixelformats() table?

> +	for (const PixelFormat &format : viewfinder_->nativeFormats()) {
> +		auto match = std::find_if(formats.begin(), formats.end(),
> +					  [&](const PixelFormat &f) {
> +						  return f == format;
> +					  });
> +		if (match != formats.end()) {
> +			cfg.pixelFormat = format;
> +			break;
> +		}
> +	}
> +
>  	CameraConfiguration::Status validation = config_->validate();
>  	if (validation == CameraConfiguration::Invalid) {
>  		qWarning() << "Failed to create valid camera configuration";
>
Laurent Pinchart March 24, 2020, 12:52 p.m. UTC | #2
Hi Kieran,

On Tue, Mar 24, 2020 at 12:41:13PM +0000, Kieran Bingham wrote:
> On 24/03/2020 10:30, Laurent Pinchart wrote:
> > Query the viewfinder for the formats it supports natively, and select
> > one of them for the stream if possible.
> 
> This should help improve performances indeed!
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  src/qcam/main_window.cpp | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> > 
> > diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
> > index b13660bccb25..565732698a5e 100644
> > --- a/src/qcam/main_window.cpp
> > +++ b/src/qcam/main_window.cpp
> > @@ -297,6 +297,19 @@ int MainWindow::startCapture()
> >  		}
> >  	}
> >  
> > +	/* Use a format supported by the viewfinder if available. */
> > +	std::vector<PixelFormat> formats = cfg.formats().pixelformats();
> 
> That's just a reference right? Not a full copy of the pixelformats() table?

No, it's a copy, as StreamFormats doesn't store a vector of
PixelFormats, but a map. The vector is constructed at runtime.

> > +	for (const PixelFormat &format : viewfinder_->nativeFormats()) {
> > +		auto match = std::find_if(formats.begin(), formats.end(),
> > +					  [&](const PixelFormat &f) {
> > +						  return f == format;
> > +					  });
> > +		if (match != formats.end()) {
> > +			cfg.pixelFormat = format;
> > +			break;
> > +		}
> > +	}
> > +
> >  	CameraConfiguration::Status validation = config_->validate();
> >  	if (validation == CameraConfiguration::Invalid) {
> >  		qWarning() << "Failed to create valid camera configuration";

Patch

diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index b13660bccb25..565732698a5e 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -297,6 +297,19 @@  int MainWindow::startCapture()
 		}
 	}
 
+	/* Use a format supported by the viewfinder if available. */
+	std::vector<PixelFormat> formats = cfg.formats().pixelformats();
+	for (const PixelFormat &format : viewfinder_->nativeFormats()) {
+		auto match = std::find_if(formats.begin(), formats.end(),
+					  [&](const PixelFormat &f) {
+						  return f == format;
+					  });
+		if (match != formats.end()) {
+			cfg.pixelFormat = format;
+			break;
+		}
+	}
+
 	CameraConfiguration::Status validation = config_->validate();
 	if (validation == CameraConfiguration::Invalid) {
 		qWarning() << "Failed to create valid camera configuration";