[{"id":27475,"web_url":"https://patchwork.libcamera.org/comment/27475/","msgid":"<20230704232223.GD7148@pendragon.ideasonboard.com>","date":"2023-07-04T23:22:23","subject":"Re: [libcamera-devel] [PATCH v2 1/2] v4l2: Use SystemDevices\n\tproperties to identify cameras","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Tue, Jul 04, 2023 at 11:57:45PM +0100, Kieran Bingham via libcamera-devel wrote:\n> The CameraManager->get(dev_t) helper was implemented only to support the\n> V4L2 Adaptation layer, and has been deprecated now that a new camera\n> property - SystemDevices has been introduced.\n> \n> Rework the implementation of getCameraIndex() to use the SystemDevices\n> property and remove reliance on the now deprecated call.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/v4l2/v4l2_compat_manager.cpp | 29 ++++++++++++++++++++++++-----\n>  1 file changed, 24 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp\n> index 0f7575c54b22..948dadad646d 100644\n> --- a/src/v4l2/v4l2_compat_manager.cpp\n> +++ b/src/v4l2/v4l2_compat_manager.cpp\n> @@ -24,6 +24,7 @@\n>  \n>  #include <libcamera/camera.h>\n>  #include <libcamera/camera_manager.h>\n> +#include <libcamera/property_ids.h>\n>  \n>  #include \"v4l2_camera_file.h\"\n>  \n> @@ -113,14 +114,32 @@ int V4L2CompatManager::getCameraIndex(int fd)\n>  \tif (ret < 0)\n>  \t\treturn -1;\n>  \n> -\tstd::shared_ptr<Camera> target = cm_->get(statbuf.st_rdev);\n> -\tif (!target)\n> -\t\treturn -1;\n> +\tconst dev_t devnum = statbuf.st_rdev;\n>  \n> +\t/*\n> +\t * Iterate each known camera and identify if it reports this nodes\n> +\t * device number in its list of SystemDevices.\n> +\t */\n>  \tauto cameras = cm_->cameras();\n>  \tfor (auto [index, camera] : utils::enumerate(cameras)) {\n> -\t\tif (camera == target)\n> -\t\t\treturn index;\n> +\t\tSpan<const int64_t> devices = camera->properties()\n> +\t\t\t\t\t\t      .get(properties::SystemDevices)\n> +\t\t\t\t\t\t      .value_or(Span<int64_t>{});\n> +\n> +\t\t/*\n> +\t\t * While there may be multiple Cameras that could reference the\n\ns/Cameras/Camera instances/ (or just cameras)\n\n> +\t\t * same device node, we take a first match as a best effort for\n> +\t\t * now.\n> +\t\t *\n> +\t\t * \\todo Consider reworking the V4L2 adaptation layer to stop\n> +\t\t * trying to map video nodes directly to a camera and instead\n> +\t\t * hide all devices that may be used by libcamera and expose a\n> +\t\t * consistent 1:1 mapping with each Camera instance.\n\nTrying to word this in a way that would help me understand it better:\n\n\t\t * \\todo Each camera can be accessed through any of the video\n\t\t * device nodes that it uses. This may confuse applications.\n\t\t * Consider reworking the V4L2 adaptation layer to instead\n\t\t * expose each Camera instance through a single video device\n\t\t * node (with a consistent and stable mapping). The other device\n\t\t * nodes could possibly be hidden from the application by\n\t\t * intercepting additional calls to the C library.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t\t */\n> +\t\tfor (const int64_t dev : devices) {\n> +\t\t\tif (dev == static_cast<int64_t>(devnum))\n> +\t\t\t\treturn index;\n> +\t\t}\n>  \t}\n>  \n>  \treturn -1;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D41B2BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  4 Jul 2023 23:22:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42BD0628BB;\n\tWed,  5 Jul 2023 01:22:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 14DBD61E38\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Jul 2023 01:22:24 +0200 (CEST)","from pendragon.ideasonboard.com (85-160-42-71.reb.o2.cz\n\t[85.160.42.71])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 659B88CC;\n\tWed,  5 Jul 2023 01:21:39 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1688512946;\n\tbh=5hufJQzBOeFG4Vc+Y2HuDjTQI6ho6z9DNMldbJVKpC4=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=BBZVyymE8stff7p4HoUdq6/UAqJ3Fro/yXCuaZ/UF+q4/K9Vs+DsW4YpEuRXYJ07/\n\tPvA/OU7d8rfEc5Nk5HZ+SpNjk7an0nhceB5q0LNvkaC955NJYELBZNl2sfljhU0XE4\n\tXxAdUFfIPlPnLWom/oOfQnaLxrp7ZK/mFt8PadTwCniJFOXmprvBT16SeOMvdExiZw\n\t1SmTLvUOhtM3LBeOfnpaMXB203cZzkczwPr+bGyRhFqukEDtndPI4lUoDCH59z8DXN\n\tSrMbul0leOXS0U2jPUDk1z0b3CW+8gmWy1JYU7/j8h4gb4X/0qczikmnCfMIB0pPer\n\tdDSHEYqMmGhNA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1688512899;\n\tbh=5hufJQzBOeFG4Vc+Y2HuDjTQI6ho6z9DNMldbJVKpC4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=EJ1GzA6/aTnbCyt5y2JddkzT3cozhWgpg2Kc/LdpTk4TBtADanRer2LdMxh0eE3ro\n\tZkQ+qgL+QkOD51CBOWYpjI/CAsakJ/N5NfC9q5eYxM3Bl7D0s26GYghGbqRBYVgSDj\n\tKQYAMoSWQg9ATLBO1uvTv7E4bxsq5x8VZ1HVfl50="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"EJ1GzA6/\"; dkim-atps=neutral","Date":"Wed, 5 Jul 2023 02:22:23 +0300","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20230704232223.GD7148@pendragon.ideasonboard.com>","References":"<20230704225746.3838484-1-kieran.bingham@ideasonboard.com>\n\t<20230704225746.3838484-2-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230704225746.3838484-2-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 1/2] v4l2: Use SystemDevices\n\tproperties to identify cameras","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]