{"id":193,"url":"https://patchwork.libcamera.org/api/patches/193/?format=json","web_url":"https://patchwork.libcamera.org/patch/193/","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":"<20190108204733.10823-4-jacopo@jmondi.org>","date":"2019-01-08T20:47:33","name":"[libcamera-devel,v3,3/3] libcamera: Add link handling functions","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"8bbdf1f99212909e43ab7865c4f3f7494528b22a","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/193/mbox/","series":[{"id":63,"url":"https://patchwork.libcamera.org/api/series/63/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=63","date":"2019-01-08T20:47:30","name":"libcamera: media device: Add link handling","version":3,"mbox":"https://patchwork.libcamera.org/series/63/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/193/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/193/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E7A360B30\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 21:47:34 +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 relay2-d.mail.gandi.net (Postfix) with ESMTPSA id C08C140008;\n\tTue,  8 Jan 2019 20:47:33 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  8 Jan 2019 21:47:33 +0100","Message-Id":"<20190108204733.10823-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190108204733.10823-1-jacopo@jmondi.org>","References":"<20190108204733.10823-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 3/3] 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 20:47:34 -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---\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(+)","diff":"diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex 22c32b7..286740d 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 disableLinks();\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 b2c3d8e..fdc9bf8 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 ca12caa..1130ba4 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -386,6 +386,35 @@ MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink)\n \treturn nullptr;\n }\n \n+/**\n+ * \\brief Disable all links in the media device\n+ *\n+ * Disable all the media device links, clearing the MEDIA_LNK_FL_ENABLED flag\n+ * on links which are not flagged as IMMUTABLE.\n+ *\n+ * \\return 0 on success, or a negative error code otherwise\n+ */\n+int MediaDevice::disableLinks()\n+{\n+\tfor (MediaEntity *entity : entities_) {\n+\t\tfor (MediaPad *pad : entity->pads()) {\n+\t\t\tif (!(pad->flags() & MEDIA_PAD_FL_SOURCE))\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@@ -602,4 +631,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 to\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 on 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 4ff9620..cd2b912 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@@ -95,6 +96,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 link\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 that connection.\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","v3","3/3"]}