[v2,4/4] libcamera: pipeline_handler: Allow calling stop() on a disconnected camera
diff mbox series

Message ID 20261202141623.1375959-5-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: atomic-disconnects
Related show

Commit Message

Barnabás Pőcze Dec. 2, 2026, 2:16 p.m. UTC
From: Stefan Klug <stefan.klug@ideasonboard.com>

Calling stop() on a disconnected camera currently has no effect. However,
this is problematic as the disconnection procedure does not stop the
camera either, meaning that PipelineHandler::stop() does not run for a
disconnected camera.

This is a problem as it prevents the pipeline handler from properly stopping
streaming and for already queued requests to be returned as cancelled.

So modify Camera::stop() so that it proceeds for disconnected cameras
if they are otherwise in the "Running" state. And adjust the documentation
accordingly.

Note that the camera cannot be stopped when the disconnection is processed
because concurrent queueRequest() calls by the application can run into
various race conditions. So this change makes it the application's
responsibility to stop a running camera, even if it was disconnected.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/camera.cpp | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index f45c80cc7c..6f277fb872 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -743,14 +743,6 @@  int Camera::Private::isAccessAllowed(State low, State high,
 
 void Camera::Private::disconnect()
 {
-	/*
-	 * If the camera was running when the hardware was removed force the
-	 * state to Configured state to allow applications to free resources
-	 * and call release() before deleting the camera.
-	 */
-	if (state_.load(std::memory_order_acquire) == Private::CameraRunning)
-		state_.store(Private::CameraConfigured, std::memory_order_release);
-
 	disconnected_.store(true, std::memory_order_relaxed);
 }
 
@@ -935,7 +927,9 @@  const std::string &Camera::id() const
  * physical device disconnection. The media device is passed as a parameter.
  *
  * As soon as this signal is emitted the camera instance will refuse all new
- * application API calls by returning errors immediately.
+ * application API calls by returning errors immediately. The only exception is
+ * the stop() function which must be called on the camera if it was in running
+ * state before, to ensure all resources are released.
  */
 
 Camera::Camera(std::unique_ptr<Private> d, const std::string &id,
@@ -1451,7 +1445,6 @@  int Camera::start(const ControlList *controls)
  * running, it is a no-op.
  *
  * \return 0 on success or a negative error code otherwise
- * \retval -ENODEV The camera has been disconnected from the system
  * \retval -EACCES The camera is not running so can't be stopped
  */
 int Camera::stop()
@@ -1465,7 +1458,7 @@  int Camera::stop()
 	if (d->state() != Private::CameraRunning)
 		return 0;
 
-	int ret = d->isAccessAllowed(Private::CameraRunning);
+	int ret = d->isAccessAllowed(Private::CameraRunning, true);
 	if (ret < 0)
 		return ret;