[libcamera-devel,v2,07/12] android: camera_device: Get rid of stream counter

Message ID 20200902152236.69770-8-jacopo@jmondi.org
State Accepted
Headers show
Series
  • android: camera_device: Fix JPEG/RAW sizes
Related show

Commit Message

Jacopo Mondi Sept. 2, 2020, 3:22 p.m. UTC
Now that CameraConfiguration::addConfiguration() returns the index
of the newly added configuration, there's no need to use a custom
counter to keep track of the StreamConfiguration index associated with
a CameraStream.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/android/camera_device.cpp | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

Comments

Laurent Pinchart Sept. 5, 2020, 9:37 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Wed, Sep 02, 2020 at 05:22:31PM +0200, Jacopo Mondi wrote:
> Now that CameraConfiguration::addConfiguration() returns the index
> of the newly added configuration, there's no need to use a custom
> counter to keep track of the StreamConfiguration index associated with
> a CameraStream.
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/android/camera_device.cpp | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index b110bfe43ece..ace7f6b17b4a 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1195,12 +1195,6 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  	streams_.clear();
>  	streams_.reserve(stream_list->num_streams);
>  
> -	/*
> -	 * Track actually created streams, as there may not be a 1:1 mapping of
> -	 * camera3 streams to libcamera streams.
> -	 */
> -	unsigned int streamIndex = 0;
> -
>  	/* First handle all non-MJPEG streams. */
>  	for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
>  		camera3_stream_t *stream = stream_list->streams[i];
> @@ -1230,9 +1224,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  		streamConfiguration.size = size;
>  		streamConfiguration.pixelFormat = format;
>  
> -		config_->addConfiguration(streamConfiguration);
> -
> -		streams_[i].index = streamIndex++;
> +		streams_[i].index = config_->addConfiguration(streamConfiguration);

As explained in the review of 06/12, this could also be

		config_->addConfiguration(streamConfiguration);
		streams_[i].index = config_->size() - 1;

In any case,

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

>  	}
>  
>  	/* Now handle MJPEG streams, adding a new stream if required. */
> @@ -1280,8 +1272,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  			LOG(HAL, Info) << "Adding " << streamConfiguration.toString()
>  				       << " for MJPEG support";
>  
> -			config_->addConfiguration(streamConfiguration);
> -			streams_[i].index = streamIndex++;
> +			streams_[i].index = config_->addConfiguration(streamConfiguration);
>  		}
>  	}
>
Hirokazu Honda Sept. 8, 2020, 4:07 a.m. UTC | #2
I personally prefer the way Laurent suggested.

On Sun, Sep 6, 2020 at 6:38 AM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Jacopo,
>
> Thank you for the patch.
>
> On Wed, Sep 02, 2020 at 05:22:31PM +0200, Jacopo Mondi wrote:
> > Now that CameraConfiguration::addConfiguration() returns the index
> > of the newly added configuration, there's no need to use a custom
> > counter to keep track of the StreamConfiguration index associated with
> > a CameraStream.
> >
> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> > ---
> >  src/android/camera_device.cpp | 13 ++-----------
> >  1 file changed, 2 insertions(+), 11 deletions(-)
> >
> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> > index b110bfe43ece..ace7f6b17b4a 100644
> > --- a/src/android/camera_device.cpp
> > +++ b/src/android/camera_device.cpp
> > @@ -1195,12 +1195,6 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
> >       streams_.clear();
> >       streams_.reserve(stream_list->num_streams);
> >
> > -     /*
> > -      * Track actually created streams, as there may not be a 1:1 mapping of
> > -      * camera3 streams to libcamera streams.
> > -      */
> > -     unsigned int streamIndex = 0;
> > -
> >       /* First handle all non-MJPEG streams. */
> >       for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
> >               camera3_stream_t *stream = stream_list->streams[i];
> > @@ -1230,9 +1224,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
> >               streamConfiguration.size = size;
> >               streamConfiguration.pixelFormat = format;
> >
> > -             config_->addConfiguration(streamConfiguration);
> > -
> > -             streams_[i].index = streamIndex++;
> > +             streams_[i].index = config_->addConfiguration(streamConfiguration);
>
> As explained in the review of 06/12, this could also be
>
>                 config_->addConfiguration(streamConfiguration);
>                 streams_[i].index = config_->size() - 1;
>
> In any case,
>
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
> >       }
> >
> >       /* Now handle MJPEG streams, adding a new stream if required. */
> > @@ -1280,8 +1272,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
> >                       LOG(HAL, Info) << "Adding " << streamConfiguration.toString()
> >                                      << " for MJPEG support";
> >
> > -                     config_->addConfiguration(streamConfiguration);
> > -                     streams_[i].index = streamIndex++;
> > +                     streams_[i].index = config_->addConfiguration(streamConfiguration);
> >               }
> >       }
> >
>
> --
> Regards,
>
> Laurent Pinchart
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index b110bfe43ece..ace7f6b17b4a 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1195,12 +1195,6 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 	streams_.clear();
 	streams_.reserve(stream_list->num_streams);
 
-	/*
-	 * Track actually created streams, as there may not be a 1:1 mapping of
-	 * camera3 streams to libcamera streams.
-	 */
-	unsigned int streamIndex = 0;
-
 	/* First handle all non-MJPEG streams. */
 	for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
 		camera3_stream_t *stream = stream_list->streams[i];
@@ -1230,9 +1224,7 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 		streamConfiguration.size = size;
 		streamConfiguration.pixelFormat = format;
 
-		config_->addConfiguration(streamConfiguration);
-
-		streams_[i].index = streamIndex++;
+		streams_[i].index = config_->addConfiguration(streamConfiguration);
 	}
 
 	/* Now handle MJPEG streams, adding a new stream if required. */
@@ -1280,8 +1272,7 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 			LOG(HAL, Info) << "Adding " << streamConfiguration.toString()
 				       << " for MJPEG support";
 
-			config_->addConfiguration(streamConfiguration);
-			streams_[i].index = streamIndex++;
+			streams_[i].index = config_->addConfiguration(streamConfiguration);
 		}
 	}