[libcamera-devel,08/15] v4l2: v4l2_camera: Re-validate configuration after adjusted

Message ID 20200616131244.70308-9-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • Support v4l2-compliance
Related show

Commit Message

Paul Elder June 16, 2020, 1:12 p.m. UTC
If the camera configuration has been adjusted, validate it again to
ensure that it's valid, before configuring the camera with it.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 src/v4l2/v4l2_camera.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Laurent Pinchart June 17, 2020, 1:10 a.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Tue, Jun 16, 2020 at 10:12:37PM +0900, Paul Elder wrote:
> If the camera configuration has been adjusted, validate it again to
> ensure that it's valid, before configuring the camera with it.

This shouldn't be needed, an adjusted configuration is supposed to be
valid. If that's not the case, it's a bug in the pipeline handler (in
which case a unit test should be added to catch this, in addition to
fixing the bug).

> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
>  src/v4l2/v4l2_camera.cpp | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp
> index 2557320..fdbf461 100644
> --- a/src/v4l2/v4l2_camera.cpp
> +++ b/src/v4l2/v4l2_camera.cpp
> @@ -119,11 +119,18 @@ int V4L2Camera::configure(StreamConfiguration *streamConfigOut,
>  		LOG(V4L2Compat, Debug) << "Configuration invalid";
>  		return -EINVAL;
>  	}
> -	if (validation == CameraConfiguration::Adjusted)
> +	if (validation == CameraConfiguration::Adjusted) {
>  		LOG(V4L2Compat, Debug) << "Configuration adjusted";
> +		validation = config_->validate();
> +		if (validation != CameraConfiguration::Valid) {
> +			LOG(V4L2Compat, Error)
> +				<< "Configuration adjusted but not valid";
> +			return -EINVAL;
> +		}
> +	}
>  
> -	LOG(V4L2Compat, Debug) << "Validated configuration is: "
> -			      << streamConfig.toString();
> +	LOG(V4L2Compat, Debug)
> +		<< "Validated configuration is: " << streamConfig.toString();
>  
>  	int ret = camera_->configure(config_.get());
>  	if (ret < 0)

Patch

diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp
index 2557320..fdbf461 100644
--- a/src/v4l2/v4l2_camera.cpp
+++ b/src/v4l2/v4l2_camera.cpp
@@ -119,11 +119,18 @@  int V4L2Camera::configure(StreamConfiguration *streamConfigOut,
 		LOG(V4L2Compat, Debug) << "Configuration invalid";
 		return -EINVAL;
 	}
-	if (validation == CameraConfiguration::Adjusted)
+	if (validation == CameraConfiguration::Adjusted) {
 		LOG(V4L2Compat, Debug) << "Configuration adjusted";
+		validation = config_->validate();
+		if (validation != CameraConfiguration::Valid) {
+			LOG(V4L2Compat, Error)
+				<< "Configuration adjusted but not valid";
+			return -EINVAL;
+		}
+	}
 
-	LOG(V4L2Compat, Debug) << "Validated configuration is: "
-			      << streamConfig.toString();
+	LOG(V4L2Compat, Debug)
+		<< "Validated configuration is: " << streamConfig.toString();
 
 	int ret = camera_->configure(config_.get());
 	if (ret < 0)