From patchwork Wed Mar 27 17:27:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Vuillaumier X-Patchwork-Id: 19819 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 6709BBD160 for ; Wed, 27 Mar 2024 17:28:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 212B763354; Wed, 27 Mar 2024 18:28:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="RK/wXtKH"; dkim-atps=neutral Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on20601.outbound.protection.outlook.com [IPv6:2a01:111:f403:260f::601]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A4D7363331 for ; Wed, 27 Mar 2024 18:28:10 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lp2b0Y5DFXfLJItYeUTMPmPcgEEgQnxISNGt99fgPpNa00qzoKFCXVz7MnROOn0oreuRHTbK6iil3XJE44IV9mebG4VeJbtYGMARWT4BIWVgJ0S1gai4j0soexqGGwJrTnv0u+sQgYWvO2UTKfXcOACJ7zZFVhvRGzaznxucx+Fxv0lxbbrC5RO1ITKodpTBxndI8yfopNDQsKfBJtW+QS0saXO4XR/BSiohATUSfA8zmP9FlXD7VFRMw0PexNL1IYpNdk3vVy558KuRAxfTMoZCfAWBIGF8qijSzv/xmej1yQh5PL35xTHHQLTB9T+GYgCD4PzB3dmOJNZTJg3PzA== 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=tJ1iULtkpwCOr84ZAiqsCOjAYc3Zi89uB0Fgsk89Suo=; b=UYlL6+83xkKazm32iVxoPAhImOj5DBDULBKPa5L9iUUe950gH8mDj0I1w/TpJup4i25DLOddgLSlGRq2YoAlT56FX7Gr7O8/l16+8VkkUCpQKMjEkKaBvVHJruhb5SqWzlvDcshYMpm7g9zqnMxysAj7fMRX7L4I/iCGXQ4hx+yoLgsoT/DcgVYswiskPpdpzgZU1T9R3/BNeCTkRtdgRo9LF/IiZEWExiXVnQ/9TztuNKkLRGTEz7MIRjDOio5vY9dnw+aqf6w7A+O0ssGzsLUNaFpFbUqVSL+4Z4bD7TxB1DED8RySt/h/7N2GqD3JeNUk5CHTwLe9hueWS8Q2Ww== 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=tJ1iULtkpwCOr84ZAiqsCOjAYc3Zi89uB0Fgsk89Suo=; b=RK/wXtKHygRRGjrQczjQKr5+cXU/VW/P/H6X81tiPEjmwqNbC3icN15I0s0glWJhDSumpILC4uMKdQrxIh1fUECAarZYV/Xzfb3JR3vC1r9H85UwWtL5WB+eLmDyY90rIiIt6w/8ELcApUEOYtmJXvsgND7CmUAKNO30smzAVbk= 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 AM0PR04MB6913.eurprd04.prod.outlook.com (2603:10a6:208:184::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Wed, 27 Mar 2024 17:28:09 +0000 Received: from AM9PR04MB8147.eurprd04.prod.outlook.com ([fe80::2208:ff47:a8fe:dea6]) by AM9PR04MB8147.eurprd04.prod.outlook.com ([fe80::2208:ff47:a8fe:dea6%5]) with mapi id 15.20.7409.031; Wed, 27 Mar 2024 17:28:09 +0000 From: Julien Vuillaumier To: libcamera-devel@lists.libcamera.org Cc: julien.vuillaumier@nxp.com, Jacopo Mondi Subject: [PATCH v3 2/2] libcamera: camera_manager: Add environment variable to order pipelines match Date: Wed, 27 Mar 2024 18:27:31 +0100 Message-Id: <20240327172731.434048-3-julien.vuillaumier@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240327172731.434048-1-julien.vuillaumier@nxp.com> References: <20240327172731.434048-1-julien.vuillaumier@nxp.com> X-ClientProxiedBy: AM0PR02CA0167.eurprd02.prod.outlook.com (2603:10a6:20b:28d::34) To AM9PR04MB8147.eurprd04.prod.outlook.com (2603:10a6:20b:3e0::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8147:EE_|AM0PR04MB6913:EE_ X-MS-Office365-Filtering-Correlation-Id: a7f7e37d-fe93-4e46-8878-08dc4e83455e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 42endNeR+oANSGfrSZdxk01EsPsOGBErKY0sH+B+wKBFaIXbAj1Vcn8FBxN/SoNCgeeJ8ecm5ZSaJZB+BizWT/o76roTxreUQaidKS0qQvuMdmcNPYfu/5R4nECReqR23cO6y5944VloYbl/7G7j762VR8bG0RDdYoHx3LI5Ep5i/XT0UVDAcqubPXGwld8vI+pYYIpS2KmuKkR5T64C6kp4HeaCeLNZwxkEVAMJQS+EUkkj7a6a0swdI+bZRHRkC8G8v9nYl0gt+/Kym7kec5Y21ErK6vwwQeT/bx08f1V6pw5TicVO4CUd7mKttj8ifgUoBqXiNJ0hTQbpzj2eOvmdE2gG9A4w9gnumyKdTce5IeOu4cWTXlfdQzfrpFcP7ylrA83jG5qfAQh5cX62J8XR7KoNnvISl/FY60ohXtw7yUfH2iN/3RFORRTVBVfKTfFIEZA4ZTa76hn7OIqz4N0FraYRRRBw9oFIzSCdRmd71Qx3Og7QU1+ICRGH7Oc/DffQJ1WQBr5aNcns9tWdYruaBjAtuTqUOrbHCdNp5G5wKBEgKemy+l6X9atk3pqdry59ag4otuNDTudssIO9jE0aQZvy7h9qfo47867JNCU5b/FbRHkAXFRK5H6fVBMg1BMcWxVQFuQ665c3BHQ1tcPG8vsNxwpyvp4JGgiku1PvjbGVuqQNVGN7OqfyzpXKOZIUnniRHuKRUlJEcuAHzg== 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)(366007)(1800799015)(52116005)(38350700005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AjQffDnFFQiDP41Aps9D+1TLbhWDhK/n1wYDO0Hv9+52LTaW/J08JWC+4xJiv/osT9HtU+x69uCyY8W8SLFsRL4Igb315hpjBsw+JdfeM7mACbAzj9eUKAlNINh35JV7EILL2rfg8/VGixjtxuEmtncmVpyGXrOOBFuO0aiR5ibcgYc+aVWq/zXOsEIr1XMn6AQoEPUQUS3f3gCD9UcB7kiiZBva+vPrHX858AhLKWCv9hXbyQBMhPfazNVn7DlAbfEJuClE4Cc2tpf5j79G8XCz+TvQGu+gmu6FxbXOGVv8RviCMZfvHevUds5HHvUSTr2FUGc6VXMTy8MBJzyV87eDwVM50If5p7tuOeF1ULsOQV6mb5ZiTtE+K/j8QZ4GPTJnZNxFJG11OiYE6syIbIq6sCkJBGCAMu3C5ELa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J17K4r2QvHYTIAeQGUaK3/B4uNJMm1adG1aRD0ZWDAXcojzAgJbqlEyL5NiWrQBGfXNRQMWR2TLlbaEjuCSYaThICsp9i/4ILj4nXgk9Ws0y1Q== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7f7e37d-fe93-4e46-8878-08dc4e83455e X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8147.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 17:28:09.3275 (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: fG8krlYjefnjCM7OUbdutz+d4TuI/bJ2JjKqEjNz/6WJKU2RAr8LxeILQ/5vD5z/Brh13TblBuISvA+7JsgGA+25GQ/KACH5GkH9NhiHagc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6913 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 registered pipeline handler 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 to give the option to define an ordered list of pipelines to match on. LIBCAMERA_PIPELINES_MATCH_LIST="[,[,...]]]" Example: LIBCAMERA_PIPELINES_MATCH_LIST="PipelineHandlerRkISP1,SimplePipelineHandler" Signed-off-by: Julien Vuillaumier Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- Documentation/environment_variables.rst | 8 ++++ include/libcamera/internal/camera_manager.h | 1 + src/libcamera/camera_manager.cpp | 53 ++++++++++++++++----- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Documentation/environment_variables.rst b/Documentation/environment_variables.rst index a9b230bc..c763435c 100644 --- a/Documentation/environment_variables.rst +++ b/Documentation/environment_variables.rst @@ -37,6 +37,14 @@ 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. The pipeline handler names used to populate the + variable are the ones passed to the REGISTER_PIPELINE_HANDLER() macro in the + source code. + + 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..5694d40d 100644 --- a/include/libcamera/internal/camera_manager.h +++ b/include/libcamera/internal/camera_manager.h @@ -44,6 +44,7 @@ protected: private: int init(); void createPipelineHandlers(); + void pipelineFactoryMatch(const PipelineHandlerFactoryBase *factory); void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_); /* diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 355f3ada..ce6607e1 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -99,16 +99,37 @@ 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. */ + const char *pipesList = + utils::secure_getenv("LIBCAMERA_PIPELINES_MATCH_LIST"); + if (pipesList) { + /* + * When a list of preferred pipelines is defined, iterate + * through the ordered list to match the enumerated devices. + */ + 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(); + /* Match all the registered pipeline handlers. */ for (const PipelineHandlerFactoryBase *factory : factories) { LOG(Camera, Debug) << "Found registered pipeline handler '" @@ -117,15 +138,23 @@ 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"; } }