[{"id":259,"web_url":"https://patchwork.libcamera.org/comment/259/","msgid":"<2340076.z8LKMoXKEm@avalon>","date":"2019-01-08T18:11:13","subject":"Re: [libcamera-devel] [PATCH v2 2/4] libcamera: media_device: Add\n\tfunctions to get a MediaLink","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Tuesday, 8 January 2019 19:04:05 EET Jacopo Mondi wrote:\n> Add three overloaded functions 'link()' to retrieve a link between two\n> pads. Each overloaded implementation exposes a different method to\n> identify the source and sink pads.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n> v1->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> diff --git a/src/libcamera/include/media_device.h\n> b/src/libcamera/include/media_device.h index 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\nsourceName and sinkName should be references. Don't forget to update the \\sa \nin the documentation accordingly.\n\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_;\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 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\n> std::string &name) const return 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,\n> const MediaEntity *sink, unsigned int sinkIdx) const + * \\sa\n> MediaDevice::link(const MediaPad *source, const MediaPad *sink) const + *\n> + * \\return The link that connects the two entities, or nullptr if not such\n\ns/entities/pads/\n\n> a + * link exists\n> + */\n> +MediaLink *MediaDevice::link(const std::string sourceName, unsigned int\n> sourceIdx, +\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\n> sourceIdx, const std::string sinkName, unsigned int sinkIdx) const + * \\sa\n> MediaDevice::link(const MediaPad *source, const MediaPad *sink) const + *\n> + * \\return The link that connects the two entities, or nullptr if not such\n\ns/entities/pads/\n\n> a + * link exists\n> + */\n> +MediaLink *MediaDevice::link(const MediaEntity *source, unsigned int\n> 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\n> sourceIdx, const std::string sinkName, unsigned int sinkIdx) const + * \\sa\n> MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx, const\n> MediaEntity *sink, unsigned int sinkIdx) const + *\n> + * \\return The link that connects the two entities, nullptr otherwise\n\n\"The link that connects the two pads, or nullptr if not such link exists\"\n\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\n> their\n\nWith the small issues above fixed,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CCFB60B2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 19:10:06 +0100 (CET)","from avalon.localnet (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 439FE586;\n\tTue,  8 Jan 2019 19:10:05 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546971005;\n\tbh=qFBvT4tLbSMvu0jkkbuWsURLwQOhpPhOwP/s06V0a5w=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=gzpviHPBCG5ZMySXpGwxyBkQJluw07bCM2c+vmVMpEEp1Czex5a/hEwE2OogW+PIq\n\tQ0awWqnxOZaJVL70cdf3QyVd/u30rmzZ/2mAaiFyE+Edbyfy/XS4VZM8a3OCUze0S/\n\tFYjuNb3/ZBJWObiSLA1zOzslNZzSPVTInGwqo+Y4=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 08 Jan 2019 20:11:13 +0200","Message-ID":"<2340076.z8LKMoXKEm@avalon>","Organization":"Ideas on Board Oy","In-Reply-To":"<20190108170407.4770-3-jacopo@jmondi.org>","References":"<20190108170407.4770-1-jacopo@jmondi.org>\n\t<20190108170407.4770-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"7Bit","Content-Type":"text/plain; charset=\"us-ascii\"","Subject":"Re: [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 18:10:06 -0000"}}]