From patchwork Wed Dec 2 14:16:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 29135 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6DAA6C3361 for ; Wed, 2 Dec 2026 14:16:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 940646AAE3; Wed, 2 Dec 2026 15:16:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="AZLY/qJW"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CEB46AAD3 for ; Wed, 2 Dec 2026 15:16:28 +0100 (CET) Received: from pb-laptop.local (185.182.215.118.nat.pool.zt.hu [185.182.215.118]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 140094BB; Wed, 2 Dec 2026 15:13:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1796220829; bh=EXV8EPkli2dOQcBqZ9evFAbdM4W7VqHPoStTWZLrTC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AZLY/qJWJAsweOrUvk+XQSVpNjHFK3tjvnpSVgpZikz/nBqCgI7EylTQahtKKLmG7 dvQgEg++atbW2w+2jSjdQd+ejUvXauCupIHPqK29bTV8CdnKlzpmluGclIDrzaMBho OA20Z7IHgFS8HwV6zv5ZDtPuM2InOPyPvYUlq7HE= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham Subject: [PATCH v2 4/4] libcamera: pipeline_handler: Allow calling stop() on a disconnected camera Date: Wed, 2 Dec 2026 15:16:23 +0100 Message-ID: <20261202141623.1375959-5-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202141623.1375959-1-barnabas.pocze@ideasonboard.com> References: <20261202141623.1375959-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org From: Stefan Klug 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 Signed-off-by: Kieran Bingham Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham --- src/libcamera/camera.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) 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 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;