From patchwork Mon Nov 30 08:30:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 29109 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 D9B00C3304 for ; Mon, 30 Nov 2026 08:30:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5390A6AA3A; Mon, 30 Nov 2026 09:30:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fQJ4WRok"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B709B6AA37 for ; Mon, 30 Nov 2026 09:30:09 +0100 (CET) Received: from [127.0.1.1] (chfd-03-b2-v4wan-176392-cust229.vm15.cable.virginm.net [82.19.20.230]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 75309C31; Mon, 30 Nov 2026 09:27:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1796027252; bh=5WCLVWXOGzsD+vXHDoLmkcRk/9Esp2AgX9XQjqz28VM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fQJ4WRokoFQQSDe+X5s2rqAg/WzNMR3wGPpW3gR+6tO0AddbElL29YoWI/kn5SLtU f8bafH3/uoBtqK4v+jAMMK41+zFolf+6hJvrgMrImVIxuIq1d73IDUnFFYRNC/qG40 sKisOce6brUfSPxtvSHdHKSRQxTMpG1z6wRyJuZ8= From: Daniel Scally Date: Mon, 30 Nov 2026 08:30:00 +0000 Subject: [PATCH 1/2] libcamera: camera_manager: Allow other threads to create cameras MIME-Version: 1.0 Message-Id: <20261130-camera-thread-v1-1-bca905afbeef@ideasonboard.com> References: <20261130-camera-thread-v1-0-bca905afbeef@ideasonboard.com> In-Reply-To: <20261130-camera-thread-v1-0-bca905afbeef@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2339; i=dan.scally@ideasonboard.com; h=from:subject:message-id; bh=5WCLVWXOGzsD+vXHDoLmkcRk/9Esp2AgX9XQjqz28VM=; b=owEBbQKS/ZANAwAKAchJV3psRXUyAcsmYgBrDTQQauuCj478z3biORMAHn6BCoFT1G05eCWx9 7Na0+O0v0iJAjMEAAEKAB0WIQQqyuwyDnZdb+mxmm/ISVd6bEV1MgUCaw00EAAKCRDISVd6bEV1 MvH/EACk4lfbdxzbx0S81+RMuK40TVq6fQtIQ+pmnFKKR5qbjEBP40fmaPx41Vxr0Sq0N++YN22 K0/n+i6Ig7HQaNZZU6ysRfC91pRvgDOc8SxCgPr8224QdvCJ/i8QQdZWQUCkMegJ+dApl8SwWeL 2frl6Ei/zVA8nPQ0SwcFpNU5LkBMLc/MCA4z5bcbd8/toPr1Py/ct0tpAIwzDTUcrLOD5InFtis 5J6g/1IHRSCR41CW4Wx3ofkfNqX1Ya85avDS5G/tPftcmKqL6htUqeIzmAfkl28idogHumGcSi+ MvX4sk96j/m2LvCJ6sxO+0/0kCxmxHZUlKHCXslIHaXijECr1hAP8rEBOo1JCr7wtH5szotD2/c XiVFNfY5TVqpNSdt2/uorw3/woXmPR6A13ZabBK8kNGanRrr1is2RmvUXp4w53fmiaGOoDyHZtI DtRY0BdNNxYyYBk6t/V80sfznaZIUclTz1x5lqqfv77sXFIO5H5x6uZBaLCV3pT+RBi5amhqYuu Umj8MW+OZkHTbpmtGCXXMotCbikUsAYaCwWSz6eSo5N17NrOv3At6A/c9f9FqiEXVtu5N2cHyPM gYBSKbJPMblLQF0A+WAXsuNQZiGfrSVkqNARPuB2V73l/iQz7zs2vgS2yaeHf8W7ugzIVF1XCV4 dnKorPTOc9yQY7Q== X-Developer-Key: i=dan.scally@ideasonboard.com; a=openpgp; fpr=EEC699ACA1B7CB5D31330C0BBD501C2A3546CCF6 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 addCamera() and removeCamera() currently restrict the caller to the CameraManager thread. I can't see a compelling reason to keep that restriction; the addition / removal of the new Camera to the vector of Cameras is guarded by a mutex, and the notification of the change is performed by emitting a signal that will be handled by the program thread anyway. Removing the restriction makes it much easier to move PipelineHandlers to their own thread - drop it. Signed-off-by: Daniel Scally --- With the next patch, addCamera() will be called from the new thread for the PipelineHandler instead of the CameraManager's thread in PipelineHandler::registerCamera() via manager_->d()->addCamera(). It might be better to use invokeMethod? addCamera() doesn't create any objects that might then inherit the wrong thread so it didn't seem to be necessary, but I'm not totally sure so I thought I'd mention it. --- src/libcamera/camera_manager.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 9c9073053710096f844670e8e1a5b70f2e4372bb..0f2189217c86e0ecc8673af0f5c7bf191eb2395d 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -198,13 +198,9 @@ void CameraManager::Private::cleanup() * * Device numbers from the SystemDevices property are used by the V4L2 * compatibility layer to map V4L2 device nodes to Camera instances. - * - * \context This function shall be called from the CameraManager thread. */ void CameraManager::Private::addCamera(std::shared_ptr camera) { - ASSERT(Thread::current() == this); - { MutexLocker locker(mutex_); @@ -236,13 +232,9 @@ void CameraManager::Private::addCamera(std::shared_ptr camera) * This function is called by pipeline handlers to unregister cameras from the * camera manager. Unregistered cameras won't be reported anymore by the * cameras() and get() calls, but references may still exist in applications. - * - * \context This function shall be called from the CameraManager thread. */ void CameraManager::Private::removeCamera(std::shared_ptr camera) { - ASSERT(Thread::current() == this); - { MutexLocker locker(mutex_); From patchwork Mon Nov 30 08:30:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 29110 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 237C5C3360 for ; Mon, 30 Nov 2026 08:30:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BAF476AA4A; Mon, 30 Nov 2026 09:30:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TZAu1zTG"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EBF7F6AA3A for ; Mon, 30 Nov 2026 09:30:09 +0100 (CET) Received: from [127.0.1.1] (chfd-03-b2-v4wan-176392-cust229.vm15.cable.virginm.net [82.19.20.230]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AE2ADC36; Mon, 30 Nov 2026 09:27:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1796027252; bh=JSBZnaD6elIM+SuGtJZmRBVG2m+StG/DlJuxvjwSQkk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TZAu1zTGorb5P+SjPpNWcpcZ6mVjT9P1nzQql2RBeo+sOxkq09Va8PUC1ZKT6TXsd /XW1mNHU7HgJBI2FRcC+x+NVOfXO1njdvp674VuqzExepW5VmUzaeKa08+zBk+INfT 7Mo0/1ILKBoplzWt/MTNtuUHfQssLzjhMtl26JkY= From: Daniel Scally Date: Mon, 30 Nov 2026 08:30:01 +0000 Subject: [PATCH 2/2] libcamera: pipeline_manager: Move PipelineHandlers to unique thread MIME-Version: 1.0 Message-Id: <20261130-camera-thread-v1-2-bca905afbeef@ideasonboard.com> References: <20261130-camera-thread-v1-0-bca905afbeef@ideasonboard.com> In-Reply-To: <20261130-camera-thread-v1-0-bca905afbeef@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2895; i=dan.scally@ideasonboard.com; h=from:subject:message-id; bh=JSBZnaD6elIM+SuGtJZmRBVG2m+StG/DlJuxvjwSQkk=; b=owEBbQKS/ZANAwAKAchJV3psRXUyAcsmYgBrDTQQzIiyuq5u1Gr33kktf7KXtKSCu5AM4c2ZX brhqN7NMc+JAjMEAAEKAB0WIQQqyuwyDnZdb+mxmm/ISVd6bEV1MgUCaw00EAAKCRDISVd6bEV1 MkX6D/9wJEQSClA2myCDhWhppK7NEWrFb/uUDMspy08EzOeRXGchXsaKddMCK7E5Ox8ZgK/i/up XFbUBuf87MWHpQo1HlWb3uPGd/RCVP2ctuqkAVWKIQus7vmhCU31r1rW/9pyZrPPM6WBLYvXSHz M2EaTRf4y72MzOln/5gi5hoOO6e7mjraLo7F0gWQ1MwGIId2Kdh02uCBGsQ5juNLeqAo9yMoRd/ T/eqWb6hK20dIBOVSbbZrtSmMdpLfRLk7blrd+Nsx8ccG1EuMt4QoBChBWA48q1m1mp4iqN1Zax hVoZoejnm/bWvXy0wPYyVCDQU7Btj12c1t9UXChCB3XoPI/sMFr0PGDHuz/Tjt7kVrspY8qAGXf cohoDxRdYduVd2NOX3gSqb3bcy3ANcp0s8EsZtR3PWbW/NiHxSBHWoqGP18cxYGSg2UBrudWu4C icg1jpiidsDc7/7YAVcLO+BVqBrAdhqlZ8wifeDEHmTGuii/x0H44YZPbNiQNEyZl3Tl/2DtsDS hI7zOd22Y6TolnGKSenqnw8CcITY9bxqAU2ayklIce3m6aSc54xhH0jOZTzzjRewcyQLPlqYNlk 5TmhCrgZji1r5Y08MUQNZMDM8ESvppvCDKL+6o/M3vMJ9yUkgSttOvQaTFz9Z+ATk1hf6x0SPTX /Xtch+ofPzm8wmQ== X-Developer-Key: i=dan.scally@ideasonboard.com; a=openpgp; fpr=EEC699ACA1B7CB5D31330C0BBD501C2A3546CCF6 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 All PipelineHandlers and the Cameras that they create currently live in the CameraManager Thread. This creates a problem when a Camera is streaming and a second Camera is started; the event loops that drive buffers to the ISP video devices then share a thread with ioctl()s to the driver, and this means the loops stall whilst those ioctl()s are running. To solve the issue move PipelineHandlers to their own thread. Signed-off-by: Daniel Scally --- include/libcamera/internal/pipeline_handler.h | 2 ++ src/libcamera/camera_manager.cpp | 3 ++- src/libcamera/pipeline_handler.cpp | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 6a018fe428661c179dc35ec6a986dd5ae22e7b92..d9fabd8121ce1c296c4e2a0951aa7ba5d63f0d2b 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -30,8 +30,10 @@ class FrameBuffer; class MediaDevice; class PipelineHandler; class Request; +class Thread; class PipelineHandler : public std::enable_shared_from_this, + public Thread, public Object { public: diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 0f2189217c86e0ecc8673af0f5c7bf191eb2395d..42c2892168031c25997710785dcaab6e57c14fbc 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -158,7 +158,8 @@ void CameraManager::Private::pipelineFactoryMatch(const PipelineHandlerFactoryBa /* Provide as many matching pipelines as possible. */ while (1) { std::shared_ptr pipe = factory->create(o); - if (!pipe->match(enumerator_.get())) + if (!pipe->invokeMethod(&PipelineHandler::match, + ConnectionTypeBlocking, enumerator_.get())) break; LOG(Camera, Debug) diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index a803f6208c324efc8fb4f244b28d301d0c1f70c4..43aa1a62de013975215bf4ac342a22b99f735fcc 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -13,6 +13,8 @@ #include #include +#include +#include #include #include @@ -74,12 +76,18 @@ PipelineHandler::PipelineHandler(CameraManager *manager, : manager_(manager), maxQueuedRequestsDevice_(maxQueuedRequestsDevice), useCount_(0) { + moveToThread(this); + Thread::start(); } PipelineHandler::~PipelineHandler() { for (std::shared_ptr &media : mediaDevices_) media->release(); + + exit(); + wait(); + removeMessages(this); } /**