[libcamera-devel] cam: Create stream names after configuring the camera

Message ID 20200316020109.2466468-1-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • [libcamera-devel] cam: Create stream names after configuring the camera
Related show

Commit Message

Niklas Söderlund March 16, 2020, 2:01 a.m. UTC
The stream in the stream configuration is not filled in before we
configure the camera, move the generating and caching of names after the
configuration.

Without this fix writing multiple streams to disk overwrites the frames
as the filenames are not unique.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/cam/capture.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Laurent Pinchart March 16, 2020, 7:43 a.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Mon, Mar 16, 2020 at 03:01:09AM +0100, Niklas Söderlund wrote:
> The stream in the stream configuration is not filled in before we
> configure the camera, move the generating and caching of names after the
> configuration.
> 
> Without this fix writing multiple streams to disk overwrites the frames
> as the filenames are not unique.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

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

> ---
>  src/cam/capture.cpp | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp
> index b62a9b24b2169b05..55fa2dabcee97f21 100644
> --- a/src/cam/capture.cpp
> +++ b/src/cam/capture.cpp
> @@ -30,18 +30,18 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)
>  		return -ENODEV;
>  	}
>  
> +	ret = camera_->configure(config_);
> +	if (ret < 0) {
> +		std::cout << "Failed to configure camera" << std::endl;
> +		return ret;
> +	}
> +
>  	streamName_.clear();
>  	for (unsigned int index = 0; index < config_->size(); ++index) {
>  		StreamConfiguration &cfg = config_->at(index);
>  		streamName_[cfg.stream()] = "stream" + std::to_string(index);
>  	}
>  
> -	ret = camera_->configure(config_);
> -	if (ret < 0) {
> -		std::cout << "Failed to configure camera" << std::endl;
> -		return ret;
> -	}
> -
>  	camera_->requestCompleted.connect(this, &Capture::requestComplete);
>  
>  	if (options.isSet(OptFile)) {
Niklas Söderlund March 18, 2020, 3:22 a.m. UTC | #2
Hi,

I have now pushed this patch to master.

On 2020-03-16 03:01:09 +0100, Niklas Söderlund wrote:
> The stream in the stream configuration is not filled in before we
> configure the camera, move the generating and caching of names after the
> configuration.
> 
> Without this fix writing multiple streams to disk overwrites the frames
> as the filenames are not unique.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/cam/capture.cpp | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp
> index b62a9b24b2169b05..55fa2dabcee97f21 100644
> --- a/src/cam/capture.cpp
> +++ b/src/cam/capture.cpp
> @@ -30,18 +30,18 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)
>  		return -ENODEV;
>  	}
>  
> +	ret = camera_->configure(config_);
> +	if (ret < 0) {
> +		std::cout << "Failed to configure camera" << std::endl;
> +		return ret;
> +	}
> +
>  	streamName_.clear();
>  	for (unsigned int index = 0; index < config_->size(); ++index) {
>  		StreamConfiguration &cfg = config_->at(index);
>  		streamName_[cfg.stream()] = "stream" + std::to_string(index);
>  	}
>  
> -	ret = camera_->configure(config_);
> -	if (ret < 0) {
> -		std::cout << "Failed to configure camera" << std::endl;
> -		return ret;
> -	}
> -
>  	camera_->requestCompleted.connect(this, &Capture::requestComplete);
>  
>  	if (options.isSet(OptFile)) {
> -- 
> 2.25.1
>

Patch

diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp
index b62a9b24b2169b05..55fa2dabcee97f21 100644
--- a/src/cam/capture.cpp
+++ b/src/cam/capture.cpp
@@ -30,18 +30,18 @@  int Capture::run(EventLoop *loop, const OptionsParser::Options &options)
 		return -ENODEV;
 	}
 
+	ret = camera_->configure(config_);
+	if (ret < 0) {
+		std::cout << "Failed to configure camera" << std::endl;
+		return ret;
+	}
+
 	streamName_.clear();
 	for (unsigned int index = 0; index < config_->size(); ++index) {
 		StreamConfiguration &cfg = config_->at(index);
 		streamName_[cfg.stream()] = "stream" + std::to_string(index);
 	}
 
-	ret = camera_->configure(config_);
-	if (ret < 0) {
-		std::cout << "Failed to configure camera" << std::endl;
-		return ret;
-	}
-
 	camera_->requestCompleted.connect(this, &Capture::requestComplete);
 
 	if (options.isSet(OptFile)) {