From patchwork Thu Jun 15 22:51:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18745 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 48CBCC322E for ; Thu, 15 Jun 2023 22:51:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F0EC5628B5; Fri, 16 Jun 2023 00:51:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686869501; bh=0apE+OXO3+ttEexAiaZTI8fAdClf0EQZjcXMlcwSsd4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fUqppE2hmHfBzN/h9xJYdSrFkCU0SNE1YNG9YQ3KqGXo09OpWM+IY1SlY6YTFnSY9 5D3DCeI+KNqQ8J3qYfiE9UDU96OaNzNR7nQggj8IV7WNcDg3Fdvlbk1lORa6SkWxu5 Enn0wN7YfPXjRBTaAO80F6T50/q7WV+G3yaLp3jZRUktN2TuwGq7ATlkF3cRFJg5Tk RpPaZw26OCksdWIuNc0mHdtLCySlsHK7TzkGS0uSRAe7KmWnnOzLJTqdWI2I8PNami JpMMtYSxTMAR5SjeJsDV4lWjs350Qd0WqNRJuhDAEku8T8RRPRpFW8gMrKtU9bwgQ+ VT7YStrkctQ8A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 09FA261E4F for ; Fri, 16 Jun 2023 00:51:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sKiIsAZn"; dkim-atps=neutral Received: from Monstersaurus.local (aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net [82.37.23.78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 36824C7F; Fri, 16 Jun 2023 00:51:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686869466; bh=0apE+OXO3+ttEexAiaZTI8fAdClf0EQZjcXMlcwSsd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sKiIsAZnUw3ezlOefMTFEmge9cZrLysXCqPa3u/dn1YWdhxvz0u4a6kw98G8dNpeK +jXDg8mPba086/JBUjNhP2fdG2hUXitAZFbiTbFhr/9VBQYCUT+1EdHw3TRO6FDSNl OxVzxVNU0IK2OT04udPJYLJYtQUnu+5ospwf9eYw= To: libcamera devel Date: Thu, 15 Jun 2023 23:51:32 +0100 Message-Id: <20230615225133.622612-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230615225133.622612-1-kieran.bingham@ideasonboard.com> References: <20230615225133.622612-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] v4l2: Use SystemDevices properties to identify cameras 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: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraManager->get(dev_t) helper was implemented only to support the V4L2 Adaptation layer, and has been deprecated now that a new camera property - SystemDevices has been introduced. Rework the implementation of getCameraIndex() to use the SystemDevices property and remove reliance on the now deprecated call. Signed-off-by: Kieran Bingham --- src/v4l2/v4l2_compat_manager.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index 0f7575c54b22..c49124290b42 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "v4l2_camera_file.h" @@ -113,14 +114,31 @@ int V4L2CompatManager::getCameraIndex(int fd) if (ret < 0) return -1; - std::shared_ptr target = cm_->get(statbuf.st_rdev); - if (!target) - return -1; + const dev_t devnum = statbuf.st_rdev; + /* + * Iterate each known camera and identify if it reports this nodes + * device number in its list of SystemDevices. + */ auto cameras = cm_->cameras(); for (auto [index, camera] : utils::enumerate(cameras)) { - if (camera == target) - return index; + const auto devices = camera->properties() + .get(properties::SystemDevices) + .value_or(std::vector{}); + + /* + * While there may be multiple Cameras that could reference the + * same device node, we take a first match as a best effort for + * now. + * + * \todo Consider reworking the V4L2 adaptation layer to stop + * trying to map video nodes directly to a camera and instead + * hide all devices that may be used by libcamera and expose a + * consistent 1:1 mapping with each Camera instance. + */ + for (const int64_t dev : devices) + if (dev == static_cast(devnum)) + return index; } return -1;