{"id":146,"url":"https://patchwork.libcamera.org/api/1.1/patches/146/?format=json","web_url":"https://patchwork.libcamera.org/patch/146/","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":"<20190103173859.22624-3-jacopo@jmondi.org>","date":"2019-01-03T17:38:56","name":"[libcamera-devel,2/5] libcamera: media_device: Add function to get a MediaLink","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"492d4d1cb9a532c8bf40991bd1315ebfa9336ea8","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/146/mbox/","series":[{"id":52,"url":"https://patchwork.libcamera.org/api/1.1/series/52/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=52","date":"2019-01-03T17:38:54","name":"libcamera: media device: Add link handling","version":1,"mbox":"https://patchwork.libcamera.org/series/52/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/146/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/146/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 22A5B60B13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Jan 2019 18:39:03 +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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id B3A2DFF804;\n\tThu,  3 Jan 2019 17:39:02 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  3 Jan 2019 18:38:56 +0100","Message-Id":"<20190103173859.22624-3-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190103173859.22624-1-jacopo@jmondi.org>","References":"<20190103173859.22624-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 2/5] libcamera: media_device: Add function\n\tto 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":"Thu, 03 Jan 2019 17:39:03 -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 entities.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/media_device.h |   6 ++\n src/libcamera/media_device.cpp       | 119 +++++++++++++++++++++++++++\n 2 files changed, 125 insertions(+)","diff":"diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex 9f45fc7..3228ad5 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) const;\n+\tMediaLink *link(const MediaEntity *source, unsigned int sourceIdx,\n+\t\t\tconst MediaEntity *sink, unsigned int sinkIdx) const;\n+\tMediaLink *link(const MediaPad *source, const MediaPad *sink) const;\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 2f9490c..6892300 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -306,6 +306,125 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const\n \treturn nullptr;\n }\n \n+/**\n+ * \\brief Return the MediaLink that connects two entities identified by name\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 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, nullptr otherwise\n+ */\n+MediaLink *MediaDevice::link(const std::string sourceName, unsigned int sourceIdx,\n+\t\t\t     const std::string sinkName, unsigned int sinkIdx) const\n+{\n+\tconst MediaEntity *source = getEntityByName(sourceName);\n+\tif (!source) {\n+\t\tLOG(Error) << \"Failed to find entity with name: \"\n+\t\t\t   << sourceName << \"\\n\";\n+\t\treturn nullptr;\n+\t}\n+\n+\tconst MediaPad *sourcePad = source->getPadByIndex(sourceIdx);\n+\tif (!sourcePad) {\n+\t\tLOG(Error) << \"Entity \\\"\" << sourceName << \"\\\" \"\n+\t\t\t   << \"has no pad at index \" << sourceIdx << \"\\n\";\n+\t\treturn nullptr;\n+\t}\n+\n+\tconst MediaEntity *sink = getEntityByName(sinkName);\n+\tif (!sink) {\n+\t\tLOG(Error) << \"Failed to find entity with name: \"\n+\t\t\t   << sinkName << \"\\n\";\n+\t\treturn nullptr;\n+\t}\n+\n+\tconst MediaPad *sinkPad = sink->getPadByIndex(sinkIdx);\n+\tif (!sinkPad) {\n+\t\tLOG(Error) << \"Entity \\\"\" << sinkName << \"\\\" \"\n+\t\t\t   << \"has no pad at index \" << sinkIdx << \"\\n\";\n+\t\treturn nullptr;\n+\t}\n+\n+\treturn link(sourcePad, sinkPad);\n+}\n+\n+/**\n+ * \\brief Return the MediaLink that connects two entities\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 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, nullptr otherwise\n+ */\n+MediaLink *MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx,\n+\t\t\t     const MediaEntity *sink, unsigned int sinkIdx) const\n+{\n+\n+\tconst MediaPad *sourcePad = source->getPadByIndex(sourceIdx);\n+\tif (!sourcePad) {\n+\t\tLOG(Error) << \"Entity \\\"\" << source->name() << \"\\\" \"\n+\t\t\t   << \"has no pad at index \" << sourceIdx << \"\\n\";\n+\t\treturn nullptr;\n+\t}\n+\n+\tconst MediaPad *sinkPad = sink->getPadByIndex(sinkIdx);\n+\tif (!sinkPad) {\n+\t\tLOG(Error) << \"Entity \\\"\" << sink->name() << \"\\\" \"\n+\t\t\t   << \"has no pad at index \" << sinkIdx << \"\\n\";\n+\t\treturn nullptr;\n+\t}\n+\n+\treturn link(sourcePad, sinkPad);\n+}\n+\n+/**\n+ * \\brief Return 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 pads, nullptr otherwise\n+ */\n+MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink) const\n+{\n+\tif (!source || !sink)\n+\t\treturn nullptr;\n+\n+\t/*\n+\t * Now that we have made sure all instances are valid, compare\n+\t * their ids to find a matching link.\n+\t */\n+\tfor (MediaLink *link : source->links()) {\n+\t\tif (link->sink()->id() != sink->id())\n+\t\t\tcontinue;\n+\n+\t\tif (link->sink()->entity()->id() != sink->entity()->id())\n+\t\t\tcontinue;\n+\n+\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","2/5"]}