Patch Detail
Show a patch.
GET /api/patches/184/?format=api
{ "id": 184, "url": "https://patchwork.libcamera.org/api/patches/184/?format=api", "web_url": "https://patchwork.libcamera.org/patch/184/", "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": "<20190108170407.4770-4-jacopo@jmondi.org>", "date": "2019-01-08T17:04:06", "name": "[libcamera-devel,v2,3/4] libcamera: Add link handling functions", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4f31116e67b3d524730ec62dc2d39485e3a66cae", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/184/mbox/", "series": [ { "id": 61, "url": "https://patchwork.libcamera.org/api/series/61/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=61", "date": "2019-01-08T17:04:03", "name": "libcamera: media device: Add link handling", "version": 2, "mbox": "https://patchwork.libcamera.org/series/61/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/184/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/184/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6E2A460B31\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 8 Jan 2019 18:04:10 +0100 (CET)", "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id 0B52E20000E;\n\tTue, 8 Jan 2019 17:04:09 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 8 Jan 2019 18:04:06 +0100", "Message-Id": "<20190108170407.4770-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20190108170407.4770-1-jacopo@jmondi.org>", "References": "<20190108170407.4770-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 3/4] libcamera: Add link handling\n\tfunctions", "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": "Tue, 08 Jan 2019 17:04:11 -0000" }, "content": "Add a function to the MediaLink class to set the state of a link to\nenabled or disabled. The function makes use of an internal MediaDevice\nmethod, which is defined private and only accessible by the MediaLink\nsetEnable() function itself.\n\nAlso add to MediaDevice a function to reset all links registered in the\nmedia graph.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nv1->v2:\n- Add resetLinks() function\n- s/enable()/setEnable()\n- s/setLink()/setupLink()\n- Pass MediaLink and not two MediaPads to MediaDevice::setupLink\n\n src/libcamera/include/media_device.h | 4 ++\n src/libcamera/include/media_object.h | 1 +\n src/libcamera/media_device.cpp | 75 ++++++++++++++++++++++++++++\n src/libcamera/media_object.cpp | 29 +++++++++++\n 4 files changed, 109 insertions(+)\n\n--\n2.20.1", "diff": "diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex 397d349..0f423aa 100644\n--- a/src/libcamera/include/media_device.h\n+++ b/src/libcamera/include/media_device.h\n@@ -45,6 +45,7 @@ public:\n \tMediaLink *link(const MediaEntity *source, unsigned int sourceIdx,\n \t\t\tconst MediaEntity *sink, unsigned int sinkIdx);\n \tMediaLink *link(const MediaPad *source, const MediaPad *sink);\n+\tint resetLinks();\n\n private:\n \tstd::string driver_;\n@@ -65,6 +66,9 @@ private:\n \tbool populateEntities(const struct media_v2_topology &topology);\n \tbool populatePads(const struct media_v2_topology &topology);\n \tbool populateLinks(const struct media_v2_topology &topology);\n+\n+\tfriend int MediaLink::setEnable(bool enable);\n+\tint setupLink(const MediaLink *link, unsigned int flags);\n };\n\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/media_object.h b/src/libcamera/include/media_object.h\nindex d92aab3..bb46fac 100644\n--- a/src/libcamera/include/media_object.h\n+++ b/src/libcamera/include/media_object.h\n@@ -41,6 +41,7 @@ public:\n \tMediaPad *source() const { return source_; }\n \tMediaPad *sink() const { return sink_; }\n \tunsigned int flags() const { return flags_; }\n+\tint setEnable(bool enable);\n\n private:\n \tfriend class MediaDevice;\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 7ce5c22..9900c3f 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -385,6 +385,35 @@ MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink)\n \treturn nullptr;\n }\n\n+/**\n+ * \\brief Reset all links in the media device\n+ *\n+ * Reset the media device links, clearing the MEDIA_LNK_FL_ENABLED flag\n+ * on links which are not flagged as IMMUTABLE.\n+ *\n+ * \\return 0 for success, or a negative error code otherwise\n+ */\n+int MediaDevice::resetLinks()\n+{\n+\tfor (MediaEntity *entity : entities_) {\n+\t\tfor (MediaPad *pad : entity->pads()) {\n+\t\t\tif (pad->flags() & MEDIA_PAD_FL_SINK)\n+\t\t\t\tcontinue;\n+\n+\t\t\tfor (MediaLink *link : pad->links()) {\n+\t\t\t\tif (link->flags() & MEDIA_LNK_FL_IMMUTABLE)\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tint ret = link->setEnable(false);\n+\t\t\t\tif (ret)\n+\t\t\t\t\treturn ret;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n /**\n * \\var MediaDevice::objects_\n * \\brief Global map of media objects (entities, pads, links) keyed by their\n@@ -601,4 +630,50 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology)\n \treturn true;\n }\n\n+/**\n+ * \\brief Apply \\a flags to a link between two pads\n+ * \\param link The link to apply flags on\n+ * \\param flags The flags to apply to the link\n+ *\n+ * This function applies the link \\a flags (as defined by the MEDIA_LNK_FL_*\n+ * macros from the Media Controller API) to the given \\a link. It implements\n+ * low-level link setup as it performs no checks on the validity of the \\a\n+ * flags, and assumes that the supplied \\a flags are valid for the link (e.g.\n+ * immutable links cannot be disabled).\"\n+*\n+ * \\sa MediaLink::setEnable(bool enable)\n+ *\n+ * \\return 0 for success, or a negative error code otherwise\n+ */\n+int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)\n+{\n+\tstruct media_link_desc linkDesc = { };\n+\tMediaPad *source = link->source();\n+\tMediaPad *sink = link->sink();\n+\n+\tlinkDesc.source.entity = source->entity()->id();\n+\tlinkDesc.source.index = source->index();\n+\tlinkDesc.source.flags = MEDIA_PAD_FL_SOURCE;\n+\n+\tlinkDesc.sink.entity = sink->entity()->id();\n+\tlinkDesc.sink.index = sink->index();\n+\tlinkDesc.sink.flags = MEDIA_PAD_FL_SINK;\n+\n+\tlinkDesc.flags = flags;\n+\n+\tint ret = ioctl(fd_, MEDIA_IOC_SETUP_LINK, &linkDesc);\n+\tif (ret) {\n+\t\tret = -errno;\n+\t\tLOG(Error) << \"Failed to setup link: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tLOG(Debug) << source->entity()->name() << \"[\"\n+\t\t << source->index() << \"] -> \"\n+\t\t << sink->entity()->name() << \"[\"\n+\t\t << sink->index() << \"]: \" << flags;\n+\n+\treturn 0;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp\nindex 612550d..c6cb02b 100644\n--- a/src/libcamera/media_object.cpp\n+++ b/src/libcamera/media_object.cpp\n@@ -15,6 +15,7 @@\n #include <linux/media.h>\n\n #include \"log.h\"\n+#include \"media_device.h\"\n #include \"media_object.h\"\n\n /**\n@@ -89,6 +90,34 @@ namespace libcamera {\n * Each link is referenced in the link array of both of the pads it connect.\n */\n\n+/**\n+ * \\brief Enable or disable a lik\n+ * \\param enable True to enable the link, false to disable it\n+ *\n+ * Set the status of a link, according to the value of \\a enable.\n+ * Links between two pads can be set to the enabled or disabled state freely,\n+ * unless they're immutable links, whose status cannot be changed.\n+ * Enabling an immutable link is not considered an error, while trying to\n+ * disable it is.\n+ *\n+ * Enabling a link establishes a data connection between two pads, while\n+ * disabling it interrupts such a connections.\n+ *\n+ * \\return 0 on success, or a negative error code otherwise\n+ */\n+int MediaLink::setEnable(bool enable)\n+{\n+\tunsigned int flags = enable ? MEDIA_LNK_FL_ENABLED : 0;\n+\n+\tint ret = dev_->setupLink(this, flags);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tflags_ = flags;\n+\n+\treturn 0;\n+}\n+\n /**\n * \\brief Construct a MediaLink\n * \\param link The media link kernel data\n", "prefixes": [ "libcamera-devel", "v2", "3/4" ] }