[{"id":1008,"web_url":"https://patchwork.libcamera.org/comment/1008/","msgid":"<20190302225101.GL4682@pendragon.ideasonboard.com>","date":"2019-03-02T22:51:01","subject":"Re: [libcamera-devel] [PATCH 05/10] libcamera: ipu3: Implement\n\tbuffer allocation","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 Thu, Feb 28, 2019 at 09:04:05PM +0100, Jacopo Mondi wrote:\n> Implement buffer allocation in IPU3 pipeline handlers.\n> As the pipeline handler supports a single stream, preprare two buffer\n> pools for 'viewfinder' and 'stat' video devices, and export the 'output'\n> video device buffers to the Stream's pool.\n> \n> Share buffers between the CIO2 output and the ImgU input video devices,\n> as the output of the former should immediately be provided to the\n> latter for further processing.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 47 ++++++++++++++++++++++++----\n>  1 file changed, 41 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 1e89e57f628b..c7b7973952a0 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -47,6 +47,9 @@ struct ImguDevice {\n>  \tV4L2Device *viewfinder;\n>  \tV4L2Device *stat;\n>  \t/* TODO: add param video device for 3A tuning */\n> +\n> +\tBufferPool vfPool;\n> +\tBufferPool statPool;\n>  };\n>  \n>  struct Cio2Device {\n> @@ -63,6 +66,8 @@ struct Cio2Device {\n>  \tV4L2Device *output;\n>  \tV4L2Subdevice *csi2;\n>  \tV4L2Subdevice *sensor;\n> +\n> +\tBufferPool pool;\n>  };\n>  \n>  class IPU3CameraData : public CameraData\n> @@ -319,18 +324,48 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, Stream *stream)\n>  {\n>  \tconst StreamConfiguration &cfg = stream->configuration();\n>  \tIPU3CameraData *data = cameraData(camera);\n> +\tV4L2Device *viewfinder = data->imgu->viewfinder;\n> +\tV4L2Device *output = data->imgu->output;\n> +\tV4L2Device *input = data->imgu->input;\n>  \tV4L2Device *cio2 = data->cio2.output;\n> +\tV4L2Device *stat = data->imgu->stat;\n> +\tint ret;\n>  \n> -\tif (!cfg.bufferCount)\n> +\tif (!cfg.bufferCount) {\n> +\t\tLOG(IPU3, Error)\n> +\t\t\t<< \"Invalid number of buffers: \"<< cfg.bufferCount;\n>  \t\treturn -EINVAL;\n\nCan this happen ? Shouldn't it be caught in upper layers ?\n\n> -\n> -\tint ret = cio2->exportBuffers(&stream->bufferPool());\n> -\tif (ret) {\n> -\t\tLOG(IPU3, Error) << \"Failed to request memory\";\n> -\t\treturn ret;\n>  \t}\n>  \n> +\t/* Share buffers between CIO2 output and ImgU input. */\n> +\tdata->cio2.pool.createBuffers(IPU3_BUF_NUM);\n\nThe number of buffers doesn't have to match between the internal pool\nand the external pool. I would define a separate constant for this, even\nif their values happen to be the same for now.\n\n> +\tret = cio2->exportBuffers(&data->cio2.pool);\n> +\tif (ret)\n> +\t\tgoto error_reserve_memory;\n> +\tinput->importBuffers(&data->cio2.pool);\n\nCan't this fail ?\n\n> +\n> +\t/* Prepare the buffer pools for viewfinder and stat. */\n> +\tdata->imgu->vfPool.createBuffers(IPU3_BUF_NUM);\n> +\tret = viewfinder->exportBuffers(&data->imgu->vfPool);\n> +\tif (ret)\n> +\t\tgoto error_reserve_memory;\n> +\n> +\tdata->imgu->statPool.createBuffers(IPU3_BUF_NUM);\n> +\tret = stat->exportBuffers(&data->imgu->statPool);\n> +\tif (ret)\n> +\t\tgoto error_reserve_memory;\n> +\n> +\t/* Export ImgU output buffers to the stream's pool. */\n> +\tret = output->exportBuffers(&stream->bufferPool());\n> +\tif (ret)\n> +\t\tgoto error_reserve_memory;\n> +\n>  \treturn 0;\n> +\n> +error_reserve_memory:\n> +\tLOG(IPU3, Error) << \"Failed to reserve memory\";\n\nI'd duplicate the error message instead of using a goto, in order to\nprint which memory allocation failed.\n\nAs we won't queue buffers for the viewfinder and stats video node (at\nleast for now), do we even need to allocate them ?\n\n> +\n> +\treturn ret;\n>  }\n>  \n>  int PipelineHandlerIPU3::freeBuffers(Camera *camera, Stream *stream)","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 0C970610BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  2 Mar 2019 23:51:08 +0100 (CET)","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 69A4054E;\n\tSat,  2 Mar 2019 23:51:07 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1551567067;\n\tbh=EJ4jVBo5/kUVhn1lw4CKW4hYK5L9LOJS1U2DjAKmKNc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=F5w+V4m0Apwg/UVTccl1h4n4epztDRBDbj7hq0Q9gIfhCTLVevatjS29Gvcb+cm3+\n\tK22DMarfMZ3RpFRgywQ7eOc8zMTUOmRAqXN0lxNMzwmvn+qoy3vNx3R9cIlA6EsgVr\n\t3uxiQA422h/9xRcZNcySLyk7BWqfdpqR6p+nDaO8=","Date":"Sun, 3 Mar 2019 00:51:01 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190302225101.GL4682@pendragon.ideasonboard.com>","References":"<20190228200410.3022-1-jacopo@jmondi.org>\n\t<20190228200410.3022-6-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190228200410.3022-6-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 05/10] libcamera: ipu3: Implement\n\tbuffer allocation","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":"Sat, 02 Mar 2019 22:51:08 -0000"}}]