Patch Detail
Show a patch.
GET /api/patches/18930/?format=api
{ "id": 18930, "url": "https://patchwork.libcamera.org/api/patches/18930/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18930/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230808125228.29043-4-jacopo.mondi@ideasonboard.com>", "date": "2023-08-08T12:52:22", "name": "[libcamera-devel,RFC,3/9] libcamera: device_enumerator: Prepare for more device types", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "41d611eab058b315cc59b3298e4209e2b6821294", "submitter": { "id": 143, "url": "https://patchwork.libcamera.org/api/people/143/?format=api", "name": "Jacopo Mondi", "email": "jacopo.mondi@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18930/mbox/", "series": [ { "id": 4002, "url": "https://patchwork.libcamera.org/api/series/4002/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4002", "date": "2023-08-08T12:52:19", "name": "libcamera: Generalize device match and support USB devices", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4002/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18930/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18930/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 4D495BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 8 Aug 2023 12:52:55 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EF09A627EF;\n\tTue, 8 Aug 2023 14:52:54 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 35D6361E19\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 8 Aug 2023 14:52:48 +0200 (CEST)", "from uno.localdomain (mob-5-90-60-22.net.vodafone.it [5.90.60.22])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5C207396B; \n\tTue, 8 Aug 2023 14:51:40 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1691499175;\n\tbh=pSSxhla5CU9zLBFJD8ZnASnLfCNOxKaWLO3D5RiG0mc=;\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:Cc:\n\tFrom;\n\tb=UMt1dRaKthKWomRlRYul8JytVK2Hl2eDXzDGD+np/6zy8E/smqTkltizsjXOGji9y\n\tbwprtd+dBUrLL1GdWQYSqVwGpFjoxUqXpfFw6TnWqxtL8v/QNKcCHodIJHnhWRK1Yo\n\t0+pzebsPwaG+iqcu7IRIT8pS/zwZD2uCsHO9OnC6vsC588gArERRDr0LSmN5KNtFIV\n\t6F4v4kZfsMlF4uRNreu549SsJJ7/f640GcYRerWkG0WgvvD377IlYr796yn/4XSaOc\n\tW6+q0urTLnVIz9/qDs1L7vC5+8oM879RotQm4xEgNqZlOJsG3+UmECBGWxzmSZIhHf\n\tebmccVi/Ye7rw==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1691499100;\n\tbh=pSSxhla5CU9zLBFJD8ZnASnLfCNOxKaWLO3D5RiG0mc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=CHTX8AgxqPmKGc13eG7eWv+8F/V64qXomVBMAM0UQ9ClFPQq2JzlopToWG0X/bj0F\n\thtJWuDpZ5DS5HB5FfmzF0Bmbk2hE+4fHOScjmdJ0r4YnSH/oJSzA12JXzZ8eXAOOuy\n\ta2RsfVMzx79GnRxuUYfHtgQ7f7/xGHLsXcgUkGZk=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"CHTX8Agx\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org, Sophie Friedrich <dev@flowerpot.me>", "Date": "Tue, 8 Aug 2023 14:52:22 +0200", "Message-Id": "<20230808125228.29043-4-jacopo.mondi@ideasonboard.com>", "X-Mailer": "git-send-email 2.40.1", "In-Reply-To": "<20230808125228.29043-1-jacopo.mondi@ideasonboard.com>", "References": "<20230808125228.29043-1-jacopo.mondi@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC 3/9] libcamera: device_enumerator: Prepare\n\tfor more device types", "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": "Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Modify the existing device_enumerator implementation and documentation\nto prepare to support enumeration and matching of more device types than\nMediaDevice instances.\n\nMove all media device related types and function to use the\n\"mediaDevice\" name in place of a more generic \"device\" and modify the\nderived sysfs and udev based derived classes accordingly.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n .../libcamera/internal/device_enumerator.h | 8 +--\n src/libcamera/device_enumerator.cpp | 70 ++++++++++---------\n src/libcamera/device_enumerator_sysfs.cpp | 4 +-\n src/libcamera/device_enumerator_udev.cpp | 8 +--\n 4 files changed, 47 insertions(+), 43 deletions(-)", "diff": "diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\nindex 2afb9fa0dea8..8df6a3e2ac92 100644\n--- a/include/libcamera/internal/device_enumerator.h\n+++ b/include/libcamera/internal/device_enumerator.h\n@@ -34,12 +34,12 @@ public:\n \tSignal<> devicesAdded;\n \n protected:\n-\tstd::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);\n-\tvoid addDevice(std::unique_ptr<MediaDevice> media);\n-\tvoid removeDevice(const std::string &deviceNode);\n+\tstd::unique_ptr<MediaDevice> createMediaDevice(const std::string &deviceNode);\n+\tvoid addMediaDevice(std::unique_ptr<MediaDevice> media);\n+\tvoid removeMediaDevice(const std::string &deviceNode);\n \n private:\n-\tstd::vector<std::shared_ptr<MediaDevice>> devices_;\n+\tstd::vector<std::shared_ptr<MediaDevice>> mediaDevices_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\nindex 3dda08380e6e..2ab731c68db9 100644\n--- a/src/libcamera/device_enumerator.cpp\n+++ b/src/libcamera/device_enumerator.cpp\n@@ -17,23 +17,26 @@\n \n /**\n * \\file device_enumerator.h\n- * \\brief Enumeration and matching of media devices\n+ * \\brief Enumeration and matching of camera devices\n *\n- * The purpose of device enumeration and matching is to find media devices in\n- * the system and map them to pipeline handlers.\n+ * The purpose of device enumeration and matching is to find devices in the\n+ * system from which a camera can be created and map them to pipeline handlers.\n *\n- * At the core of the enumeration is the DeviceEnumerator class, responsible\n- * for enumerating all media devices in the system. It handles all interactions\n- * with the operating system in a platform-specific way. For each media device\n- * found an instance of MediaDevice is created to store information about the\n- * device gathered from the kernel through the Media Controller API.\n+ * At the core of the enumeration is the DeviceEnumerator class, responsible for\n+ * enumerating all devices in the system used to create cameras. It handles all\n+ * interactions with the operating system in a platform-specific way. For each\n+ * system device found an instance of the opportune class is created to store\n+ * information about the device gathered from the kernel through the supported\n+ * Linux kernel API, which include the Media Controller API, USB-based devices\n+ * and more.\n *\n- * The DeviceEnumerator can enumerate all or specific media devices in the\n- * system. When a new media device is added the enumerator creates a\n- * corresponding MediaDevice instance.\n+ * The DeviceEnumerator can enumerate all or specific devices in the system.\n+ * When a new device is added the enumerator creates a corresponding instance of\n+ * the opportune class. In example, for each enumerated media device a\n+ * MediaDevice class instance is created.\n *\n * The enumerator supports searching among enumerated devices based on criteria\n- * expressed in a DeviceMatch object.\n+ * expressed in a DeviceMatch derived classes instance.\n */\n \n namespace libcamera {\n@@ -42,13 +45,14 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator)\n \n /**\n * \\class DeviceEnumerator\n- * \\brief Enumerate, store and search media devices\n+ * \\brief Enumerate, store and search system devices\n *\n * The DeviceEnumerator class is responsible for all interactions with the\n- * operating system related to media devices. It enumerates all media devices\n- * in the system, and for each device found creates an instance of the\n- * MediaDevice class and stores it internally. The list of media devices can\n- * then be searched using DeviceMatch search patterns.\n+ * operating system related to camera devices. It enumerates the devices in the\n+ * system from which a camera can be created, and for each device found creates\n+ * an instance of the opportune class and stores it internally. The list of\n+ * devices can then be searched using the corresponding DeviceMatch derived\n+ * class search patterns.\n *\n * The enumerator also associates media device entities with device node paths.\n */\n@@ -88,7 +92,7 @@ std::unique_ptr<DeviceEnumerator> DeviceEnumerator::create()\n \n DeviceEnumerator::~DeviceEnumerator()\n {\n-\tfor (const std::shared_ptr<MediaDevice> &media : devices_) {\n+\tfor (const std::shared_ptr<MediaDevice> &media : mediaDevices_) {\n \t\tif (media->busy())\n \t\t\tLOG(DeviceEnumerator, Error)\n \t\t\t\t<< \"Removing media device \" << media->deviceNode()\n@@ -106,15 +110,15 @@ DeviceEnumerator::~DeviceEnumerator()\n \n /**\n * \\fn DeviceEnumerator::enumerate()\n- * \\brief Enumerate all media devices in the system\n+ * \\brief Enumerate all camera devices in the system\n *\n- * This function finds and add all media devices in the system to the\n+ * This function finds and add all camera devices in the system to the\n * enumerator. It shall be implemented by all subclasses of DeviceEnumerator\n * using system-specific methods.\n *\n- * Individual media devices that can't be properly enumerated shall be skipped\n- * with a warning message logged, without returning an error. Only errors that\n- * prevent enumeration altogether shall be fatal.\n+ * Individual devices that can't be properly enumerated shall be skipped with a\n+ * warning message logged, without returning an error. Only errors that prevent\n+ * enumeration altogether shall be fatal.\n *\n * \\context This function is \\threadbound.\n *\n@@ -132,11 +136,11 @@ DeviceEnumerator::~DeviceEnumerator()\n * shall ensure that device nodes are ready to be used (for instance, if\n * applicable, by waiting for device nodes to be created and access permissions\n * to be set by the system). Once done, it shall add the media device to the\n- * system with addDevice().\n+ * system with addMediaDevice().\n *\n * \\return Created media device instance on success, or nullptr otherwise\n */\n-std::unique_ptr<MediaDevice> DeviceEnumerator::createDevice(const std::string &deviceNode)\n+std::unique_ptr<MediaDevice> DeviceEnumerator::createMediaDevice(const std::string &deviceNode)\n {\n \tstd::unique_ptr<MediaDevice> media = std::make_unique<MediaDevice>(deviceNode);\n \n@@ -174,12 +178,12 @@ std::unique_ptr<MediaDevice> DeviceEnumerator::createDevice(const std::string &d\n * This function shall be called after all members of the entities of the\n * media graph have been confirmed to be initialized.\n */\n-void DeviceEnumerator::addDevice(std::unique_ptr<MediaDevice> media)\n+void DeviceEnumerator::addMediaDevice(std::unique_ptr<MediaDevice> media)\n {\n \tLOG(DeviceEnumerator, Debug)\n \t\t<< \"Added device \" << media->deviceNode() << \": \" << media->driver();\n \n-\tdevices_.push_back(std::move(media));\n+\tmediaDevices_.push_back(std::move(media));\n \n \t/* \\todo To batch multiple additions, emit with a small delay here. */\n \tdevicesAdded.emit();\n@@ -190,17 +194,17 @@ void DeviceEnumerator::addDevice(std::unique_ptr<MediaDevice> media)\n * \\param[in] deviceNode Path to the media device to remove\n *\n * Remove the media device identified by \\a deviceNode previously added to the\n- * enumerator with addDevice(). The media device's MediaDevice::disconnected\n- * signal is emitted.\n+ * enumerator with addMediaDevice(). The media device's\n+ * MediaDevice::disconnected signal is emitted.\n */\n-void DeviceEnumerator::removeDevice(const std::string &deviceNode)\n+void DeviceEnumerator::removeMediaDevice(const std::string &deviceNode)\n {\n \tstd::shared_ptr<MediaDevice> media;\n \n-\tfor (auto iter = devices_.begin(); iter != devices_.end(); ++iter) {\n+\tfor (auto iter = mediaDevices_.begin(); iter != mediaDevices_.end(); ++iter) {\n \t\tif ((*iter)->deviceNode() == deviceNode) {\n \t\t\tmedia = std::move(*iter);\n-\t\t\tdevices_.erase(iter);\n+\t\t\tmediaDevices_.erase(iter);\n \t\t\tbreak;\n \t\t}\n \t}\n@@ -231,7 +235,7 @@ void DeviceEnumerator::removeDevice(const std::string &deviceNode)\n */\n std::shared_ptr<MediaDevice> DeviceEnumerator::search(const MediaDeviceMatch &dm)\n {\n-\tfor (std::shared_ptr<MediaDevice> &media : devices_) {\n+\tfor (std::shared_ptr<MediaDevice> &media : mediaDevices_) {\n \t\tif (media->busy())\n \t\t\tcontinue;\n \ndiff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp\nindex 686bb8099485..71730f54c3e8 100644\n--- a/src/libcamera/device_enumerator_sysfs.cpp\n+++ b/src/libcamera/device_enumerator_sysfs.cpp\n@@ -73,7 +73,7 @@ int DeviceEnumeratorSysfs::enumerate()\n \t\t\tcontinue;\n \t\t}\n \n-\t\tstd::unique_ptr<MediaDevice> media = createDevice(devnode);\n+\t\tstd::unique_ptr<MediaDevice> media = createMediaDevice(devnode);\n \t\tif (!media)\n \t\t\tcontinue;\n \n@@ -85,7 +85,7 @@ int DeviceEnumeratorSysfs::enumerate()\n \t\t\tcontinue;\n \t\t}\n \n-\t\taddDevice(std::move(media));\n+\t\taddMediaDevice(std::move(media));\n \t}\n \n \tclosedir(dir);\ndiff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp\nindex 0abc1248887b..3cb0044a9434 100644\n--- a/src/libcamera/device_enumerator_udev.cpp\n+++ b/src/libcamera/device_enumerator_udev.cpp\n@@ -78,7 +78,7 @@ int DeviceEnumeratorUdev::addUdevDevice(struct udev_device *dev)\n \n \tif (!strcmp(subsystem, \"media\")) {\n \t\tstd::unique_ptr<MediaDevice> media =\n-\t\t\tcreateDevice(udev_device_get_devnode(dev));\n+\t\t\tcreateMediaDevice(udev_device_get_devnode(dev));\n \t\tif (!media)\n \t\t\treturn -ENODEV;\n \n@@ -106,7 +106,7 @@ int DeviceEnumeratorUdev::addUdevDevice(struct udev_device *dev)\n \t\t\treturn 0;\n \t\t}\n \n-\t\taddDevice(std::move(media));\n+\t\taddMediaDevice(std::move(media));\n \t\treturn 0;\n \t}\n \n@@ -322,7 +322,7 @@ int DeviceEnumeratorUdev::addV4L2Device(dev_t devnum)\n \t\tLOG(DeviceEnumerator, Debug)\n \t\t\t<< \"All dependencies for media device \"\n \t\t\t<< deps->media_->deviceNode() << \" found\";\n-\t\taddDevice(std::move(deps->media_));\n+\t\taddMediaDevice(std::move(deps->media_));\n \t\tpending_.remove(*deps);\n \t}\n \n@@ -343,7 +343,7 @@ void DeviceEnumeratorUdev::udevNotify()\n \t} else if (action == \"remove\") {\n \t\tconst char *subsystem = udev_device_get_subsystem(dev);\n \t\tif (subsystem && !strcmp(subsystem, \"media\"))\n-\t\t\tremoveDevice(std::string(deviceNode));\n+\t\t\tremoveMediaDevice(std::string(deviceNode));\n \t}\n \n \tudev_device_unref(dev);\n", "prefixes": [ "libcamera-devel", "RFC", "3/9" ] }