{"id":761,"url":"https://patchwork.libcamera.org/api/patches/761/?format=json","web_url":"https://patchwork.libcamera.org/patch/761/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190320163055.22056-16-jacopo@jmondi.org>","date":"2019-03-20T16:30:39","name":"[libcamera-devel,v4,15/31] RFC: libcamera: ipu3: Enable ImgU media links","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"2750b2766eeb8728a290644eed82866de9c7b6c0","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/761/mbox/","series":[{"id":214,"url":"https://patchwork.libcamera.org/api/series/214/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=214","date":"2019-03-20T16:30:24","name":"libcamera: ipu3: Add ImgU support + multiple streams","version":4,"mbox":"https://patchwork.libcamera.org/series/214/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/761/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/761/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 68355611B9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Mar 2019 17:30:37 +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 00C4120000F;\n\tWed, 20 Mar 2019 16:30:36 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 20 Mar 2019 17:30:39 +0100","Message-Id":"<20190320163055.22056-16-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190320163055.22056-1-jacopo@jmondi.org>","References":"<20190320163055.22056-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 15/31] RFC: libcamera: ipu3: Enable\n\tImgU media 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":"Wed, 20 Mar 2019 16:30:37 -0000"},"content":"As the lenghty comment reports, link enable/disable is not trivial, as\nlinks in one ImgU instance interfere with capture operations in the\nother one. As I struggle to find where to disable links selectively,\nas of now reset the media graph and enable the required links at\nstreamConfiguration time.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 110 +++++++++++++++++++++++++++\n 1 file changed, 110 insertions(+)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex ed2409907cf0..43fa0e4a7f9d 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -52,6 +52,10 @@ public:\n \t}\n \n \tvoid init(MediaDevice *media, unsigned int index);\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 imguName_;\n@@ -264,6 +268,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 CIO2 device and to the ImgU\n@@ -589,6 +601,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_close_mdev;\n \n@@ -625,6 +661,80 @@ void ImgUDevice::init(MediaDevice *mediaDevice, unsigned int index)\n \tmediaDevice_ = mediaDevice;\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 = mediaDevice_->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+\tstd::string inputName = imguName_ + \" input\";\n+\tstd::string outputName = imguName_ + \" output\";\n+\tstd::string viewfinderName = imguName_ + \" viewfinder\";\n+\tstd::string statName = imguName_ + \" 3a stat\";\n+\tint ret;\n+\n+\t/* \\todo Establish rules to handle media devices open/close. */\n+\tret = mediaDevice_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = linkSetup(inputName, 0, imguName_, PAD_INPUT, enable);\n+\tif (ret) {\n+\t\tmediaDevice_->close();\n+\t\treturn ret;\n+\t}\n+\n+\tret = linkSetup(imguName_, PAD_OUTPUT, outputName, 0, enable);\n+\tif (ret) {\n+\t\tmediaDevice_->close();\n+\t\treturn ret;\n+\t}\n+\n+\tret = linkSetup(imguName_, PAD_VF, viewfinderName, 0, enable);\n+\tif (ret) {\n+\t\tmediaDevice_->close();\n+\t\treturn ret;\n+\t}\n+\n+\tret = linkSetup(imguName_, PAD_STAT, statName, 0, enable);\n+\tif (ret) {\n+\t\tmediaDevice_->close();\n+\t\treturn ret;\n+\t}\n+\n+\tmediaDevice_->close();\n+\n+\treturn 0;\n+}\n+\n int PipelineHandlerIPU3::mediaBusToCIO2Format(unsigned int code)\n {\n \tswitch (code) {\n","prefixes":["libcamera-devel","v4","15/31"]}