From patchwork Fri Sep 18 07:59:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 28321 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 7548BBE175 for ; Fri, 18 Sep 2026 08:07:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E7CA46849B; Fri, 18 Sep 2026 10:07:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="GOMJU3VV"; dkim-atps=neutral Received: from mail-wr2-x10.google.com (mail-wr2-x10.google.com [IPv6:2a00:1450:4864:30::10]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B352468729 for ; Fri, 18 Sep 2026 10:07:47 +0200 (CEST) Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-482e1b30c94so52421f8f.1 for ; Fri, 18 Sep 2026 01:07:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1789718867; x=1790323667; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SZFCXJgd6dwoSKX2hlSdUpN5Yp5J4RmsW6senPio2yo=; b=GOMJU3VVHKxr1MKbLosmukP8s5a8kbUK4WgAhYJXjQzYgBpZIjt1PLtYHfpshZCdz+ rzjoZkkrcr59tEI1ekEsbgXFT0hDh+MgDNnVeqRxDOkgctiAE/7jCmdYxaF51RUPQCao LqYC88q6HF8DBFG62bFhIdMyHdVMDwdMuVMCb6LOgB3K7FmWprZJwvvxoRVmJKWT3BQk R7N9yTzJTYG8b1IWGp0JQ+rTts1EQcy4U3ijZmQlnHLy+7ihb4YyesAp/eVjTd1qik/u 6qXC+DOFWu0nG3Bi5hFBYrcri66FSNjteDzvaAMCKRA+guX2I78y+aUAP7bj4diz5bPU Aaqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789718867; x=1790323667; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SZFCXJgd6dwoSKX2hlSdUpN5Yp5J4RmsW6senPio2yo=; b=ur/hWYaULDTPfPFreZq0SAsC0tnGV7nnmPuWjoypkHOENtQv8UYLbi2BrUCoH6yO5P ypHLty/pE0/XL37u+aAXTkRl5ri4kDHY6xVC31IPBssqS0KWzbvsS8noItfJSzCQYDXV ryqm/gE3044JEg8ROn4h/dcAm3uEZ7cpo0Av2L+CoqK8WwCpLJEJHstuSTyIzw2yBjHA p5LB14FdYF7SJ284v6sPqDeD8/3hPpXdXAEoPUNYCuqgyQozkNScE0clhFRvcrqshUvV wTIVnvYYsJQHiLHO9zau6+R8K+oF3i2ddLIxZv+suXZMByE+Vb8w7nv1hI9zGyGwbn2U 8EsA== X-Gm-Message-State: AFuF++lakfjXWBfkaPI6KyVSp8R+1Lj4fdpVWZ+IPZBvZNSKUQaqYB7Q hlU+jrkCWBjz1/860yfMWob17QWgZc+GCJhvD6+KZWEKcuvfOsHlmoU9pM5ElWLEeKJxYQ40eyj PjeYb+BI= X-Gm-Gg: AYBFou3zOHyr7iAVE2ci5KMfbn0bgTpehqqFVSrl8A9bkHgkFPF6LcZdwmBTOMtxW0P wECnyp66MkOLuKAPxvVcEN9zidLQHTXOiMImBnaLlORam3CMsqJL4Y/l7F5ynISouQYekI9SciD koM6skHT4GfUx8aTE6tPZp/iGCCGno9Oyxw1ADfITqAGJjj732v6aBPbt7U2s0uKed4y0laq3vr jK+a6W7P+QDs7ngiHazId0R31pwNF+0375OwYRhhknqra4tVQqYcdwBQRPSal4hq2qpf7TqW54j CsWDDL9lVqJTurXdWUm3MY3AwhTomNS+g/BYpLCq87VAbxSEttcNhyeVPAbhKoPmAtfTVXl4jFn SNJOMqFab5NG9V+X+wLl0ragEejOfEHXCfOCCbdvlVVf0O07XTyZ+z2XWovdG1wp2UDwrss12cO XJCDCKW/K01uw0NOPv42JDItApcRQU7lT0rRMra2pgNNsSIJ+y37SBF12ZiJaE25jl/6DU2w1Bo jTLNnipft9mPc23MjYvHnkQz+yQNbWGIEWjqsKbBIH1InbPM1QDkIbUdwvGFyfHu/qMlsjOoZes I5oMqKwd28pz8KGDuy9BOaLW98HSW4ehEnRk74n4vEXCA0eUqvmTEWDGzjNEv33L7fq0amwnth3 Np+VK3YwrAZm9fhcpSzONyU31xBMBqEXj8Ns= X-Received: by 2002:a05:600c:1d1b:b0:49e:7cc6:ec88 with SMTP id 5b1f17b1804b1-49fc7e00555mr12123645e9.1.1789718867130; Fri, 18 Sep 2026 01:07:47 -0700 (PDT) Received: from naush-dell.pitowers.org ([2a00:1098:3142:1f:45e3:df8b:2b18:6253]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-487203f077fsm1742230f8f.26.2026.09.18.01.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 01:07:46 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [RFC PATCH v1 09/20] libcamera: camera_manager: Track active pipeline handler instances Date: Fri, 18 Sep 2026 08:59:47 +0100 Message-ID: <20260918080734.1228227-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260918080734.1228227-1-naush@raspberrypi.com> References: <20260918080734.1228227-1-naush@raspberrypi.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 Sender: "libcamera-devel" The camera manager drops its reference to a pipeline handler as soon as match() returns, leaving the instance owned solely by the Camera object. Store a vector of weak references to matched pipeline handler instances. This will allow camera initialisation from a descriptor to link to an existing pipeline handler instance rather than creating a second instance for media devices that are already acquired. Weak references leave the existing ownership and lifetime model unchanged. Add a findMatchingHandler() helper that returns the active pipeline handler instance that has acquired a given media device, pruning expired references as it goes. This will be used in a future commit. Signed-off-by: Naushir Patuck --- include/libcamera/internal/camera_manager.h | 9 +++++++ src/libcamera/camera_manager.cpp | 30 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/libcamera/internal/camera_manager.h b/include/libcamera/internal/camera_manager.h index cfedee433857..89c8e4eda766 100644 --- a/include/libcamera/internal/camera_manager.h +++ b/include/libcamera/internal/camera_manager.h @@ -26,6 +26,8 @@ namespace libcamera { class Camera; class DeviceEnumerator; class IPAManager; +class MediaDevice; +class PipelineHandler; class PipelineHandlerFactoryBase; class CameraManager::Private : public Extensible::Private, public Thread @@ -53,6 +55,7 @@ private: int init(); void createPipelineHandlers(); void pipelineFactoryMatch(const PipelineHandlerFactoryBase *factory); + std::shared_ptr findMatchingHandler(const MediaDevice *media); void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_); /* @@ -70,6 +73,12 @@ private: std::unique_ptr enumerator_; + /* + * Active pipeline handler instances, accessed from the CameraManager + * thread only. + */ + std::vector> pipes_; + std::unique_ptr ipaManager_; const GlobalConfiguration configuration_; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 784ae012e280..bd9cc155b961 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -178,7 +178,37 @@ void CameraManager::Private::pipelineFactoryMatch(const PipelineHandlerFactoryBa LOG(Camera, Debug) << "Pipeline handler \"" << factory->name() << "\" matched"; + + pipes_.push_back(pipe); + } +} + +/* + * Find the active pipeline handler instance that has acquired the media device, + * if any. Expired entries are pruned from the registry as a side effect. Called + * from the CameraManager thread only. + */ +std::shared_ptr +CameraManager::Private::findMatchingHandler(const MediaDevice *media) +{ + ASSERT(Thread::current() == this); + + std::shared_ptr match; + + for (auto it = pipes_.begin(); it != pipes_.end();) { + std::shared_ptr pipe = it->lock(); + if (!pipe) { + it = pipes_.erase(it); + continue; + } + + if (!match && pipe->usesMediaDevice(media)) + match = std::move(pipe); + + ++it; } + + return match; } void CameraManager::Private::cleanup()