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); } /**