[{"id":267,"web_url":"https://patchwork.libcamera.org/comment/267/","msgid":"<2585871.qGi2XYiGBy@avalon>","date":"2019-01-08T21:33:32","subject":"Re: [libcamera-devel] [PATCH v3 3/3] libcamera: Add link handling\n\tfunctions","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 22:47:33 EET Jacopo Mondi wrote:\n> Add a function to the MediaLink class to set the state of a link to\n> enabled or disabled. The function makes use of an internal MediaDevice\n> method, which is defined private and only accessible by the MediaLink\n> setEnable() function itself.\n> \n> Also add to MediaDevice a function to reset all links registered in the\n> media graph.\n> \n> Signed-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(+)\n> \n> diff --git a/src/libcamera/include/media_device.h\n> b/src/libcamera/include/media_device.h index 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 */\n> diff --git a/src/libcamera/include/media_object.h\n> b/src/libcamera/include/media_object.h index 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\nsetEnabled() ?\n\nApart from that,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> \n>  private:\n>  \tfriend class MediaDevice;\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 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,\n> const MediaPad *sink) return 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\n> 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\n> their @@ -602,4 +631,50 @@ bool MediaDevice::populateLinks(const struct\n> media_v2_topology &topology) return 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\n> MEDIA_LNK_FL_* + * macros from the Media Controller API) to the given \\a\n> link. It implements + * low-level link setup as it performs no checks on\n> the validity of the \\a + * flags, and assumes that the supplied \\a flags\n> are valid for the link (e.g. + * 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 */\n> diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp\n> index 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\n> connect. */\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\n> freely, + * 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","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 BBD9860B2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 22:32:23 +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 3695E586;\n\tTue,  8 Jan 2019 22:32:23 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546983143;\n\tbh=5cn37g89qQe+czhQTrsro8BPrYoxvfYHQog58YMiumw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=i7qXYoiG9HLO4KSTq5J6lB/m6SPQaihNyuEroJDk+n7M7gE4c3AGOLKd56XAfMHLm\n\tZEbZt0J1xdQ6PCifcklUIDt4+dViKgPyamS00rg2bjLTpcMSTQ4qzxiXSbS4llR/gG\n\tCotrUm2WUcHADQbDYdHJO5w1IundHZ4cAx6F3kCU=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 08 Jan 2019 23:33:32 +0200","Message-ID":"<2585871.qGi2XYiGBy@avalon>","Organization":"Ideas on Board Oy","In-Reply-To":"<20190108204733.10823-4-jacopo@jmondi.org>","References":"<20190108204733.10823-1-jacopo@jmondi.org>\n\t<20190108204733.10823-4-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"7Bit","Content-Type":"text/plain; charset=\"us-ascii\"","Subject":"Re: [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 21:32:23 -0000"}},{"id":268,"web_url":"https://patchwork.libcamera.org/comment/268/","msgid":"<20190109081750.mnhxfzfbpsftpnvj@uno.localdomain>","date":"2019-01-09T08:17:50","subject":"Re: [libcamera-devel] [PATCH v3 3/3] libcamera: Add link handling\n\tfunctions","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"HI Laurent,\n\nOn Tue, Jan 08, 2019 at 11:33:32PM +0200, Laurent Pinchart wrote:\n> Hi Jacopo,\n>\n> Thank you for the patch.\n>\n> On Tuesday, 8 January 2019 22:47:33 EET Jacopo Mondi wrote:\n> > Add a function to the MediaLink class to set the state of a link to\n> > enabled or disabled. The function makes use of an internal MediaDevice\n> > method, which is defined private and only accessible by the MediaLink\n> > setEnable() function itself.\n> >\n> > Also add to MediaDevice a function to reset all links registered in the\n> > media graph.\n> >\n> > Signed-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(+)\n> >\n> > diff --git a/src/libcamera/include/media_device.h\n> > b/src/libcamera/include/media_device.h index 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 */\n> > diff --git a/src/libcamera/include/media_object.h\n> > b/src/libcamera/include/media_object.h index 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> setEnabled() ?\n>\n> Apart from that,\n>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>\n\nSorry, I missed to update that, as I was waiting for inputs on\nenable()/disable()\n\nNow fixed an pushed.\n\nThanks\n  j\n\n> >\n> >  private:\n> >  \tfriend class MediaDevice;\n> > diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> > index 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,\n> > const MediaPad *sink) return 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\n> > 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\n> > their @@ -602,4 +631,50 @@ bool MediaDevice::populateLinks(const struct\n> > media_v2_topology &topology) return 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\n> > MEDIA_LNK_FL_* + * macros from the Media Controller API) to the given \\a\n> > link. It implements + * low-level link setup as it performs no checks on\n> > the validity of the \\a + * flags, and assumes that the supplied \\a flags\n> > are valid for the link (e.g. + * 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 */\n> > diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp\n> > index 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\n> > connect. */\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\n> > freely, + * 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>\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n>\n>","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3E4A860B0B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Jan 2019 09:17:44 +0100 (CET)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay5-d.mail.gandi.net (Postfix) with ESMTPSA id BF5171C0004;\n\tWed,  9 Jan 2019 08:17:43 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Wed, 9 Jan 2019 09:17:50 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190109081750.mnhxfzfbpsftpnvj@uno.localdomain>","References":"<20190108204733.10823-1-jacopo@jmondi.org>\n\t<20190108204733.10823-4-jacopo@jmondi.org>\n\t<2585871.qGi2XYiGBy@avalon>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"uksn5y5eic7sokzy\"","Content-Disposition":"inline","In-Reply-To":"<2585871.qGi2XYiGBy@avalon>","User-Agent":"NeoMutt/20180716","Subject":"Re: [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":"Wed, 09 Jan 2019 08:17:44 -0000"}}]