[libcamera-devel,v5,2/3] android: camera_device: Use Camera3StreamConfig in configureStreams()
diff mbox series

Message ID 20201209055410.3232987-2-hiroh@chromium.org
State Superseded
Headers show
Series
  • [libcamera-devel,v5,1/3] android: camera_device: Introduce Camera3StreamConfig
Related show

Commit Message

Hirokazu Honda Dec. 9, 2020, 5:54 a.m. UTC
Use the newly introduced Camera3StreamConfig to associate the
Android requested streams with the associated StreamConfiguration
in a vector of configurations.

This change prepares to sort the vector of configuration before using
it to configure the Camera and populate the streams_ vector.

No functional changes intended.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/android/camera_device.cpp | 52 +++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 21 deletions(-)

--
2.29.2.576.ga3fc446d84-goog

Comments

Kieran Bingham Dec. 9, 2020, 10:51 a.m. UTC | #1
Hi Hiro,

On 09/12/2020 05:54, Hirokazu Honda wrote:
> Use the newly introduced Camera3StreamConfig to associate the
> Android requested streams with the associated StreamConfiguration
> in a vector of configurations.
> 
> This change prepares to sort the vector of configuration before using
> it to configure the Camera and populate the streams_ vector.
> 
> No functional changes intended.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

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

> ---
>  src/android/camera_device.cpp | 52 +++++++++++++++++++++--------------
>  1 file changed, 31 insertions(+), 21 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 09269d95..b7bf3d88 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1240,6 +1240,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  	streams_.clear();
>  	streams_.reserve(stream_list->num_streams);
> 
> +	std::vector<Camera3StreamConfig> streamConfigs;
> +	streamConfigs.reserve(stream_list->num_streams);
> +
>  	/* First handle all non-MJPEG streams. */
>  	camera3_stream_t *jpegStream = nullptr;
>  	for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
> @@ -1270,14 +1273,12 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  			continue;
>  		}
> 
> -		StreamConfiguration streamConfiguration;
> -		streamConfiguration.size = size;
> -		streamConfiguration.pixelFormat = format;
> -
> -		config_->addConfiguration(streamConfiguration);
> -		streams_.emplace_back(this, CameraStream::Type::Direct,
> -				      stream, config_->size() - 1);
> -		stream->priv = static_cast<void *>(&streams_.back());
> +		Camera3StreamConfig streamConfig;
> +		streamConfig.streams = { stream };
> +		streamConfig.types = { CameraStream::Type::Direct };
> +		streamConfig.config.size = size;
> +		streamConfig.config.pixelFormat = format;
> +		streamConfigs.push_back(std::move(streamConfig));
>  	}
> 
>  	/* Now handle the MJPEG streams, adding a new stream if required. */
> @@ -1286,9 +1287,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  		int index = -1;
> 
>  		/* Search for a compatible stream in the non-JPEG ones. */
> -		for (unsigned int i = 0; i < config_->size(); i++) {
> -			StreamConfiguration &cfg = config_->at(i);
> -
> +		for (size_t i = 0; i < streamConfigs.size(); ++i) {
> +			const auto &cfg = streamConfigs[i].config;
>  			/*
>  			 * \todo The PixelFormat must also be compatible with
>  			 * the encoder.
> @@ -1310,28 +1310,38 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  		 * introduce a new stream to satisfy the request requirements.
>  		 */
>  		if (index < 0) {
> -			StreamConfiguration streamConfiguration;
> -
>  			/*
>  			 * \todo The pixelFormat should be a 'best-fit' choice
>  			 * and may require a validation cycle. This is not yet
>  			 * handled, and should be considered as part of any
>  			 * stream configuration reworks.
>  			 */
> -			streamConfiguration.size.width = jpegStream->width;
> -			streamConfiguration.size.height = jpegStream->height;
> -			streamConfiguration.pixelFormat = formats::NV12;
> +			Camera3StreamConfig streamConfig;
> +			streamConfig.config.size.width = jpegStream->width;
> +			streamConfig.config.size.height = jpegStream->height;
> +			streamConfig.config.pixelFormat = formats::NV12;
> +			streamConfigs.push_back(std::move(streamConfig));
> 
> -			LOG(HAL, Info) << "Adding " << streamConfiguration.toString()
> +			LOG(HAL, Info) << "Adding " << streamConfig.config.toString()
>  				       << " for MJPEG support";
> 
>  			type = CameraStream::Type::Internal;
> -			config_->addConfiguration(streamConfiguration);
> -			index = config_->size() - 1;
> +			index = streamConfigs.size() - 1;
>  		}
> 
> -		streams_.emplace_back(this, type, jpegStream, index);
> -		jpegStream->priv = static_cast<void *>(&streams_.back());
> +		streamConfigs[index].streams.push_back(jpegStream);
> +		streamConfigs[index].types.push_back(type);
> +	}
> +
> +	for (const auto &streamConfig : streamConfigs) {
> +		config_->addConfiguration(streamConfig.config);
> +		for (size_t i = 0; i < streamConfig.streams.size(); ++i) {
> +			camera3_stream_t *stream = streamConfig.streams[i];
> +			const CameraStream::Type type = streamConfig.types[i];
> +			streams_.emplace_back(this, type,
> +					      stream, config_->size() - 1);
> +			stream->priv = static_cast<void*>(&streams_.back());
> +		}
>  	}
> 
>  	switch (config_->validate()) {
> --
> 2.29.2.576.ga3fc446d84-goog
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
>
Umang Jain Dec. 9, 2020, 12:45 p.m. UTC | #2
Hi Hiro

On 12/9/20 4:21 PM, Kieran Bingham wrote:
> Hi Hiro,
>
> On 09/12/2020 05:54, Hirokazu Honda wrote:
>> Use the newly introduced Camera3StreamConfig to associate the
>> Android requested streams with the associated StreamConfiguration
>> in a vector of configurations.
>>
>> This change prepares to sort the vector of configuration before using
>> it to configure the Camera and populate the streams_ vector.
>>
>> No functional changes intended.
>>
>> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
>> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Umang Jain <email@uajain.com>
>
>> ---
>>   src/android/camera_device.cpp | 52 +++++++++++++++++++++--------------
>>   1 file changed, 31 insertions(+), 21 deletions(-)
>>
>> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
>> index 09269d95..b7bf3d88 100644
>> --- a/src/android/camera_device.cpp
>> +++ b/src/android/camera_device.cpp
>> @@ -1240,6 +1240,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>>   	streams_.clear();
>>   	streams_.reserve(stream_list->num_streams);
>>
>> +	std::vector<Camera3StreamConfig> streamConfigs;
>> +	streamConfigs.reserve(stream_list->num_streams);
>> +
>>   	/* First handle all non-MJPEG streams. */
>>   	camera3_stream_t *jpegStream = nullptr;
>>   	for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
>> @@ -1270,14 +1273,12 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>>   			continue;
>>   		}
>>
>> -		StreamConfiguration streamConfiguration;
>> -		streamConfiguration.size = size;
>> -		streamConfiguration.pixelFormat = format;
>> -
>> -		config_->addConfiguration(streamConfiguration);
>> -		streams_.emplace_back(this, CameraStream::Type::Direct,
>> -				      stream, config_->size() - 1);
>> -		stream->priv = static_cast<void *>(&streams_.back());
>> +		Camera3StreamConfig streamConfig;
>> +		streamConfig.streams = { stream };
>> +		streamConfig.types = { CameraStream::Type::Direct };
>> +		streamConfig.config.size = size;
>> +		streamConfig.config.pixelFormat = format;
>> +		streamConfigs.push_back(std::move(streamConfig));
>>   	}
>>
>>   	/* Now handle the MJPEG streams, adding a new stream if required. */
>> @@ -1286,9 +1287,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>>   		int index = -1;
>>
>>   		/* Search for a compatible stream in the non-JPEG ones. */
>> -		for (unsigned int i = 0; i < config_->size(); i++) {
>> -			StreamConfiguration &cfg = config_->at(i);
>> -
>> +		for (size_t i = 0; i < streamConfigs.size(); ++i) {
>> +			const auto &cfg = streamConfigs[i].config;
>>   			/*
>>   			 * \todo The PixelFormat must also be compatible with
>>   			 * the encoder.
>> @@ -1310,28 +1310,38 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>>   		 * introduce a new stream to satisfy the request requirements.
>>   		 */
>>   		if (index < 0) {
>> -			StreamConfiguration streamConfiguration;
>> -
>>   			/*
>>   			 * \todo The pixelFormat should be a 'best-fit' choice
>>   			 * and may require a validation cycle. This is not yet
>>   			 * handled, and should be considered as part of any
>>   			 * stream configuration reworks.
>>   			 */
>> -			streamConfiguration.size.width = jpegStream->width;
>> -			streamConfiguration.size.height = jpegStream->height;
>> -			streamConfiguration.pixelFormat = formats::NV12;
>> +			Camera3StreamConfig streamConfig;
>> +			streamConfig.config.size.width = jpegStream->width;
>> +			streamConfig.config.size.height = jpegStream->height;
>> +			streamConfig.config.pixelFormat = formats::NV12;
>> +			streamConfigs.push_back(std::move(streamConfig));
>>
>> -			LOG(HAL, Info) << "Adding " << streamConfiguration.toString()
>> +			LOG(HAL, Info) << "Adding " << streamConfig.config.toString()
>>   				       << " for MJPEG support";
>>
>>   			type = CameraStream::Type::Internal;
>> -			config_->addConfiguration(streamConfiguration);
>> -			index = config_->size() - 1;
>> +			index = streamConfigs.size() - 1;
>>   		}
>>
>> -		streams_.emplace_back(this, type, jpegStream, index);
>> -		jpegStream->priv = static_cast<void *>(&streams_.back());
>> +		streamConfigs[index].streams.push_back(jpegStream);
>> +		streamConfigs[index].types.push_back(type);
>> +	}
>> +
>> +	for (const auto &streamConfig : streamConfigs) {
>> +		config_->addConfiguration(streamConfig.config);
>> +		for (size_t i = 0; i < streamConfig.streams.size(); ++i) {
>> +			camera3_stream_t *stream = streamConfig.streams[i];
>> +			const CameraStream::Type type = streamConfig.types[i];
>> +			streams_.emplace_back(this, type,
>> +					      stream, config_->size() - 1);
>> +			stream->priv = static_cast<void*>(&streams_.back());
>> +		}
>>   	}
>>
>>   	switch (config_->validate()) {
>> --
>> 2.29.2.576.ga3fc446d84-goog
>> _______________________________________________
>> libcamera-devel mailing list
>> libcamera-devel@lists.libcamera.org
>> https://lists.libcamera.org/listinfo/libcamera-devel
>>
Laurent Pinchart Dec. 10, 2020, 9:42 p.m. UTC | #3
Hi Hiro,

Thank you for the patch.

On Wed, Dec 09, 2020 at 05:54:09AM +0000, Hirokazu Honda wrote:
> Use the newly introduced Camera3StreamConfig to associate the
> Android requested streams with the associated StreamConfiguration
> in a vector of configurations.
> 
> This change prepares to sort the vector of configuration before using
> it to configure the Camera and populate the streams_ vector.
> 
> No functional changes intended.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/android/camera_device.cpp | 52 +++++++++++++++++++++--------------
>  1 file changed, 31 insertions(+), 21 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 09269d95..b7bf3d88 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1240,6 +1240,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  	streams_.clear();
>  	streams_.reserve(stream_list->num_streams);
> 
> +	std::vector<Camera3StreamConfig> streamConfigs;
> +	streamConfigs.reserve(stream_list->num_streams);
> +
>  	/* First handle all non-MJPEG streams. */
>  	camera3_stream_t *jpegStream = nullptr;
>  	for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
> @@ -1270,14 +1273,12 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  			continue;
>  		}
> 
> -		StreamConfiguration streamConfiguration;
> -		streamConfiguration.size = size;
> -		streamConfiguration.pixelFormat = format;
> -
> -		config_->addConfiguration(streamConfiguration);
> -		streams_.emplace_back(this, CameraStream::Type::Direct,
> -				      stream, config_->size() - 1);
> -		stream->priv = static_cast<void *>(&streams_.back());
> +		Camera3StreamConfig streamConfig;
> +		streamConfig.streams = { stream };
> +		streamConfig.types = { CameraStream::Type::Direct };
> +		streamConfig.config.size = size;
> +		streamConfig.config.pixelFormat = format;
> +		streamConfigs.push_back(std::move(streamConfig));
>  	}
> 
>  	/* Now handle the MJPEG streams, adding a new stream if required. */
> @@ -1286,9 +1287,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  		int index = -1;
> 
>  		/* Search for a compatible stream in the non-JPEG ones. */
> -		for (unsigned int i = 0; i < config_->size(); i++) {
> -			StreamConfiguration &cfg = config_->at(i);
> -
> +		for (size_t i = 0; i < streamConfigs.size(); ++i) {
> +			const auto &cfg = streamConfigs[i].config;

We can keep the blank line here.

>  			/*
>  			 * \todo The PixelFormat must also be compatible with
>  			 * the encoder.
> @@ -1310,28 +1310,38 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  		 * introduce a new stream to satisfy the request requirements.
>  		 */
>  		if (index < 0) {
> -			StreamConfiguration streamConfiguration;
> -
>  			/*
>  			 * \todo The pixelFormat should be a 'best-fit' choice
>  			 * and may require a validation cycle. This is not yet
>  			 * handled, and should be considered as part of any
>  			 * stream configuration reworks.
>  			 */
> -			streamConfiguration.size.width = jpegStream->width;
> -			streamConfiguration.size.height = jpegStream->height;
> -			streamConfiguration.pixelFormat = formats::NV12;
> +			Camera3StreamConfig streamConfig;
> +			streamConfig.config.size.width = jpegStream->width;
> +			streamConfig.config.size.height = jpegStream->height;
> +			streamConfig.config.pixelFormat = formats::NV12;
> +			streamConfigs.push_back(std::move(streamConfig));
> 
> -			LOG(HAL, Info) << "Adding " << streamConfiguration.toString()
> +			LOG(HAL, Info) << "Adding " << streamConfig.config.toString()
>  				       << " for MJPEG support";
> 
>  			type = CameraStream::Type::Internal;
> -			config_->addConfiguration(streamConfiguration);
> -			index = config_->size() - 1;
> +			index = streamConfigs.size() - 1;
>  		}
> 
> -		streams_.emplace_back(this, type, jpegStream, index);
> -		jpegStream->priv = static_cast<void *>(&streams_.back());
> +		streamConfigs[index].streams.push_back(jpegStream);
> +		streamConfigs[index].types.push_back(type);
> +	}
> +
> +	for (const auto &streamConfig : streamConfigs) {
> +		config_->addConfiguration(streamConfig.config);

A blank line would be nice here too.

These two small issues can be addressed when applying.

> +		for (size_t i = 0; i < streamConfig.streams.size(); ++i) {
> +			camera3_stream_t *stream = streamConfig.streams[i];
> +			const CameraStream::Type type = streamConfig.types[i];

This will become simpler with the rework of the Camera3StreamConfig
structure as proposed in patch 1/3.

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

> +			streams_.emplace_back(this, type,
> +					      stream, config_->size() - 1);
> +			stream->priv = static_cast<void*>(&streams_.back());
> +		}
>  	}
> 
>  	switch (config_->validate()) {

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 09269d95..b7bf3d88 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1240,6 +1240,9 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 	streams_.clear();
 	streams_.reserve(stream_list->num_streams);

+	std::vector<Camera3StreamConfig> streamConfigs;
+	streamConfigs.reserve(stream_list->num_streams);
+
 	/* First handle all non-MJPEG streams. */
 	camera3_stream_t *jpegStream = nullptr;
 	for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
@@ -1270,14 +1273,12 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 			continue;
 		}

-		StreamConfiguration streamConfiguration;
-		streamConfiguration.size = size;
-		streamConfiguration.pixelFormat = format;
-
-		config_->addConfiguration(streamConfiguration);
-		streams_.emplace_back(this, CameraStream::Type::Direct,
-				      stream, config_->size() - 1);
-		stream->priv = static_cast<void *>(&streams_.back());
+		Camera3StreamConfig streamConfig;
+		streamConfig.streams = { stream };
+		streamConfig.types = { CameraStream::Type::Direct };
+		streamConfig.config.size = size;
+		streamConfig.config.pixelFormat = format;
+		streamConfigs.push_back(std::move(streamConfig));
 	}

 	/* Now handle the MJPEG streams, adding a new stream if required. */
@@ -1286,9 +1287,8 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 		int index = -1;

 		/* Search for a compatible stream in the non-JPEG ones. */
-		for (unsigned int i = 0; i < config_->size(); i++) {
-			StreamConfiguration &cfg = config_->at(i);
-
+		for (size_t i = 0; i < streamConfigs.size(); ++i) {
+			const auto &cfg = streamConfigs[i].config;
 			/*
 			 * \todo The PixelFormat must also be compatible with
 			 * the encoder.
@@ -1310,28 +1310,38 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 		 * introduce a new stream to satisfy the request requirements.
 		 */
 		if (index < 0) {
-			StreamConfiguration streamConfiguration;
-
 			/*
 			 * \todo The pixelFormat should be a 'best-fit' choice
 			 * and may require a validation cycle. This is not yet
 			 * handled, and should be considered as part of any
 			 * stream configuration reworks.
 			 */
-			streamConfiguration.size.width = jpegStream->width;
-			streamConfiguration.size.height = jpegStream->height;
-			streamConfiguration.pixelFormat = formats::NV12;
+			Camera3StreamConfig streamConfig;
+			streamConfig.config.size.width = jpegStream->width;
+			streamConfig.config.size.height = jpegStream->height;
+			streamConfig.config.pixelFormat = formats::NV12;
+			streamConfigs.push_back(std::move(streamConfig));

-			LOG(HAL, Info) << "Adding " << streamConfiguration.toString()
+			LOG(HAL, Info) << "Adding " << streamConfig.config.toString()
 				       << " for MJPEG support";

 			type = CameraStream::Type::Internal;
-			config_->addConfiguration(streamConfiguration);
-			index = config_->size() - 1;
+			index = streamConfigs.size() - 1;
 		}

-		streams_.emplace_back(this, type, jpegStream, index);
-		jpegStream->priv = static_cast<void *>(&streams_.back());
+		streamConfigs[index].streams.push_back(jpegStream);
+		streamConfigs[index].types.push_back(type);
+	}
+
+	for (const auto &streamConfig : streamConfigs) {
+		config_->addConfiguration(streamConfig.config);
+		for (size_t i = 0; i < streamConfig.streams.size(); ++i) {
+			camera3_stream_t *stream = streamConfig.streams[i];
+			const CameraStream::Type type = streamConfig.types[i];
+			streams_.emplace_back(this, type,
+					      stream, config_->size() - 1);
+			stream->priv = static_cast<void*>(&streams_.back());
+		}
 	}

 	switch (config_->validate()) {