Patch Detail
Show a patch.
GET /api/1.1/patches/81/?format=api
{ "id": 81, "url": "https://patchwork.libcamera.org/api/1.1/patches/81/?format=api", "web_url": "https://patchwork.libcamera.org/patch/81/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20181222230041.29999-6-niklas.soderlund@ragnatech.se>", "date": "2018-12-22T23:00:34", "name": "[libcamera-devel,05/12] libcamera: deviceenumerator: add DeviceEnumerator class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "cfc26a59dd67dff8309149b82c159496aa27da18", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/81/mbox/", "series": [ { "id": 38, "url": "https://patchwork.libcamera.org/api/1.1/series/38/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=38", "date": "2018-12-22T23:00:29", "name": "Add basic camera enumeration", "version": 1, "mbox": "https://patchwork.libcamera.org/series/38/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/81/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/81/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B05960B2D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 Dec 2018 00:02:24 +0100 (CET)", "from wyvern.dyn.berto.se (unknown [217.31.177.236])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 946979a7-063d-11e9-9adf-005056917a89;\n\tSun, 23 Dec 2018 00:01:57 +0100 (CET)" ], "X-Halon-ID": "946979a7-063d-11e9-9adf-005056917a89", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 23 Dec 2018 00:00:34 +0100", "Message-Id": "<20181222230041.29999-6-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20181222230041.29999-1-niklas.soderlund@ragnatech.se>", "References": "<20181222230041.29999-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 05/12] libcamera: deviceenumerator: add\n\tDeviceEnumerator class", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "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>", "X-List-Received-Date": "Sat, 22 Dec 2018 23:02:24 -0000" }, "content": "Provide a DeviceEnumerator base class which enumerates all media devices\nin the system and information about them, resolving V4L2 data structures\nto paths and a method to search in all the enumerated information.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/deviceenumerator.cpp | 144 +++++++++++++++++++++++\n src/libcamera/include/deviceenumerator.h | 22 ++++\n 2 files changed, 166 insertions(+)", "diff": "diff --git a/src/libcamera/deviceenumerator.cpp b/src/libcamera/deviceenumerator.cpp\nindex 17b6874d229c791c..b2f59017e94d14aa 100644\n--- a/src/libcamera/deviceenumerator.cpp\n+++ b/src/libcamera/deviceenumerator.cpp\n@@ -5,6 +5,10 @@\n * deviceenumerator.cpp - Enumeration and matching\n */\n \n+#include <fcntl.h>\n+#include <sys/ioctl.h>\n+#include <unistd.h>\n+\n #include \"deviceenumerator.h\"\n #include \"log.h\"\n \n@@ -129,4 +133,144 @@ bool DeviceMatch::matchEntities(const std::vector<std::string> &entities) const\n \treturn true;\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Enumerator Base\n+ */\n+\n+DeviceEnumerator::~DeviceEnumerator()\n+{\n+\tfor (DeviceInfo *dev : devices_) {\n+\t\tif (dev->busy())\n+\t\t\tLOG(Error) << \"Removing device info while still in use\";\n+\n+\t\tdelete dev;\n+\t}\n+}\n+\n+int DeviceEnumerator::addDevice(const std::string &devnode)\n+{\n+\tint fd, ret;\n+\n+\tstruct media_device_info info = {};\n+\tstd::map<std::string, std::string> entities;\n+\n+\tfd = open(devnode.c_str(), O_RDWR);\n+\tif (fd < 0)\n+\t\treturn fd;\n+\n+\tret = readInfo(fd, info);\n+\tif (ret)\n+\t\tgoto out;\n+\n+\tret = readTopology(fd, entities);\n+\tif (ret)\n+\t\tgoto out;\n+\n+\tdevices_.push_back(new DeviceInfo(devnode, info, entities));\n+out:\n+\tclose(fd);\n+\n+\treturn ret;\n+}\n+\n+int DeviceEnumerator::readInfo(int fd, struct media_device_info &info)\n+{\n+\tint ret;\n+\n+\tret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &info);\n+\tif (ret < 0)\n+\t\treturn -errno;\n+\n+\treturn 0;\n+}\n+\n+int DeviceEnumerator::readTopology(int fd, std::map<std::string, std::string> &entities)\n+{\n+\tstruct media_v2_topology topology;\n+\tstruct media_v2_entity *ents = NULL;\n+\tstruct media_v2_interface *ifaces = NULL;\n+\tstruct media_v2_link *links = NULL;\n+\tint ret;\n+\n+\twhile (true) {\n+\t\ttopology = {};\n+\n+\t\tret = ioctl(fd, MEDIA_IOC_G_TOPOLOGY, &topology);\n+\t\tif (ret < 0)\n+\t\t\treturn -errno;\n+\n+\t\t__u64 version = topology.topology_version;\n+\n+\t\tents = new media_v2_entity[topology.num_entities]();\n+\t\tifaces = new media_v2_interface[topology.num_interfaces]();\n+\t\tlinks = new media_v2_link[topology.num_links]();\n+\t\ttopology.ptr_entities = (__u64)ents;\n+\t\ttopology.ptr_interfaces = (__u64)ifaces;\n+\t\ttopology.ptr_links = (__u64)links;\n+\n+\t\tret = ioctl(fd, MEDIA_IOC_G_TOPOLOGY, &topology);\n+\t\tif (ret < 0) {\n+\t\t\tret = -errno;\n+\t\t\tgoto done;\n+\t\t}\n+\n+\t\tif (version == topology.topology_version)\n+\t\t\tbreak;\n+\n+\t\tdelete[] links;\n+\t\tdelete[] ifaces;\n+\t\tdelete[] ents;\n+\t}\n+\n+\tfor (unsigned int link_id = 0; link_id < topology.num_links; link_id++) {\n+\t\tunsigned int iface_id, ent_id;\n+\t\tstd::string devnode;\n+\n+\t\tif ((links[link_id].flags & MEDIA_LNK_FL_LINK_TYPE) != MEDIA_LNK_FL_INTERFACE_LINK)\n+\t\t\tcontinue;\n+\n+\t\tfor (iface_id = 0; iface_id < topology.num_interfaces; iface_id++)\n+\t\t\tif (links[link_id].source_id == ifaces[iface_id].id)\n+\t\t\t\tbreak;\n+\n+\t\tfor (ent_id = 0; ent_id < topology.num_entities; ent_id++)\n+\t\t\tif (links[link_id].sink_id == ents[ent_id].id)\n+\t\t\t\tbreak;\n+\n+\t\tif (ent_id >= topology.num_entities || iface_id >= topology.num_interfaces)\n+\t\t\tcontinue;\n+\n+\t\tret = lookupDevnode(devnode,\n+\t\t\t\t ifaces[iface_id].devnode.major,\n+\t\t\t\t ifaces[iface_id].devnode.minor);\n+\t\tif (ret)\n+\t\t\tbreak;\n+\n+\t\tentities[ents[ent_id].name] = devnode;\n+\t}\n+done:\n+\tdelete[] links;\n+\tdelete[] ifaces;\n+\tdelete[] ents;\n+\n+\treturn ret;\n+}\n+\n+DeviceInfo *DeviceEnumerator::search(DeviceMatch &dm) const\n+{\n+\tDeviceInfo *info = NULL;\n+\n+\tfor (DeviceInfo *dev : devices_) {\n+\t\tif (dev->busy())\n+\t\t\tcontinue;\n+\n+\t\tif (dm.match(dev)) {\n+\t\t\tinfo = dev;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\treturn info;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/deviceenumerator.h b/src/libcamera/include/deviceenumerator.h\nindex fb412b8840cb2ffe..cbe17774edb7fcc5 100644\n--- a/src/libcamera/include/deviceenumerator.h\n+++ b/src/libcamera/include/deviceenumerator.h\n@@ -56,6 +56,28 @@ private:\n \tbool matchEntities(const std::vector<std::string> &entities) const;\n };\n \n+class DeviceEnumerator\n+{\n+public:\n+\tvirtual ~DeviceEnumerator();\n+\n+\tvirtual int init() = 0;\n+\tvirtual int enumerate() = 0;\n+\n+\tDeviceInfo *search(DeviceMatch &dm) const;\n+\n+protected:\n+\tint addDevice(const std::string &devnode);\n+\n+private:\n+\tstd::vector<DeviceInfo *> devices_;\n+\n+\tint readInfo(int fd, struct media_device_info &info);\n+\tint readTopology(int fd, std::map<std::string, std::string> &entities);\n+\n+\tvirtual int lookupDevnode(std::string &devnode, int major, int minor) = 0;\n+};\n+\n } /* namespace libcamera */\n \n #endif\t/* __LIBCAMERA_DEVICEENUMERATE_H__ */\n", "prefixes": [ "libcamera-devel", "05/12" ] }