[{"id":1191,"web_url":"https://patchwork.libcamera.org/comment/1191/","msgid":"<20190402110201.GO4805@pendragon.ideasonboard.com>","date":"2019-04-02T11:02:01","subject":"Re: [libcamera-devel] [PATCH v5 19/19] libcamera: ipu3: Enable ImgU\n\tmedia links","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 Tue, Mar 26, 2019 at 09:39:02AM +0100, Jacopo Mondi wrote:\n> As the lenghty comment reports, link enable/disable is not trivial, as\n\ns/lenghty/lengthy/\n\n> links in one ImgU instance interfere with capture operations in the\n> other one. As it is not yet clear if this behaviour is intended,\n> as of now reset the media graph during pipeline's match() and enable\n> the required links at streamConfiguration time.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 111 +++++++++++++++++++++++++++\n>  1 file changed, 111 insertions(+)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 66efcc37d695..f92728ae5b85 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -114,6 +114,11 @@ public:\n>  \tint start();\n>  \tvoid stop();\n>  \n> +\tint linkSetup(const std::string &source, unsigned int sourcePad,\n> +\t\t      const std::string &sink, unsigned int sinkPad,\n> +\t\t      bool enable);\n> +\tint enableLinks(bool enable);\n> +\n>  \tunsigned int index_;\n>  \tstd::string name_;\n>  \tMediaDevice *media_;\n> @@ -304,6 +309,14 @@ int PipelineHandlerIPU3::configureStreams(Camera *camera,\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> +\t/*\n> +\t * \\todo: Enable links selectively based on the requested streams.\n> +\t * As of now, enable all links unconditionally.\n> +\t */\n> +\tret = data->imgu_->enableLinks(true);\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n>  \t/*\n>  \t * Pass the requested output image size to the sensor and get back the\n>  \t * adjusted one to be propagated to the to the ImgU devices.\n> @@ -506,6 +519,30 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>  \t\treturn false;\n>  \t}\n>  \n> +\t/*\n> +\t * FIXME: enabled links in one ImgU instance interfere with capture\n> +\t * operations on the other one. This can be easily triggered by\n> +\t * capturing from one camera and then trying to capture from the other\n> +\t * one right after, without disabling media links in the media graph\n> +\t * first.\n> +\t *\n> +\t * The tricky part here is where to disable links on the ImgU instance\n> +\t * which is currently not in use:\n> +\t * 1) Link enable/disable cannot be done at start/stop time as video\n> +\t * devices needs to be linked first before format can be configured on\n> +\t * them.\n> +\t * 2) As link enable has to be done at the least in configureStreams,\n> +\t * before configuring formats, the only place where to disable links\n> +\t * would be 'stop()', but the Camera class state machine allows\n> +\t * start()<->stop() sequences without any streamConfiguration() in\n> +\t * between.\n> +\t *\n> +\t * As of now, disable all links in the media graph at 'match()' time,\n> +\t * to allow testing different cameras in different test applications\n> +\t * runs. A test application that would use two distinct cameras without\n> +\t * going through a library teardown->match() sequence would fail\n> +\t * at the moment.\n> +\t */\n>  \tif (imguMediaDev_->disableLinks())\n>  \t\tgoto error;\n>  \n> @@ -946,6 +983,80 @@ void ImgUDevice::stop()\n>  \tinput_->streamOff();\n>  }\n>  \n> +/**\n> + * \\brief Enable or disable a single link on the ImgU instance\n> + *\n> + * This method assumes the media device associated with the ImgU instance\n> + * is open.\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int ImgUDevice::linkSetup(const std::string &source, unsigned int sourcePad,\n> +\t\t\t  const std::string &sink, unsigned int sinkPad,\n> +\t\t\t  bool enable)\n> +{\n> +\tMediaLink *link = media_->link(source, sourcePad, sink, sinkPad);\n> +\tif (!link) {\n> +\t\tLOG(IPU3, Error)\n> +\t\t\t<< \"Failed to get link: '\" << source << \"':\"\n> +\t\t\t<< sourcePad << \" -> '\" << sink << \"':\" << sinkPad;\n> +\t\treturn -ENODEV;\n> +\t}\n> +\n> +\treturn link->setEnabled(enable);\n> +}\n\nIs this worth a helper in MediaDevice ?\n\n> +\n> +/**\n> + * \\brief Enable or disable all media links in the ImgU instance to prepare\n> + * for capture operations\n> + *\n> + * \\todo This method will probably be removed or changed once links will be\n> + * enabled or disabled selectively.\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int ImgUDevice::enableLinks(bool enable)\n> +{\n> +\tint ret;\n> +\n> +\t/* \\todo Establish rules to handle media devices open/close. */\n> +\tret = media_->open();\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\tstd::string inputName = name_ + \" input\";\n> +\tret = linkSetup(inputName, 0, name_, PAD_INPUT, enable);\n> +\tif (ret) {\n> +\t\tmedia_->close();\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tstd::string outputName = name_ + \" output\";\n> +\tret = linkSetup(name_, PAD_OUTPUT, outputName, 0, enable);\n> +\tif (ret) {\n> +\t\tmedia_->close();\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tstd::string viewfinderName = name_ + \" viewfinder\";\n> +\tret = linkSetup(name_, PAD_VF, viewfinderName, 0, enable);\n> +\tif (ret) {\n> +\t\tmedia_->close();\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tstd::string statName = name_ + \" 3a stat\";\n> +\tret = linkSetup(name_, PAD_STAT, statName, 0, enable);\n> +\tif (ret) {\n> +\t\tmedia_->close();\n> +\t\treturn ret;\n> +\t}\n> +\n\nYou can add a done label here, return ret at the end of the function and\nreplace all the media_->close(); return ret; with a goto done.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nuntil the IPU3 driver gets fixed.\n\n> +\tmedia_->close();\n> +\n> +\treturn 0;\n> +}\n> +\n>  /*------------------------------------------------------------------------------\n>   * CIO2 Device\n>   */","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 2892B60DB3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Apr 2019 13:02:13 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 893482F9;\n\tTue,  2 Apr 2019 13:02:12 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1554202932;\n\tbh=OhRpE2KkJvhYVKs9urX9cLs+ldgPADEzVAOd3dm/YRw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=A7xnsIx8AYApFUvm6+nu9WliJ+4OFUMzzrFj/aRPs87rW+fnBmXKf4G5HDiJWOQaw\n\t6abQ0/yauPFOSiQBwSh3tBZnDMvbGyJ5O968DEdH4JXLuV+6DOXtRcwNIl66OXpw9C\n\tWUk6vPuo5LDETmN6DOW9ay8vUWNcchl+JbRrKS3w=","Date":"Tue, 2 Apr 2019 14:02:01 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190402110201.GO4805@pendragon.ideasonboard.com>","References":"<20190326083902.26121-1-jacopo@jmondi.org>\n\t<20190326083902.26121-20-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190326083902.26121-20-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v5 19/19] libcamera: ipu3: Enable ImgU\n\tmedia links","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, 02 Apr 2019 11:02:16 -0000"}},{"id":1200,"web_url":"https://patchwork.libcamera.org/comment/1200/","msgid":"<20190402114438.GT23466@bigcity.dyn.berto.se>","date":"2019-04-02T11:44:38","subject":"Re: [libcamera-devel] [PATCH v5 19/19] libcamera: ipu3: Enable ImgU\n\tmedia links","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your work.\n\nOn 2019-03-26 09:39:02 +0100, Jacopo Mondi wrote:\n> As the lenghty comment reports, link enable/disable is not trivial, as\n> links in one ImgU instance interfere with capture operations in the\n> other one. As it is not yet clear if this behaviour is intended,\n> as of now reset the media graph during pipeline's match() and enable\n> the required links at streamConfiguration time.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 111 +++++++++++++++++++++++++++\n>  1 file changed, 111 insertions(+)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 66efcc37d695..f92728ae5b85 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -114,6 +114,11 @@ public:\n>  \tint start();\n>  \tvoid stop();\n>  \n> +\tint linkSetup(const std::string &source, unsigned int sourcePad,\n> +\t\t      const std::string &sink, unsigned int sinkPad,\n> +\t\t      bool enable);\n> +\tint enableLinks(bool enable);\n> +\n>  \tunsigned int index_;\n>  \tstd::string name_;\n>  \tMediaDevice *media_;\n> @@ -304,6 +309,14 @@ int PipelineHandlerIPU3::configureStreams(Camera *camera,\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> +\t/*\n> +\t * \\todo: Enable links selectively based on the requested streams.\n> +\t * As of now, enable all links unconditionally.\n> +\t */\n> +\tret = data->imgu_->enableLinks(true);\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n>  \t/*\n>  \t * Pass the requested output image size to the sensor and get back the\n>  \t * adjusted one to be propagated to the to the ImgU devices.\n> @@ -506,6 +519,30 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>  \t\treturn false;\n>  \t}\n>  \n> +\t/*\n> +\t * FIXME: enabled links in one ImgU instance interfere with capture\n> +\t * operations on the other one. This can be easily triggered by\n> +\t * capturing from one camera and then trying to capture from the other\n> +\t * one right after, without disabling media links in the media graph\n> +\t * first.\n> +\t *\n> +\t * The tricky part here is where to disable links on the ImgU instance\n> +\t * which is currently not in use:\n> +\t * 1) Link enable/disable cannot be done at start/stop time as video\n> +\t * devices needs to be linked first before format can be configured on\n> +\t * them.\n> +\t * 2) As link enable has to be done at the least in configureStreams,\n> +\t * before configuring formats, the only place where to disable links\n> +\t * would be 'stop()', but the Camera class state machine allows\n> +\t * start()<->stop() sequences without any streamConfiguration() in\n> +\t * between.\n> +\t *\n> +\t * As of now, disable all links in the media graph at 'match()' time,\n> +\t * to allow testing different cameras in different test applications\n> +\t * runs. A test application that would use two distinct cameras without\n> +\t * going through a library teardown->match() sequence would fail\n> +\t * at the moment.\n> +\t */\n>  \tif (imguMediaDev_->disableLinks())\n>  \t\tgoto error;\n>  \n> @@ -946,6 +983,80 @@ void ImgUDevice::stop()\n>  \tinput_->streamOff();\n>  }\n>  \n> +/**\n> + * \\brief Enable or disable a single link on the ImgU instance\n> + *\n> + * This method assumes the media device associated with the ImgU instance\n> + * is open.\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int ImgUDevice::linkSetup(const std::string &source, unsigned int sourcePad,\n> +\t\t\t  const std::string &sink, unsigned int sinkPad,\n> +\t\t\t  bool enable)\n> +{\n> +\tMediaLink *link = media_->link(source, sourcePad, sink, sinkPad);\n> +\tif (!link) {\n> +\t\tLOG(IPU3, Error)\n> +\t\t\t<< \"Failed to get link: '\" << source << \"':\"\n> +\t\t\t<< sourcePad << \" -> '\" << sink << \"':\" << sinkPad;\n> +\t\treturn -ENODEV;\n> +\t}\n> +\n> +\treturn link->setEnabled(enable);\n> +}\n> +\n> +/**\n> + * \\brief Enable or disable all media links in the ImgU instance to prepare\n> + * for capture operations\n> + *\n> + * \\todo This method will probably be removed or changed once links will be\n> + * enabled or disabled selectively.\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int ImgUDevice::enableLinks(bool enable)\n> +{\n> +\tint ret;\n> +\n> +\t/* \\todo Establish rules to handle media devices open/close. */\n> +\tret = media_->open();\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\tstd::string inputName = name_ + \" input\";\n> +\tret = linkSetup(inputName, 0, name_, PAD_INPUT, enable);\n> +\tif (ret) {\n> +\t\tmedia_->close();\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tstd::string outputName = name_ + \" output\";\n> +\tret = linkSetup(name_, PAD_OUTPUT, outputName, 0, enable);\n> +\tif (ret) {\n> +\t\tmedia_->close();\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tstd::string viewfinderName = name_ + \" viewfinder\";\n> +\tret = linkSetup(name_, PAD_VF, viewfinderName, 0, enable);\n> +\tif (ret) {\n> +\t\tmedia_->close();\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tstd::string statName = name_ + \" 3a stat\";\n> +\tret = linkSetup(name_, PAD_STAT, statName, 0, enable);\n> +\tif (ret) {\n> +\t\tmedia_->close();\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tmedia_->close();\n> +\n> +\treturn 0;\n\nWith Laurents suggestion to use a done label here,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> +}\n> +\n>  /*------------------------------------------------------------------------------\n>   * CIO2 Device\n>   */\n> -- \n> 2.21.0\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x232.google.com (mail-lj1-x232.google.com\n\t[IPv6:2a00:1450:4864:20::232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 93FF560DB3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Apr 2019 13:44:40 +0200 (CEST)","by mail-lj1-x232.google.com with SMTP id h21so11233415ljk.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 02 Apr 2019 04:44:40 -0700 (PDT)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tz15sm2686158ljz.55.2019.04.02.04.44.39\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tTue, 02 Apr 2019 04:44:39 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=5HD2Q/MGxs42jqi0WQODdm4tTkrs64nqKGvUN5lYH40=;\n\tb=BijST9dLbVGlr/PybRr9CvKk6bEm7546XMW6lzIZhnUTBJbZ21zje9mO0/kZFOL0/Y\n\tPdkNJAVHIPylEa6gA8EjzkWIEudKFSLHsEbwHWmlKElUGLz+0uD17m3jC1Hv1yCf5qga\n\tzwhLCkQ0+QKrQ1z6Mow8eZXzeJqBNQIQkR02vQi+2yI+5dMFyW4N+bW3+d3yMWVc+3nN\n\tgX43/KdUNz6HKkiUM3DpEwdEdAWSCuGdFG4nJ5WI115xTbQ7IaC7u21+klYIFidhUFQE\n\t8z+BsDIZTGU2sbJhvhD4Zip/4wMEK9xALd3XTkk4u8U07Yj7tI7KOePOulf43uZJzM4b\n\tadDA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=5HD2Q/MGxs42jqi0WQODdm4tTkrs64nqKGvUN5lYH40=;\n\tb=NwnohYT4ulmI2R+6VT1td72LYQc32ZEwN5fRWoUb8SFC6+0P6HlEuzxZljrvm+zKyf\n\tnVBnVIX36HKAo0Q1liUMvR7k4FCH1cDxf9xkIg3X/AO7/l1/drlxGF83t6T03N9tJoV3\n\toVkIvR0oebXAcqxf5uO6ZAhUCOCC/ZbpcTETIP9/l0SPY0ryeWRXbXf3DWG9us4/e48U\n\tjbK5eFAgjORNdEBIBAg7e/HjTfy12dqKvdVuajenwdDDyIE5IfNcxH5n/vtz3oeisrEN\n\tcgKABVEP33Pl4r9OV3HEU012WrP0ke/4DzieLay5a0a5Bo0LqPSvT3cdP35WXVlp4dbx\n\tgdMg==","X-Gm-Message-State":"APjAAAWZ90/poX+9bwPtYJf7sBnwT46UuhX0uZ9oPlpJeQkDp/rCTGnR\n\tOIN2kR1x19J2l2WQ/XJZvUUzimHmhwo=","X-Google-Smtp-Source":"APXvYqwDSw4ciZ99f25x2fgykvqDiJpNL7rAi3zOk06nL9OchlA4S8bX4PpkveI/1n1XDgJE3Habgg==","X-Received":"by 2002:a2e:128a:: with SMTP id\n\t10mr41392795ljs.170.1554205480023; \n\tTue, 02 Apr 2019 04:44:40 -0700 (PDT)","Date":"Tue, 2 Apr 2019 13:44:38 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190402114438.GT23466@bigcity.dyn.berto.se>","References":"<20190326083902.26121-1-jacopo@jmondi.org>\n\t<20190326083902.26121-20-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190326083902.26121-20-jacopo@jmondi.org>","User-Agent":"Mutt/1.11.3 (2019-02-01)","Subject":"Re: [libcamera-devel] [PATCH v5 19/19] libcamera: ipu3: Enable ImgU\n\tmedia links","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, 02 Apr 2019 11:44:40 -0000"}}]