{"id":909,"url":"https://patchwork.libcamera.org/api/1.1/patches/909/?format=json","web_url":"https://patchwork.libcamera.org/patch/909/","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":"<20190403150735.27580-5-jacopo@jmondi.org>","date":"2019-04-03T15:07:31","name":"[libcamera-devel,v3,4/8] libcamera: ipu3: Add multiple stream memory management","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"14fe601e6ff546f8df57efcac0191204fa7c18fe","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/909/mbox/","series":[{"id":239,"url":"https://patchwork.libcamera.org/api/1.1/series/239/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=239","date":"2019-04-03T15:07:27","name":"libcamera: ipu3: Multiple streams support","version":3,"mbox":"https://patchwork.libcamera.org/series/239/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/909/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/909/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 29B63610C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 17:06:58 +0200 (CEST)","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 B87BDFF80B;\n\tWed,  3 Apr 2019 15:06:57 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  3 Apr 2019 17:07:31 +0200","Message-Id":"<20190403150735.27580-5-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190403150735.27580-1-jacopo@jmondi.org>","References":"<20190403150735.27580-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 4/8] libcamera: ipu3: Add multiple\n\tstream memory management","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, 03 Apr 2019 15:06:58 -0000"},"content":"Perform allocation and setup of memory sharing betweent the CIO2 output\nand the ImgU input and allocate memory for each active stream.\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 78 ++++++++++++++++++++++------\n 1 file changed, 62 insertions(+), 16 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex a12e3f9a496d..f7e75fac1dfe 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -91,6 +91,7 @@ public:\n \n \tBufferPool vfPool_;\n \tBufferPool statPool_;\n+\tBufferPool outPool_;\n };\n \n class CIO2Device\n@@ -428,13 +429,21 @@ int PipelineHandlerIPU3::configureStreams(Camera *camera,\n \treturn 0;\n }\n \n+/**\n+ * \\todo Clarify if 'viewfinder' and 'stat' nodes have to be set up and\n+ * started even if not in use. As of now, if not properly configured and\n+ * enabled, the ImgU processing pipeline stalls.\n+ *\n+ * In order to be able to start the 'viewfinder' and 'stat' nodes, we need\n+ * memory to be reserved.\n+ */\n int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n \t\t\t\t\t const std::set<Stream *> &streams)\n {\n \tIPU3CameraData *data = cameraData(camera);\n-\tStream *stream = *streams.begin();\n \tCIO2Device *cio2 = &data->cio2_;\n \tImgUDevice *imgu = data->imgu_;\n+\tunsigned int bufferCount;\n \tint ret;\n \n \t/* Share buffers between CIO2 output and ImgU input. */\n@@ -446,28 +455,64 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n \tif (ret)\n \t\treturn ret;\n \n-\t/* Export ImgU output buffers to the stream's pool. */\n-\tret = imgu->exportBuffers(&imgu->output_, &stream->bufferPool());\n-\tif (ret)\n-\t\treturn ret;\n-\n \t/*\n-\t * Reserve memory in viewfinder and stat output devices. Use the\n-\t * same number of buffers as the ones requested for the output\n-\t * stream.\n+\t * Use for internal pools the same buffer number as the input\n+\t * one: it should match the pipeline lenght.\n \t */\n-\tunsigned int bufferCount = stream->bufferPool().count();\n-\n-\timgu->viewfinder_.pool->createBuffers(bufferCount);\n-\tret = imgu->exportBuffers(&imgu->viewfinder_, imgu->viewfinder_.pool);\n-\tif (ret)\n-\t\treturn ret;\n-\n+\tbufferCount = pool->count();\n \timgu->stat_.pool->createBuffers(bufferCount);\n \tret = imgu->exportBuffers(&imgu->stat_, imgu->stat_.pool);\n \tif (ret)\n \t\treturn ret;\n \n+\tfor (Stream *stream : streams) {\n+\t\tif (isOutput(data, stream)) {\n+\t\t\t/* Export output buffers to the stream's pool. */\n+\t\t\tret = imgu->exportBuffers(&imgu->output_,\n+\t\t\t\t\t\t  &stream->bufferPool());\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\n+\t\t\tif (isViewfinderActive(data))\n+\t\t\t\tcontinue;\n+\n+\t\t\t/*\n+\t\t\t * Reserve memory in viewfinder device if it is not\n+\t\t\t * part of the active streams list. Use the same\n+\t\t\t * number of buffers as the ones requested for the\n+\t\t\t * output stream.\n+\t\t\t */\n+\t\t\tbufferCount = stream->bufferPool().count();\n+\t\t\timgu->viewfinder_.pool->createBuffers(bufferCount);\n+\t\t\tret = imgu->exportBuffers(&imgu->viewfinder_,\n+\t\t\t\t\t\t  imgu->viewfinder_.pool);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\t\t} else if (isViewfinder(data, stream)) {\n+\t\t\t/* Export viewfinder buffers to the stream's pool. */\n+\t\t\tret = imgu->exportBuffers(&imgu->viewfinder_,\n+\t\t\t\t\t\t  &stream->bufferPool());\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\n+\t\t\tif (isOutputActive(data))\n+\t\t\t\tcontinue;\n+\n+\t\t\t/*\n+\t\t\t * Reserve memory in output device if it is not part\n+\t\t\t * of the active streams list. Use the same number\n+\t\t\t * of buffers as the ones requested for the viewfinder\n+\t\t\t * stream.\n+\t\t\t */\n+\t\t\tbufferCount = stream->bufferPool().count();\n+\t\t\timgu->output_.pool->createBuffers(bufferCount);\n+\t\t\tret = imgu->exportBuffers(&imgu->output_,\n+\t\t\t\t\t\t  imgu->output_.pool);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n \treturn 0;\n }\n \n@@ -819,6 +864,7 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index)\n \n \toutput_.pad = PAD_OUTPUT;\n \toutput_.name = \"output\";\n+\toutput_.pool = &outPool_;\n \n \tviewfinder_.dev = V4L2Device::fromEntityName(media,\n \t\t\t\t\t\t     name_ + \" viewfinder\");\n","prefixes":["libcamera-devel","v3","4/8"]}