{"id":18634,"url":"https://patchwork.libcamera.org/api/patches/18634/?format=json","web_url":"https://patchwork.libcamera.org/patch/18634/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20230515124550.3601128-6-kieran.bingham@ideasonboard.com>","date":"2023-05-15T12:45:50","name":"[libcamera-devel,v3,5/5] libcamera: pipeline: Register device numbers with camera","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"2f5b1b22d4295f35792f4e7412882b2c5c0a98aa","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18634/mbox/","series":[{"id":3878,"url":"https://patchwork.libcamera.org/api/series/3878/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3878","date":"2023-05-15T12:45:45","name":"libcamera: Add new Camera devices property","version":3,"mbox":"https://patchwork.libcamera.org/series/3878/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18634/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18634/checks/","tags":{},"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 C5855C32A5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 15 May 2023 12:46:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CDC5862861;\n\tMon, 15 May 2023 14:45:59 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 36E58627DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 May 2023 14:45:55 +0200 (CEST)","from Monstersaurus.local\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8316B4DB;\n\tMon, 15 May 2023 14:45:44 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1684154759;\n\tbh=NAHs9FK9AVfQThDyoQpZ9B+QTH6lGyz46GyQML1npQk=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=SRKdkizuacsuZezajvJSBh9S0A0LvYcV5oanbQcgcAoapEU9vFSgoLO0IAsJ0d0d6\n\t1EMweegIOYhzrsGIaPNH21fFfjAmUPG6n0w2JRaejhIFAWrkc4n6pSi4MTYKTAF0+s\n\tznlgTDSL2IK9y9kKmKEdfnVoDFt7eLdc0ArTlzgjUZOSClY/h2zDgtZTXIDF0P269Z\n\tYNK8CQRrORjWIGVpJl/kNPVamnJX7PRrMU2EjJPSoLQiDtRk+3ljfhTmUfYVb5YqVN\n\tBgG2Plvgjgn84fShhpwbKfTfKUKhxBTyv8gFuGMk+EccEQY+awBt5bw3WPM9hjlFOH\n\tP8UcAKICSCXPg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1684154744;\n\tbh=NAHs9FK9AVfQThDyoQpZ9B+QTH6lGyz46GyQML1npQk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=OE5LmTpun/B/RtF9RndIh07JG5regN/iLOfEzLOAkQarQCbIO+uP4ydyutvCXwxIR\n\t5XchaAFex0rysNLIbWVjfXD0YfUC/L7RmdjPr+w78jkbs0d8Q0/LJeeDCjSZoncsLb\n\tiOwk+pZsMFooUrhrty05ST8FIz88/GUij4QzFOso="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"OE5LmTpu\"; dkim-atps=neutral","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Mon, 15 May 2023 13:45:50 +0100","Message-Id":"<20230515124550.3601128-6-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20230515124550.3601128-1-kieran.bingham@ideasonboard.com>","References":"<20230515124550.3601128-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 5/5] libcamera: pipeline: Register\n\tdevice numbers with camera","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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Register the identified device numbers with each camera as the Devices\nproperty.\n\nThis facilitates camera daemons or other systems to identify which\ndevices are being managed by libcamera, and can prevent duplication of\ncamera resources.\n\nAs the Devices property now provides this list of devices, use it\ndirectly from within the CameraManager when adding a Camera rather than\npassing it through the internal API.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/camera_manager.h |  3 +--\n src/libcamera/camera_manager.cpp            | 14 +++++++++-----\n src/libcamera/pipeline_handler.cpp          | 12 ++++++++++--\n 3 files changed, 20 insertions(+), 9 deletions(-)","diff":"diff --git a/include/libcamera/internal/camera_manager.h b/include/libcamera/internal/camera_manager.h\nindex 885bb2825687..680e1f58cb02 100644\n--- a/include/libcamera/internal/camera_manager.h\n+++ b/include/libcamera/internal/camera_manager.h\n@@ -29,8 +29,7 @@ public:\n \tPrivate();\n \n \tint start();\n-\tvoid addCamera(std::shared_ptr<Camera> camera,\n-\t\t       const std::vector<dev_t> &devnums) LIBCAMERA_TSA_EXCLUDES(mutex_);\n+\tvoid addCamera(std::shared_ptr<Camera> camera) LIBCAMERA_TSA_EXCLUDES(mutex_);\n \tvoid removeCamera(std::shared_ptr<Camera> camera) LIBCAMERA_TSA_EXCLUDES(mutex_);\n \n \t/*\ndiff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nindex 70eb4e455e54..7e499def9ddc 100644\n--- a/src/libcamera/camera_manager.cpp\n+++ b/src/libcamera/camera_manager.cpp\n@@ -15,7 +15,9 @@\n #include <libcamera/base/utils.h>\n \n #include <libcamera/camera.h>\n+#include <libcamera/property_ids.h>\n \n+#include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/pipeline_handler.h\"\n \n@@ -150,19 +152,17 @@ void CameraManager::Private::cleanup()\n /**\n  * \\brief Add a camera to the camera manager\n  * \\param[in] camera The camera to be added\n- * \\param[in] devnums The device numbers to associate with \\a camera\n  *\n  * This function is called by pipeline handlers to register the cameras they\n  * handle with the camera manager. Registered cameras are immediately made\n  * available to the system.\n  *\n- * \\a devnums are used by the V4L2 compatibility layer to map V4L2 device nodes\n- * to Camera instances.\n+ * Device numbers from the Devices property are used by the V4L2 compatibility\n+ * layer to map V4L2 device nodes to Camera instances.\n  *\n  * \\context This function shall be called from the CameraManager thread.\n  */\n-void CameraManager::Private::addCamera(std::shared_ptr<Camera> camera,\n-\t\t\t\t       const std::vector<dev_t> &devnums)\n+void CameraManager::Private::addCamera(std::shared_ptr<Camera> camera)\n {\n \tASSERT(Thread::current() == this);\n \n@@ -177,6 +177,10 @@ void CameraManager::Private::addCamera(std::shared_ptr<Camera> camera,\n \t\t}\n \t}\n \n+\tauto devnums = camera->properties()\n+\t\t\t       .get(properties::Devices)\n+\t\t\t       .value_or(Span<int64_t>{});\n+\n \tcameras_.push_back(std::move(camera));\n \n \tunsigned int index = cameras_.size() - 1;\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 49092ea88a58..0b5fac7ad113 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -17,6 +17,7 @@\n \n #include <libcamera/camera.h>\n #include <libcamera/framebuffer.h>\n+#include <libcamera/property_ids.h>\n \n #include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/camera_manager.h\"\n@@ -612,7 +613,7 @@ void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera)\n \t * Walk the entity list and map the devnums of all capture video nodes\n \t * to the camera.\n \t */\n-\tstd::vector<dev_t> devnums;\n+\tstd::vector<int64_t> devnums;\n \tfor (const std::shared_ptr<MediaDevice> &media : mediaDevices_) {\n \t\tfor (const MediaEntity *entity : media->entities()) {\n \t\t\tif (entity->pads().size() == 1 &&\n@@ -624,7 +625,14 @@ void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera)\n \t\t}\n \t}\n \n-\tmanager_->_d()->addCamera(std::move(camera), devnums);\n+\t/*\n+\t * Store the associated devices as a property of the camera to allow\n+\t * systems to identify which devices are managed by libcamera.\n+\t */\n+\tCamera::Private *data = camera->_d();\n+\tdata->properties_.set(properties::Devices, devnums);\n+\n+\tmanager_->_d()->addCamera(std::move(camera));\n }\n \n /**\n","prefixes":["libcamera-devel","v3","5/5"]}