[libcamera-devel,v2] android: camera_device: Stop camera when re-configuring it
diff mbox series

Message ID 20201207093413.5479-1-jacopo@jmondi.org
State Accepted
Commit 8fed613562677dd2402b6f67f0090fcba3301f1f
Headers show
Series
  • [libcamera-devel,v2] android: camera_device: Stop camera when re-configuring it
Related show

Commit Message

Jacopo Mondi Dec. 7, 2020, 9:34 a.m. UTC
The Android camera device HAL3 specification does not require a
camera to go through any explicit close() call between configurations.
It is legit for a camera to be configured, a number of requests
processed and the re-configured again without any explicit stop.

The libcamera Android camera HAL starts the Camera at the first handled
request, and only stops it at camera close time. This mean, that two
camera configuration attempts part of the same streaming session are only
interleaved by capture requests handling.

The libcamera::Camera state machine requires the Camera to be stopped,
before any configuration take place, and this currently doesn't happen.

Fix this by stopping the camera and the associated worker thread if
a configuration attempt is performed while the Camera is in running
state.

This patch fixes cros_camera_test:
Camera3PreviewTest/Camera3SinglePreviewTest.Camera3BasicPreviewTest/0

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

---
v1 -> v2:
- Stop the camera at the very beginning of the configureStreams() function

---
 src/android/camera_device.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

--
2.29.1

Comments

Kieran Bingham Dec. 7, 2020, 12:25 p.m. UTC | #1
Hi Jacopo,

On 07/12/2020 09:34, Jacopo Mondi wrote:
> The Android camera device HAL3 specification does not require a
> camera to go through any explicit close() call between configurations.
> It is legit for a camera to be configured, a number of requests

s/legit/legitimate/

> processed and the re-configured again without any explicit stop.

s/the/then/

> 
> The libcamera Android camera HAL starts the Camera at the first handled
> request, and only stops it at camera close time. This mean, that two

s/mean,/means/

> camera configuration attempts part of the same streaming session are only

s/part//


> interleaved by capture requests handling.
> 
> The libcamera::Camera state machine requires the Camera to be stopped,

s/,//

> before any configuration take place, and this currently doesn't happen.
> 
> Fix this by stopping the camera and the associated worker thread if
> a configuration attempt is performed while the Camera is in running
> state.
> 
> This patch fixes cros_camera_test:
> Camera3PreviewTest/Camera3SinglePreviewTest.Camera3BasicPreviewTest/0
> 
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> ---
> v1 -> v2:
> - Stop the camera at the very beginning of the configureStreams() function
> 
> ---
>  src/android/camera_device.cpp | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 675af5705055..dc711550546c 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1210,6 +1210,13 @@ 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;
> +	}
> +
>  	/*
>  	 * Generate an empty configuration, and construct a StreamConfiguration
>  	 * for each camera3_stream to add to it.
> --
> 2.29.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
>

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 675af5705055..dc711550546c 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1210,6 +1210,13 @@  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;
+	}
+
 	/*
 	 * Generate an empty configuration, and construct a StreamConfiguration
 	 * for each camera3_stream to add to it.