[libcamera-devel,v5,1/2] android: CameraDevice: Add stop()
diff mbox series

Message ID 20210402021238.1297591-2-hiroh@chromium.org
State Changes Requested
Headers show
Series
  • Fix Camera3RequestDescriptor leakage
Related show

Commit Message

Hirokazu Honda April 2, 2021, 2:12 a.m. UTC
This adds CameraDevice::stop(), which cleans up the member
variables of CameraDevice. It is called in CameraDevice::close()
and CameraDevice::configureStreams().

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/android/camera_device.cpp | 19 ++++++++++++-------
 src/android/camera_device.h   |  2 ++
 2 files changed, 14 insertions(+), 7 deletions(-)

Comments

Laurent Pinchart April 2, 2021, 10:31 p.m. UTC | #1
Hi Hiro,

Thank you for the patch.

On Fri, Apr 02, 2021 at 11:12:37AM +0900, Hirokazu Honda wrote:
> This adds CameraDevice::stop(), which cleans up the member
> variables of CameraDevice. It is called in CameraDevice::close()
> and CameraDevice::configureStreams().
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>

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

> ---
>  src/android/camera_device.cpp | 19 ++++++++++++-------
>  src/android/camera_device.h   |  2 ++
>  2 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index eb327978..b45d3a54 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -659,9 +659,18 @@ void CameraDevice::close()
>  {
>  	streams_.clear();
>  
> +	stop();
> +
> +	camera_->release();
> +}
> +
> +void CameraDevice::stop()
> +{
> +	if (!running_)
> +		return;
> +
>  	worker_.stop();
>  	camera_->stop();
> -	camera_->release();
>  
>  	running_ = false;
>  }
> @@ -1547,12 +1556,8 @@ PixelFormat CameraDevice::toPixelFormat(int format) const
>   */
>  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  {
> -	/* Before any configuration attempt, stop the camera if it's running. */
> -	if (running_) {
> -		worker_.stop();
> -		camera_->stop();
> -		running_ = false;
> -	}
> +	/* Before any configuration attempt, stop the camera. */
> +	stop();
>  
>  	/*
>  	 * Generate an empty configuration, and construct a StreamConfiguration
> diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> index 11bdfec8..39cf95ad 100644
> --- a/src/android/camera_device.h
> +++ b/src/android/camera_device.h
> @@ -85,6 +85,8 @@ private:
>  		int androidFormat;
>  	};
>  
> +	void stop();
> +
>  	int initializeStreamConfigurations();
>  	std::vector<libcamera::Size>
>  	getYUVResolutions(libcamera::CameraConfiguration *cameraConfig,

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index eb327978..b45d3a54 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -659,9 +659,18 @@  void CameraDevice::close()
 {
 	streams_.clear();
 
+	stop();
+
+	camera_->release();
+}
+
+void CameraDevice::stop()
+{
+	if (!running_)
+		return;
+
 	worker_.stop();
 	camera_->stop();
-	camera_->release();
 
 	running_ = false;
 }
@@ -1547,12 +1556,8 @@  PixelFormat CameraDevice::toPixelFormat(int format) const
  */
 int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 {
-	/* Before any configuration attempt, stop the camera if it's running. */
-	if (running_) {
-		worker_.stop();
-		camera_->stop();
-		running_ = false;
-	}
+	/* Before any configuration attempt, stop the camera. */
+	stop();
 
 	/*
 	 * Generate an empty configuration, and construct a StreamConfiguration
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 11bdfec8..39cf95ad 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -85,6 +85,8 @@  private:
 		int androidFormat;
 	};
 
+	void stop();
+
 	int initializeStreamConfigurations();
 	std::vector<libcamera::Size>
 	getYUVResolutions(libcamera::CameraConfiguration *cameraConfig,