[libcamera-devel,v3,14/22] libcamera: pipeline: raspberrypi: Filter out unsupported formats

Message ID 20200704133140.1738660-15-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • Clean up formats in v4l2-compat and pipeline handlers
Related show

Commit Message

Paul Elder July 4, 2020, 1:31 p.m. UTC
Unsupported formats should not be added to the configuration when
generating the configuration. Filter them out.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
No change in v3
---
 src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Laurent Pinchart July 4, 2020, 9:23 p.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Sat, Jul 04, 2020 at 10:31:32PM +0900, Paul Elder wrote:
> Unsupported formats should not be added to the configuration when
> generating the configuration. Filter them out.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> 
> ---
> No change in v3
> ---
>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> index cbb6f1c..18d068a 100644
> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
> @@ -569,13 +569,11 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
>  
>  		/* Translate the V4L2PixelFormat to PixelFormat. */
>  		std::map<PixelFormat, std::vector<SizeRange>> deviceFormats;
> -		std::transform(fmts.begin(), fmts.end(), std::inserter(deviceFormats, deviceFormats.end()),
> -			       [&](const decltype(fmts)::value_type &format) {
> -					return decltype(deviceFormats)::value_type{
> -						format.first.toPixelFormat(),
> -						format.second
> -					};
> -			       });
> +		for (auto format : fmts) {

		for (const auto &format : fmts) {

> +			PixelFormat pixelFormat = format.first.toPixelFormat();
> +			if (pixelFormat.isValid())
> +				deviceFormats[pixelFormat] = format.second;
> +		}

I wonder if newer C++ versions will get a std::transform_if(), or if
global mind sanity will prevail :-)

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>  		/* Add the stream format based on the device node used for the use case. */
>  		StreamFormats formats(deviceFormats);

Patch

diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index cbb6f1c..18d068a 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -569,13 +569,11 @@  CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
 
 		/* Translate the V4L2PixelFormat to PixelFormat. */
 		std::map<PixelFormat, std::vector<SizeRange>> deviceFormats;
-		std::transform(fmts.begin(), fmts.end(), std::inserter(deviceFormats, deviceFormats.end()),
-			       [&](const decltype(fmts)::value_type &format) {
-					return decltype(deviceFormats)::value_type{
-						format.first.toPixelFormat(),
-						format.second
-					};
-			       });
+		for (auto format : fmts) {
+			PixelFormat pixelFormat = format.first.toPixelFormat();
+			if (pixelFormat.isValid())
+				deviceFormats[pixelFormat] = format.second;
+		}
 
 		/* Add the stream format based on the device node used for the use case. */
 		StreamFormats formats(deviceFormats);