[libcamera-devel] [PATCH v2 9/9] RFC: Stop PostProcessor when camera is stopped

Umang Jain umang.jain at ideasonboard.com
Fri Sep 10 09:06:38 CEST 2021


Stopping the post-processor thread from CameraDevice is not ideal.
But it temporarily avoids the crash on stopping the camera.

Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
---
 src/android/camera_device.cpp | 8 ++++++++
 src/android/camera_stream.h   | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 73eb5758..fa2db72f 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -425,6 +425,14 @@ int CameraDevice::open(const hw_module_t *hardwareModule)
 
 void CameraDevice::close()
 {
+	for (CameraStream &cameraStream : streams_) {
+		/* CameraStream doesn't have user defined destructor as
+		 * it is MoveConstructible. Stop the post-processor thread
+		 * from here before clearing streams_.
+		 */
+		cameraStream.stopPostProcessorThread();
+	}
+
 	streams_.clear();
 
 	stop();
diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h
index dbb7eee3..bd37473e 100644
--- a/src/android/camera_stream.h
+++ b/src/android/camera_stream.h
@@ -133,6 +133,13 @@ public:
 		    const Camera3RequestDescriptor *context);
 	libcamera::FrameBuffer *getBuffer();
 	void putBuffer(libcamera::FrameBuffer *buffer);
+	void stopPostProcessorThread()
+	{
+		if (thread_) {
+			thread_->exit();
+			thread_->wait();
+		}
+	}
 
 	enum ProcessStatus {
 		Succeeded,
-- 
2.31.1



More information about the libcamera-devel mailing list