Patch Detail
Show a patch.
GET /api/patches/84/?format=api
{ "id": 84, "url": "https://patchwork.libcamera.org/api/patches/84/?format=api", "web_url": "https://patchwork.libcamera.org/patch/84/", "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": "<20181222230041.29999-9-niklas.soderlund@ragnatech.se>", "date": "2018-12-22T23:00:37", "name": "[libcamera-devel,08/12] libcamera: deviceenumerator: add documentation", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "71ea7887451d8146d5da791cd4800a8cf42b9024", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/84/mbox/", "series": [ { "id": 38, "url": "https://patchwork.libcamera.org/api/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/84/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/84/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 8817E60B34\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 Dec 2018 00:02:30 +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 97d4075f-063d-11e9-9adf-005056917a89;\n\tSun, 23 Dec 2018 00:02:03 +0100 (CET)" ], "X-Halon-ID": "97d4075f-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:37 +0100", "Message-Id": "<20181222230041.29999-9-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 08/12] libcamera: deviceenumerator: add\n\tdocumentation", "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:30 -0000" }, "content": "Document the intended use-case of the different elements of the device\nenumerator.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/deviceenumerator.cpp | 249 +++++++++++++++++++++++++++--\n 1 file changed, 239 insertions(+), 10 deletions(-)", "diff": "diff --git a/src/libcamera/deviceenumerator.cpp b/src/libcamera/deviceenumerator.cpp\nindex 6d675fc78af8e586..fc43ecc7e2d07e05 100644\n--- a/src/libcamera/deviceenumerator.cpp\n+++ b/src/libcamera/deviceenumerator.cpp\n@@ -13,12 +13,55 @@\n #include \"deviceenumerator.h\"\n #include \"log.h\"\n \n+/**\n+ * \\file deviceenumerator.h\n+ * \\brief Enumerating and matching of media devices\n+ *\n+ * The purpose of device enumeration and matching is to find media\n+ * devices in the system and map one or more media devices to a pipeline\n+ * handler. During enumeration information about each media device is\n+ * gathered, transformed and stored.\n+ *\n+ * The core of the enumeration is DeviceEnumerator which is responsible\n+ * for all interactions with the operating system and the entry point\n+ * for other parts of libcamera.\n+ *\n+ * The DeviceEnumerator can enumerate all or specific media devices in\n+ * the system. When a new media device is added the enumerator gathers\n+ * information about it and stores it in a DeviceInfo object.\n+ *\n+ * The last functionality provided is the ability to search among the\n+ * enumerate media devices for one matching information known to the\n+ * searcher. This is done by populating and passing a DeviceMatch object\n+ * to the DeviceEnumerator.\n+ *\n+ * \\todo Add sysfs based device enumerator\n+ * \\todo Add support for hot-plug and hot-unplug.\n+ */\n+\n namespace libcamera {\n \n-/* -----------------------------------------------------------------------------\n- * DeviceInfo\n+/**\n+ * \\class DeviceInfo\n+ * \\brief Container of information for enumerated device\n+ *\n+ * The DeviceInfo class holds information about a media device. It provides\n+ * methods to retrieve the information stored and to lookup entity names\n+ * to device node paths. Furthermore it provides a scheme where a device\n+ * can be acquired and released to indicate if the device is in use.\n+ *\n+ * \\todo Look into the possibility to replace this with a more complete MediaDevice model.\n */\n \n+/**\n+ * \\brief Construct a container of device information\n+ *\n+ * \\param[in] devnode The path to the device node of the media device\n+ * \\param[in] info Information retrieved from MEDIA_IOC_DEVICE_INFO IOCTL\n+ * \\param[in] entities A map of media graph 'Entity name' -> 'devnode path'\n+ *\n+ * The caller is responsible to provide all information for the device.\n+ */\n DeviceInfo::DeviceInfo(const std::string &devnode, const struct media_device_info &info,\n \t\t const std::map<std::string, std::string> &entities)\n \t: acquired_(false), devnode_(devnode), info_(info), entities_(entities)\n@@ -27,6 +70,15 @@ DeviceInfo::DeviceInfo(const std::string &devnode, const struct media_device_inf\n \t\tLOG(Info) << \"Device: \" << devnode_ << \" Entity: '\" << entity.first << \"' -> \" << entity.second;\n }\n \n+/**\n+ * \\brief Claim a device for exclusive use\n+ *\n+ * Once a device is successfully acquired the caller is responsible to\n+ * release it once it is done wit it.\n+ *\n+ * \\retval 0 Device claimed\n+ * \\retval -EBUSY Device already claimed by someone else\n+ */\n int DeviceInfo::acquire()\n {\n \tif (acquired_)\n@@ -37,26 +89,53 @@ int DeviceInfo::acquire()\n \treturn 0;\n }\n \n+/**\n+ * \\brief Release a device from exclusive use\n+ */\n void DeviceInfo::release()\n {\n \tacquired_ = false;\n }\n \n+/**\n+ * \\brief Check if a device is in use\n+ *\n+ * \\retval true Device is in use\n+ * \\retval false Device is free\n+ */\n bool DeviceInfo::busy() const\n {\n \treturn acquired_;\n }\n \n+/**\n+ * \\brief Retrieve the devnode to the media device\n+ *\n+ * \\return Path to the media device (example /dev/media0)\n+ */\n const std::string &DeviceInfo::devnode() const\n {\n \treturn devnode_;\n }\n \n+/**\n+ * \\brief Retrieve the media device v4l2 information\n+ *\n+ * \\return v4l2 specific information structure\n+ */\n const struct media_device_info &DeviceInfo::info() const\n {\n \treturn info_;\n }\n \n+/**\n+ * \\brief List all entities of the device\n+ *\n+ * List all media entities names from the media graph which are known\n+ * and to which this instance can lookup the device node path.\n+ *\n+ * \\return List of strings\n+ */\n std::vector<std::string> DeviceInfo::entities() const\n {\n \tstd::vector<std::string> entities;\n@@ -67,6 +146,19 @@ std::vector<std::string> DeviceInfo::entities() const\n \treturn entities;\n }\n \n+/**\n+ * \\brief Lookup a media entity name and retrieve its device node path\n+ *\n+ * \\param[in] name Entity name to lookup\n+ * \\param[out] devnode Path to \\a name devnode if lookup is successful\n+ *\n+ * The caller is responsible to check the return code of the function\n+ * to determine if the entity name could be looked up.\n+ *\n+ * \\retval true Successful - \\a devnode contains valid data\n+ * \\retval false Fail - \\a devnode contains invalid data\n+ *\n+ */\n bool DeviceInfo::lookup(const std::string &name, std::string &devnode) const\n {\n \tauto it = entities_.find(name);\n@@ -80,20 +172,49 @@ bool DeviceInfo::lookup(const std::string &name, std::string &devnode) const\n \treturn true;\n }\n \n-/* -----------------------------------------------------------------------------\n- * DeviceMatch\n+/**\n+ * \\class DeviceMatch\n+ * \\brief Description of a media device search pattern\n+ *\n+ * The DeviceMatch class describes a media device using properties from\n+ * the v4l2 struct media_device_info, entity names in the media graph or\n+ * other properties which can be used to identify a media device.\n+ *\n+ * The description of a media device can then be passed to an enumerator\n+ * to try and find a matching media device.\n */\n \n+/**\n+ * \\brief Construct a media device search pattern\n+ *\n+ * \\param[in] driver The Linux device driver name who created the media device\n+ */\n DeviceMatch::DeviceMatch(const std::string &driver)\n \t: driver_(driver)\n {\n }\n \n+/**\n+ * \\brief Add a media entity name to the search pattern\n+ *\n+ * \\param[in] entity The name of the entity in the media graph\n+ */\n void DeviceMatch::add(const std::string &entity)\n {\n \tentities_.push_back(std::string(entity));\n }\n \n+/**\n+ * \\brief Compare a search pattern with a media device\n+ *\n+ * \\param[in] info Information about a enumerated media device\n+ *\n+ * Matching is performed on the Linux device driver name and entity names\n+ * from the media graph.\n+ *\n+ * \\retval true The device described in \\a info matches search pattern\n+ * \\retval false The device described in \\a info do not match search pattern\n+ */\n bool DeviceMatch::match(const DeviceInfo *info) const\n {\n \tstd::vector<std::string> entities;\n@@ -107,13 +228,32 @@ bool DeviceMatch::match(const DeviceInfo *info) const\n \treturn true;\n }\n \n+/**\n+ * \\brief Compare a v4l2 struct media_device_info to search pattern\n+ *\n+ * \\param[in] info Information about a enumerated media device\n+ *\n+ * Not all parameters of struct media_device_info is compared.\n+ *\n+ * \\todo Allow for empty driver_ search pattern as a no-op\n+ * \\todo Add more optional matching pairs from struct media_device_info\n+ *\n+ * \\retval true The device described in \\a info matches search pattern\n+ * \\retval false The device described in \\a info do not match search pattern\n+ */\n bool DeviceMatch::matchInfo(const struct media_device_info &info) const\n {\n-\t/* TODO: Add more optinal matching pairs from struct media_device_info */\n-\t/* TODO: Allow for empty driver in DeviceMatch */\n \treturn driver_ == info.driver;\n }\n \n+/**\n+ * \\brief Compare media entities of media device with search pattern\n+ *\n+ * \\param[in] info Information about a enumerated media device\n+ *\n+ * \\retval true The device described in \\a info matches search pattern\n+ * \\retval false The device described in \\a info do not match search pattern\n+ */\n bool DeviceMatch::matchEntities(const std::vector<std::string> &entities) const\n {\n \tfor (const std::string &name : entities_) {\n@@ -134,10 +274,30 @@ bool DeviceMatch::matchEntities(const std::vector<std::string> &entities) const\n \treturn true;\n }\n \n-/* -----------------------------------------------------------------------------\n- * Enumerator Base\n+/**\n+ * \\class DeviceEnumerator\n+ * \\brief Enumerate, interrogate, store and search media device information\n+ *\n+ * The DeviceEnumerator class is responsible for all interactions with\n+ * the operation system when searching and interrogating media devices.\n+ *\n+ * It is possible to automatically search and add all media devices in\n+ * the system or specify which media devices should be interrogated\n+ * in order for a specialized application to open as few resources\n+ * as possible to get hold of a specific camera.\n+ *\n+ * Once one or many media devices have been enumerated it is possible\n+ * to search among them to try and find a matching device using a\n+ * DeviceMatch object.\n+ *\n */\n \n+/**\n+ * \\brief Create a new device enumerator matching the systems capabilities\n+ *\n+ * Create a enumerator based on resource available to the system. Not all\n+ * different enumerator types are guaranteed to support all features.\n+ */\n DeviceEnumerator *DeviceEnumerator::create()\n {\n \tDeviceEnumerator *enumerator;\n@@ -165,6 +325,15 @@ DeviceEnumerator::~DeviceEnumerator()\n \t}\n }\n \n+/**\n+ * \\brief Add a media device to the enumerator\n+ *\n+ * \\param[in] devnode path to the media device to add\n+ *\n+ * Opens the media device and quires its topology and other information.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceEnumerator::addDevice(const std::string &devnode)\n {\n \tint fd, ret;\n@@ -191,6 +360,16 @@ out:\n \treturn ret;\n }\n \n+/**\n+ * \\brief Fetch the MEDIA_IOC_DEVICE_INFO from media device\n+ *\n+ * \\param[in] fd File pointer to media device\n+ * \\param[out] info Information retrieved from MEDIA_IOC_DEVICE_INFO IOCTL\n+ *\n+ * Opens the media device and quires its information.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceEnumerator::readInfo(int fd, struct media_device_info &info)\n {\n \tint ret;\n@@ -202,6 +381,18 @@ int DeviceEnumerator::readInfo(int fd, struct media_device_info &info)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Fetch the topology from media device\n+ *\n+ * \\param[in] fd File pointer to media device\n+ * \\param[out] entities Map of entity names to device node paths\n+ *\n+ * The media graph is retrieved using MEDIA_IOC_G_TOPOLOGY and the\n+ * result is transformed to a map where the entity name is the key\n+ * and the filesystem path for that entity device node is the value.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceEnumerator::readTopology(int fd, std::map<std::string, std::string> &entities)\n {\n \tstruct media_v2_topology topology;\n@@ -274,6 +465,18 @@ done:\n \treturn ret;\n }\n \n+/**\n+ * \\brief Search available media devices for a pattern match\n+ *\n+ * \\param[in] dm search pattern\n+ *\n+ * Search the enumerated media devices who are not already in use\n+ * for a match described in \\a dm. If a match is found and the caller\n+ * intends to use it the caller is responsible to mark the DeviceInfo\n+ * object as in use and to release it when it's done with it.\n+ *\n+ * \\return pointer to the matching DeviceInfo, NULL if no match is found\n+ */\n DeviceInfo *DeviceEnumerator::search(DeviceMatch &dm) const\n {\n \tDeviceInfo *info = NULL;\n@@ -291,8 +494,11 @@ DeviceInfo *DeviceEnumerator::search(DeviceMatch &dm) const\n \treturn info;\n }\n \n-/* -----------------------------------------------------------------------------\n- * Enumerator Udev\n+/**\n+ * \\class DeviceEnumeratorUdev\n+ * \\brief Udev implementation of device enumeration\n+ *\n+ * Implementation of system enumeration functions using libudev.\n */\n \n DeviceEnumeratorUdev::DeviceEnumeratorUdev()\n@@ -306,6 +512,13 @@ DeviceEnumeratorUdev::~DeviceEnumeratorUdev()\n \t\tudev_unref(udev_);\n }\n \n+/**\n+ * \\brief Initialize the enumerator\n+ *\n+ * \\retval 0 Initialized\n+ * \\retval -EBUSY Busy (already initialized)\n+ * \\retval -ENODEV Failed to talk to udev\n+ */\n int DeviceEnumeratorUdev::init()\n {\n \tif (udev_)\n@@ -318,6 +531,14 @@ int DeviceEnumeratorUdev::init()\n \treturn 0;\n }\n \n+/**\n+ * \\brief Enumerate all media devices using udev\n+ *\n+ * Find, enumerate and add all media devices in the system to the\n+ * enumerator.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ */\n int DeviceEnumeratorUdev::enumerate()\n {\n \tstruct udev_enumerate *udev_enum = NULL;\n@@ -367,6 +588,14 @@ done:\n \treturn ret >= 0 ? 0 : ret;\n }\n \n+/**\n+ * \\brief Lookup device node from device number using udev\n+ *\n+ * Translate a device number (major, minor) to a device node path.\n+ *\n+ * \\return 0 on success none zero otherwise\n+ *\n+ */\n int DeviceEnumeratorUdev::lookupDevnode(std::string &devnode, int major, int minor)\n {\n \tstruct udev_device *device;\n", "prefixes": [ "libcamera-devel", "08/12" ] }