[{"id":1346,"web_url":"https://patchwork.libcamera.org/comment/1346/","msgid":"<20190415123612.GE4809@pendragon.ideasonboard.com>","date":"2019-04-15T12:36:12","subject":"Re: [libcamera-devel] [PATCH v4 04/12] libcamera: ipu3: Add\n\tmultiple stream memory management","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, Apr 09, 2019 at 09:25:40PM +0200, Jacopo Mondi wrote:\n> Perform allocation and setup of memory sharing between the CIO2 output\n> and the ImgU input and allocate memory for each active stream.\n\nNo SoB ?\n\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 65 +++++++++++++++++++++-------\n>  1 file changed, 49 insertions(+), 16 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 527213a8970a..f5d768f9f87f 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> @@ -380,13 +381,23 @@ 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> +\tIPU3Stream *outStream = &data->outStream_;\n> +\tIPU3Stream *vfStream = &data->vfStream_;\n>  \tCIO2Device *cio2 = &data->cio2_;\n>  \tImgUDevice *imgu = data->imgu_;\n> +\n>  \tint ret;\n>  \n>  \t/* Share buffers between CIO2 output and ImgU input. */\n> @@ -398,28 +409,49 @@ 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 the stat's internal pools the same number of buffer as\n\ns/pools/pool/\n\nWith this fixed,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t * for the input pool.\n> +\t * \\todo To be revised when we'll actually use the stat node.\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> +\tunsigned int bufferCount = 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> +\t/* Allocate buffers for each active stream. */\n> +\tfor (Stream *s : streams) {\n> +\t\tIPU3Stream *stream = static_cast<IPU3Stream *>(s);\n> +\t\tImgUDevice::ImgUOutput *dev = stream->device_;\n> +\n> +\t\tret = imgu->exportBuffers(dev, &stream->bufferPool());\n> +\t\tif (ret)\n> +\t\t\treturn ret;\n> +\t}\n> +\n> +\t/*\n> +\t * Allocate buffers also on non-active outputs; use the same number\n> +\t * of buffers as the active ones.\n> +\t */\n> +\tif (!outStream->active_) {\n> +\t\tbufferCount = vfStream->bufferPool().count();\n> +\t\toutStream->device_->pool->createBuffers(bufferCount);\n> +\t\tret = imgu->exportBuffers(outStream->device_,\n> +\t\t\t\t\t  outStream->device_->pool);\n> +\t\tif (ret)\n> +\t\t\treturn ret;\n> +\t}\n> +\n> +\tif (!vfStream->active_) {\n> +\t\tbufferCount = outStream->bufferPool().count();\n> +\t\tvfStream->device_->pool->createBuffers(bufferCount);\n> +\t\tret = imgu->exportBuffers(vfStream->device_,\n> +\t\t\t\t\t  vfStream->device_->pool);\n> +\t\tif (ret)\n> +\t\t\treturn ret;\n> +\t}\n> +\n>  \treturn 0;\n>  }\n>  \n> @@ -780,6 +812,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\");","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 BABD6600F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 Apr 2019 14:36:21 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0F8FF333;\n\tMon, 15 Apr 2019 14:36:21 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555331781;\n\tbh=Orid/CVJjWL1F5nT9kHj8kaYDbq3qNmafMlWZXm7gts=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=pG1L99xtrpeF6Ank3lJNhaBr849Pm4Ub/SH6a8AefjDpeR2xrv4z7wVDZoqckENxr\n\t5OtZatnKDKrJNSowFkR/nGtbk/l1ZhG/91oaveBHCoxkjwz4Ngtccn8veBWvwMxERl\n\tJx8wNOGJtrBKldl52K8pVtA3UV9SJgcGXbdwBDME=","Date":"Mon, 15 Apr 2019 15:36:12 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190415123612.GE4809@pendragon.ideasonboard.com>","References":"<20190409192548.20325-1-jacopo@jmondi.org>\n\t<20190409192548.20325-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190409192548.20325-5-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v4 04/12] libcamera: ipu3: Add\n\tmultiple stream 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":"Mon, 15 Apr 2019 12:36:22 -0000"}}]