From patchwork Fri May 3 14:49:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Vuillaumier X-Patchwork-Id: 20000 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 7A0D1C32C9 for ; Fri, 3 May 2024 14:50:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D40F663424; Fri, 3 May 2024 16:50:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="D9/6MnYJ"; 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 092C463418 for ; Fri, 3 May 2024 16:50:01 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g3BWbBipQglNtrMPYcomoKIyj2fk5epYLzwuqV5U/Wns7eXkRzfmHadxPDL7MNQddjtrKnbot9ixSvUoQSAMkx/nFTaDmgvajQEVW9F0P9ev13b6y0MNAIQNT1Sd/sj5I5Y2VB7osIJS3TVGq6f47o2wILnuGasvgcfEzoZasaT1NV4vHYerSqhAbg2Z8gX3ObPiSiuF3Jr6y41ffzVNBaidMPWxkVYh/J5LOn/UTDBjzTYk0sj2Gj1lak3vmxTTjCR0YwKuZQn+FoiwOWU1dP4xuk1E5lhlEFqqy4LwKLiJudPKW0DtEql+SDMohWF/0saEQuIxHaFVmX/VOCuoMg== 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=rU9/Qw6PkUXap96LyU45h9YkfzExaDjBmlCXecYLFKg=; b=UMOoKZWNfgeB0S/obtf3pcjjjfGKGYy6RCxwjdXtgbzXjiKSthmEfBPPwLe2VbNS+H7Dbm3GItEqTHupPTwzNvDTSvkMut846WVEU7S5QnUb7gTWw66JSXEJ6c0uB35VP0+TU2K+Qv1p972JhAHzzsKIWBfJIQV6d3PupaWc+0eJoABuMMsG6rhP5wqPZ5D5VLs5YpeCJWAEAXG2TXHDcXOOsIROKZllDAj8qOP91FU/5rcVmZ6VtDA4PEr1ZWQN5/YyAL1NB/3Lc+hgeeDLroa5TFRpSvg1tA70eTzaFD0JHxd1IwqO3yPX4A+Mhz9h6z6sFLTE+mQhAN8l/OSFZA== 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=rU9/Qw6PkUXap96LyU45h9YkfzExaDjBmlCXecYLFKg=; b=D9/6MnYJekVjDc15GZzbYHAEjx6TzuwQls0PT3FlpqdjqqOtRs/xcEsV0BhC7Q1GeYxADFA1iNhFarr9A2fXzIxsowzu2TfgJaITDuFA4WJZ/TpUIeS4lGcJ0MD56HK/bqohH2dt/OU+xC/s7p6100MuAlz82mNIACjtzEIZN0c= 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 PAXPR04MB9570.eurprd04.prod.outlook.com (2603:10a6:102:24d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.30; Fri, 3 May 2024 14:49:59 +0000 Received: from AM9PR04MB8147.eurprd04.prod.outlook.com ([fe80::eace:e980:28a4:ef8a]) by AM9PR04MB8147.eurprd04.prod.outlook.com ([fe80::eace:e980:28a4:ef8a%2]) with mapi id 15.20.7544.029; Fri, 3 May 2024 14:49:59 +0000 From: Julien Vuillaumier To: libcamera-devel@lists.libcamera.org Cc: jacopo.mondi@ideasonboard.com, kieran.bingham@ideasonboard.com, julien.vuillaumier@nxp.com Subject: [PATCH v4 3/3] libcamera: camera_manager: Add environment variable to order pipelines match Date: Fri, 3 May 2024 16:49:19 +0200 Message-Id: <20240503144919.2371357-4-julien.vuillaumier@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240503144919.2371357-1-julien.vuillaumier@nxp.com> References: <20240503144919.2371357-1-julien.vuillaumier@nxp.com> X-ClientProxiedBy: AM0PR03CA0003.eurprd03.prod.outlook.com (2603:10a6:208:14::16) To AM9PR04MB8147.eurprd04.prod.outlook.com (2603:10a6:20b:3e0::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8147:EE_|PAXPR04MB9570:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b3fcb57-6f92-453d-8b17-08dc6b804e12 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|52116005|1800799015|376005|366007|38350700005; X-Microsoft-Antispam-Message-Info: sl/wq8OnAigtb/nbnH5UvFcVYJu6Z886iluQuFxvEnfz7nBq5pqOsivNmhzNV/YqV3gYIzbo2N7Yd7UIinB5DVZ5EsLQmvWmpWGN5bVxYFXmdmLYko8sY2BjNMW+iumUj1n/JfDKsUur9ijvlI3OAQN4v1AlrE4d/ISnJqgj7nYE85lexSfSnVqSoLTW/5q9z1ix09lZb8fD59FyWkHepHKdoSG0ix0THgdr+g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K7IVXLsMCpbmn/+jcKu1SfszaBE/fxdT8+uzdxuYrNlFtQAsRud2mJWMfvA== 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)(52116005)(1800799015)(376005)(366007)(38350700005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kQ5cXTi92w4lPXRgC6lgkCA4JRA83WvUcFmPGuG/IbfnXPPoPlPeh8lRw9+tySp09UmdbeAcF99z47y1klkungUkBoJQOfaK0s8imIvjKZULa7PNnFQ1qv9O8ZOreHPiHNh/xtakzdGwI+NQwfKUL60GKIRN/YlmaCAK5IyyIY0EEoqrHYEEW2jyoBbW5q8b9rPb0lzXuHBeO/zDT5NkgjjXjVKlc06MnowvSG07ZjD+9tf/bh3KjLNNjpw/a36vo2PmCZFB9H3hUhUm5yM7C2BrO1GsbrRmHxWUSw/YBYIdx2qBlMXiZDTP7y7YgaL8SSD0XNsuBGZSqMV9BDMbrdxqm7jbclGLIlKw/ipySJrYl0eaKnt4QqZ9JD8b5M2ARt0JEaRq/XlIbMF0YZhq9kudPNDrWTvgs9f0mUg6ctbEb4+g16RyyrbzwixhCl5Wu3KzY6MhOkjwiCZWtZoTpJ5n3HGzRU4S40KMBeuS0isFxvQcWcXHuUZuAY8J4561lYgcHsWTrBZPAeysNfS8iiJj1r5pFxcAnB0L0cvPed7kbe0r2kPyuzsJHBe4bLq3xPmJLIhmsMhQOQDX0wlRR3ZxCY72guj9qrMoPKVqX8pGMvtV9DlRy8tsZgaUPPCSbEg4AKsYMOifVpZVlpfkw0ss0rNbZ0huN2AXp5RNmAX30b+kLIGOmM+u6WWwwsltkv51oQqxrkk8+y5MLKaVCpe9C2kgS7/LVRZKBU6Dud5cBzhpX9KJxlezsRcJOh3jG8PMmnbcraNgrbcJnUfeXXjQaLmMgwZ7FMSdCc22wNM6fkK4U1Dz6e6Q2BURoBx5X037N9l3scXvItNWFzlb6grCLZL0/qx6sENN0Jgl8lB/fmZl4wauoyiChqw0gFAgE+u8PkoceSyYp8k2CKjCHxKoZqsxyrO08B3tLbrGtuptxBLupBv5f38GebKPy6MfmHuTocQ0Adb6AuKMyy1El+507oOgyME8iJ6UDVpgJUDMxmatffdTO863tbfZ4tcLlywQBJ9tI5kG/pIRX7/tNh88BOVZvnG1T6ljNEZGeBSRP4GGljnXk6aO/i37aynw1IU51yPGm0KU2lSxFZS7mR88wTzR0Ak+CJ8YsFvgMwW27/YdY/prcK2wATyUKNJzAJ5/bGX/4SSL2Sr0dwU5k4JgzifHp89MhvleKPAss1ZF1oFnnE57A4xuGL6g5kd9p0Fijhh9RnFWU6Rr2FlKmPA2+6AUW/nk4WVloL1/L7jDy/sgl5FjKnM62AQ9vB/iiipANttz9liBgMaE/Rr245PmkPnjBLhZPdGEeO2R7rruatfJaRFynMzXSLzcQshk02ZKtZkr2OPHEyS7z0O7HXjicu1a1QyeMcCrEAdgH/xNJjgb59ti1OL19dwFltfRhz+LIGtTmIiJ6XhX7VQ66b24Sx36fwGbgu3njprvL68fgHqvcK5RV74To6kmgxLGP9014lHnySrXwtCnOUGx1FW2O0HsPs8rQ6Pz6hGmy5MpFLrR/hkEJt19AoQ6635nC9sLCt9Y32ajLTLHTrAo3ZRse05QGe2wXvM5/+kQVZYFBnmCOnlzj5QkSeC9EoDD4UAjfVUccS2wP/pXSLD7EA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b3fcb57-6f92-453d-8b17-08dc6b804e12 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8147.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2024 14:49:59.0916 (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: tHhtvrJiPM6bjC0xm/0zU7PjbIk4znrmV66cmzbbWPbzhh8xN1B8x63AvaTr/1xW8VxdWiXGVDZH/Xn7NPyvM2T03NCQMhdsFH2JD+EY1RM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9570 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="rkisp1,simple" 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..4e9fbb27 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: ``rkisp1,simple`` + 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"; } }