{"id":183,"url":"https://patchwork.libcamera.org/api/1.1/patches/183/?format=json","web_url":"https://patchwork.libcamera.org/patch/183/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20190108170407.4770-3-jacopo@jmondi.org>","date":"2019-01-08T17:04:05","name":"[libcamera-devel,v2,2/4] libcamera: media_device: Add functions to get a MediaLink","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"1363059fcfc2bb3ddcd3a91a05465bdeb61b4f88","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/183/mbox/","series":[{"id":61,"url":"https://patchwork.libcamera.org/api/1.1/series/61/?format=json","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/183/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/183/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 D75A060B2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 18:04:09 +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 7B15A200013;\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:05 +0100","Message-Id":"<20190108170407.4770-3-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 2/4] libcamera: media_device: Add\n\tfunctions to get a MediaLink","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:10 -0000"},"content":"Add three overloaded functions 'link()' to retrieve a link between two\npads. Each overloaded implementation exposes a different method to\nidentify the source and sink pads.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nv1->v2:\n- Drop error handling: let the ioctl fail and report the error\n- Drop the const qualifier to link() methods\n- Incorporate comments changes\n\n src/libcamera/include/media_device.h |  6 +++\n src/libcamera/media_device.cpp       | 79 ++++++++++++++++++++++++++++\n 2 files changed, 85 insertions(+)\n\n--\n2.20.1","diff":"diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex 9f45fc7..397d349 100644\n--- a/src/libcamera/include/media_device.h\n+++ b/src/libcamera/include/media_device.h\n@@ -40,6 +40,12 @@ public:\n \tconst std::vector<MediaEntity *> &entities() const { return entities_; }\n \tMediaEntity *getEntityByName(const std::string &name) const;\n\n+\tMediaLink *link(const std::string sourceName, unsigned int sourceIdx,\n+\t\t\tconst std::string sinkName, unsigned int sinkIdx);\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+\n private:\n \tstd::string driver_;\n \tstd::string devnode_;\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex b0d10ed..7ce5c22 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -306,6 +306,85 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const\n \treturn nullptr;\n }\n\n+/**\n+ * \\brief Retrieve the MediaLink connecting two pads, identified by entity\n+ * names and pad indexes\n+ * \\param sourceName The source entity name\n+ * \\param sourceIdx The index of the source pad\n+ * \\param sinkName The sink entity name\n+ * \\param sinkIdx The index of the sink pad\n+ *\n+ * Find the link that connects the pads at index \\a sourceIdx of the source\n+ * entity with name \\a sourceName, to the pad at index \\a sinkIdx of the\n+ * sink entity with name \\a sinkName, if any.\n+ *\n+ * \\sa MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx, const MediaEntity *sink, unsigned int sinkIdx) const\n+ * \\sa MediaDevice::link(const MediaPad *source, const MediaPad *sink) const\n+ *\n+ * \\return The link that connects the two entities, or nullptr if not such a\n+ * link exists\n+ */\n+MediaLink *MediaDevice::link(const std::string sourceName, unsigned int sourceIdx,\n+\t\t\t     const std::string sinkName, unsigned int sinkIdx)\n+{\n+\tconst MediaEntity *source = getEntityByName(sourceName);\n+\tconst MediaEntity *sink = getEntityByName(sinkName);\n+\tif (!source || !sink)\n+\t\treturn nullptr;\n+\n+\treturn link(source, sourceIdx, sink, sinkIdx);\n+}\n+\n+/**\n+ * \\brief Retrieve the MediaLink connecting two pads, identified by the\n+ * entities they belong to and pad indexes\n+ * \\param source The source entity\n+ * \\param sourceIdx The index of the source pad\n+ * \\param sink The sink entity\n+ * \\param sinkIdx The index of the sink pad\n+ *\n+ * Find the link that connects the pads at index \\a sourceIdx of the source\n+ * entity \\a source, to the pad at index \\a sinkIdx of the sink entity \\a\n+ * sink, if any.\n+ *\n+ * \\sa MediaDevice::link(const std::string sourceName, unsigned int sourceIdx, const std::string sinkName, unsigned int sinkIdx) const\n+ * \\sa MediaDevice::link(const MediaPad *source, const MediaPad *sink) const\n+ *\n+ * \\return The link that connects the two entities, or nullptr if not such a\n+ * link exists\n+ */\n+MediaLink *MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx,\n+\t\t\t     const MediaEntity *sink, unsigned int sinkIdx)\n+{\n+\n+\tconst MediaPad *sourcePad = source->getPadByIndex(sourceIdx);\n+\tconst MediaPad *sinkPad = sink->getPadByIndex(sinkIdx);\n+\tif (!sourcePad || !sinkPad)\n+\t\treturn nullptr;\n+\n+\treturn link(sourcePad, sinkPad);\n+}\n+\n+/**\n+ * \\brief Retrieve the MediaLink that connects two pads\n+ * \\param source The source pad\n+ * \\param sink The sink pad\n+ *\n+ * \\sa MediaDevice::link(const std::string sourceName, unsigned int sourceIdx, const std::string sinkName, unsigned int sinkIdx) const\n+ * \\sa MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx, const MediaEntity *sink, unsigned int sinkIdx) const\n+ *\n+ * \\return The link that connects the two entities, nullptr otherwise\n+ */\n+MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink)\n+{\n+\tfor (MediaLink *link : source->links()) {\n+\t\tif (link->sink()->id() == sink->id())\n+\t\t\treturn link;\n+\t}\n+\n+\treturn nullptr;\n+}\n+\n /**\n  * \\var MediaDevice::objects_\n  * \\brief Global map of media objects (entities, pads, links) keyed by their\n","prefixes":["libcamera-devel","v2","2/4"]}