From patchwork Fri Mar 8 11:00:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Vuillaumier X-Patchwork-Id: 19646 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 B2102C0F2A for ; Fri, 8 Mar 2024 11:01:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7567C62875; Fri, 8 Mar 2024 12:01:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="cvpY9zxx"; dkim-atps=neutral Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on20601.outbound.protection.outlook.com [IPv6:2a01:111:f403:2611::601]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 91ED562865 for ; Fri, 8 Mar 2024 12:01:37 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M6dcF0gil9D1qBg3dKGtLE+gWfWDImRve7r/MbtWcCS/H8x6dqj4Z66DB39juoA26QtdjFDD1juHF6Sezb9fkCrOoSROSsLj3eWQuOMOh0dIl6GG6MEjnGlbwgi6ZDJ5gnhkTzT9XAZWtGzxczpqiFFpOr20PFvwlum+pppNX7BuCgnv1Op6hopTl1KNRVeyYBtrGp1ywlN4Qi5V9mol9VCV87p5ZAV9nWcCr/3l22UgNZVdG25h/WHVtKl3zfCoIxxI2RWD6k0l+7SA/3Ruy47IErK+qgYpm6BddgWdssgl9UNTYQRxL84ximjxLHCD30noCsHcCtjdIEl9Iu6EvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CqbfDMgXnG42hbsPTvU39oLRCo07hgHGY5JvaRvUef4=; b=YADLzYmr09k2SYVPLLOsumaTuHLiT6mZUpyzZLX83sZ/4TlHpuWHZt/hJxEYxNlIgpKvqKpF9zfFMM1XyHNKZHYvAFX/rA9fE/7Lnbmiegegf7pM+CSXWHUg6SDYmCXcYalvX5AioXUMAB6b46NHxQlhXxi2bfjz1Z2G/bPDCELiDLwbwrJttRYcuchboSOJUZYDqwzCw9EQhPSuv5fDfdGr17BmcHtecvnmVMTPx7toCn2DfGnT4uYqmL9OSL0DGXCAhtjgbM13/dDzdKO1xquLecXgPmY8jjHZpBkDBlHWhzfQkdFWKzEfTQNbl54iiOkWY0SHNNhjk9szaPaLSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CqbfDMgXnG42hbsPTvU39oLRCo07hgHGY5JvaRvUef4=; b=cvpY9zxxDFUBE35fhnCTUf4bDhyle83Mnu5pL7Jn2mcUKUl2NL4nxwmieiurp9SrukMBZOFeG5MCcbzb3QKSpOqsmT0qbHUoZ61o6k4aJkkW61vItS8vrS+C6kVfWowY/fRQ55jXHNknbdA8mhMwGXoRaCI5lAX6X9vmVdwxwmI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8147.eurprd04.prod.outlook.com (2603:10a6:20b:3e0::22) by AM9PR04MB8683.eurprd04.prod.outlook.com (2603:10a6:20b:43e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Fri, 8 Mar 2024 11:01:36 +0000 Received: from AM9PR04MB8147.eurprd04.prod.outlook.com ([fe80::3fdf:4cf8:d542:1b49]) by AM9PR04MB8147.eurprd04.prod.outlook.com ([fe80::3fdf:4cf8:d542:1b49%4]) with mapi id 15.20.7362.028; Fri, 8 Mar 2024 11:01:36 +0000 From: Julien Vuillaumier To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 2/2] libcamera: camera_manager: Add environment variable to order pipelines match Date: Fri, 8 Mar 2024 12:00:56 +0100 Message-Id: <20240308110056.453320-3-julien.vuillaumier@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240308110056.453320-1-julien.vuillaumier@nxp.com> References: <20240308110056.453320-1-julien.vuillaumier@nxp.com> X-ClientProxiedBy: AM0PR04CA0052.eurprd04.prod.outlook.com (2603:10a6:208:1::29) To AM9PR04MB8147.eurprd04.prod.outlook.com (2603:10a6:20b:3e0::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8147:EE_|AM9PR04MB8683:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e988057-3e17-4ec0-ee5e-08dc3f5f1f82 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rPu54LixYkyrquPxrkqkA8MnvQHruN43X+FzBnEB/qM+EssJAiO0xeFcbOrlsVlRcekgtUoXsAfJ127hHINOcB8aqkyygXuutOuVbIEZfYqIfccsD/LVplTlPgAV+QloMInc1G+mgS1vaxHigx4uwBDFzAsdUW/Amcsp8DDjkL+PTmI89pcmB27VhLqKuwZ/iWvzcNZ3BCcQDlMpp23RXCqQT81S01IR+E9aOeP1j7q3H9DjZrGiSTnHrh+KeMhrx0P150wag8RN0sFHVsiO4yf4jGUVXEv1RJhuN281M8Icxsb+6O+v1JSQS/oaDJyYOekMtraN6DMSHOQXmzq/g61dWohpS5YuxqpHNM3V3Qr9oy4a6OSgthOvzRqGbWSSnWq+kJYnB7yaVQYhgtReF5HUro5II9OwUp6FSO3l1A0T6JIliTFTTJuibSzukNNmyF0h5uVghOQvT57wwrm0kFkeCCGhYkPMwuMpgd267vm+cXmFCbtq7RaZTHlp5bZadK6GNjpAkCS7mz7YP4TmcAFjo9uUbrp7fKJSMBcAaey/1ZTeEPAFUhTNXj/bW7z/g0ykVjpyeXfCoY+i6PPTrCOnIcmFwI3kRyxFytqu0SHEDacCKzKIXpoKRa4z0AI4gR/sOE+yUNWE+ILZx3eVKpvncni1zjCAXg/6fKgZJuFcBUbouH/TVdyY6R2XV2+fp5tjDL/hxpaOaWyiGRvErg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8147.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005)(52116005)(1800799015)(38350700005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Q8jFnLkTOZQwMYppqMpO977PoAYKdITAIZEZ4qBRtW6NI78wU5+ityvKrm/+YhwcKPSegaTnNmKpI6mmpMDEIDySv6Ao2Z+IT4CMiYXwgtXTh96AYGayV+g137GRyGET8KaEENiAfdRKNwFyv8giGGXKa/4PlXyWLIw+RMHcDnaCzdfejeOvUVuyvnN9chKZ8RYAFLjqsxzJz8jFlvcTZ8PTMbV3O6DKlRiHtODbxxqoItvznie8xhrBrRHUbayVk19y76bRtkJc82AMI/c/u6TE6kcNtRFUPFFvzRJm7wd96KlG+i8OOnlE2fBjVzIBdb8ZHUwCCThNA8yzbcNSUpuwwOA7auNANvy77MwzGonNAzsktA3Rb+sRmLxKCq/+9rxrEpCSn09NdSRsDr+cQEv1AoSjmqYyW+wiaxpMShRrK9AEw9b8VXHsqsTPvkjPTXvor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bSnlFG5HOgexLdTsnpBuBF9wik0IrclgUZiJ6aQgY4JCjvlpyPNM+CxQVHW3Z4EZwNvcqVfJBWWS+LrK8/eXQYQXfQ4+1qZJjWA2Qr8c+WkTg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e988057-3e17-4ec0-ee5e-08dc3f5f1f82 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8147.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 11:01:36.4206 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: n2azlw/UpKzt0NvRrr/ot3zdz17xJ6VL6piYkpzC28fVqEKzRvJgKH8AnMZ5fox0Es1VB5EZlmlfJ0l7K8gi6XdXFHculkXSBAtEgdLgJPc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8683 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" To match the enumerated media devices, each pipeline handler registered is used in no specific order. It is a limitation when several pipelines can match the devices, and user has to select a specific pipeline. For this purpose, environment variable LIBCAMERA_PIPELINES_MATCH_LIST is created that gives the option to define an ordered list of pipelines to invoke during the match process. LIBCAMERA_PIPELINES_MATCH_LIST="[,[,...]]]" Example: LIBCAMERA_PIPELINES_MATCH_LIST="PipelineHandlerRkISP1,SimplePipelineHandler" Signed-off-by: Julien Vuillaumier Reviewed-by: Jacopo Mondi --- Documentation/environment_variables.rst | 5 ++ include/libcamera/internal/camera_manager.h | 1 + src/libcamera/camera_manager.cpp | 57 ++++++++++++++++----- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Documentation/environment_variables.rst b/Documentation/environment_variables.rst index a9b230bc..ea4da3c9 100644 --- a/Documentation/environment_variables.rst +++ b/Documentation/environment_variables.rst @@ -37,6 +37,11 @@ LIBCAMERA_IPA_MODULE_PATH Example value: ``${HOME}/.libcamera/lib:/opt/libcamera/vendor/lib`` +LIBCAMERA_PIPELINES_MATCH_LIST + Define an ordered list of pipeline names to be used to match the media devices in the system. + + Example value: ``PipelineHandlerRkISP1,SimplePipelineHandler`` + LIBCAMERA_RPI_CONFIG_FILE Define a custom configuration file to use in the Raspberry Pi pipeline handler. diff --git a/include/libcamera/internal/camera_manager.h b/include/libcamera/internal/camera_manager.h index 33ebe069..c57e509a 100644 --- a/include/libcamera/internal/camera_manager.h +++ b/include/libcamera/internal/camera_manager.h @@ -45,6 +45,7 @@ private: int init(); void createPipelineHandlers(); void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_); + void pipelineFactoryMatch(const PipelineHandlerFactoryBase *factory); /* * This mutex protects diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 355f3ada..620be1c8 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -99,13 +99,36 @@ int CameraManager::Private::init() void CameraManager::Private::createPipelineHandlers() { - CameraManager *const o = LIBCAMERA_O_PTR(); - /* * \todo Try to read handlers and order from configuration - * file and only fallback on all handlers if there is no - * configuration file. + * file and only fallback on environment variable or all handlers, if + * there is no configuration file. + */ + + /* + * When a list of preferred pipelines is defined, iterate through the + * ordered list to match the devices enumerated. + * Otherwise, device matching is done in no specific order with each + * registered pipeline handler. */ + const char *pipesList = + utils::secure_getenv("LIBCAMERA_PIPELINES_MATCH_LIST"); + if (pipesList) { + for (const auto &pipeName : utils::split(pipesList, ",")) { + const PipelineHandlerFactoryBase *factory; + factory = PipelineHandlerFactoryBase::getFactoryByName(pipeName); + if (!factory) + continue; + + LOG(Camera, Debug) + << "Found listed pipeline handler '" + << pipeName << "'"; + pipelineFactoryMatch(factory); + } + + return; + } + const std::vector &factories = PipelineHandlerFactoryBase::factories(); @@ -117,15 +140,25 @@ void CameraManager::Private::createPipelineHandlers() * Try each pipeline handler until it exhaust * all pipelines it can provide. */ - while (1) { - std::shared_ptr pipe = factory->create(o); - if (!pipe->match(enumerator_.get())) - break; + pipelineFactoryMatch(factory); + } +} - LOG(Camera, Debug) - << "Pipeline handler \"" << factory->name() - << "\" matched"; - } +void CameraManager::Private::pipelineFactoryMatch(const PipelineHandlerFactoryBase *factory) +{ + CameraManager *const o = LIBCAMERA_O_PTR(); + + /* + * Provide as many matching pipelines as possible + */ + while (1) { + std::shared_ptr pipe = factory->create(o); + if (!pipe->match(enumerator_.get())) + break; + + LOG(Camera, Debug) + << "Pipeline handler \"" << factory->name() + << "\" matched"; } }