[{"id":2180,"web_url":"https://patchwork.libcamera.org/comment/2180/","msgid":"<20190706114552.GM17685@bigcity.dyn.berto.se>","date":"2019-07-06T11:45:52","subject":"Re: [libcamera-devel] [PATCH 3/9] libcamera: pipeline: Support\n\texternal buffers","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 patch.\n\nOn 2019-07-05 00:53:28 +0200, Jacopo Mondi wrote:\n> Add support for use external buffers to libcamera pipeline handlers.\n> \n> Use the memory type flag in pipeline handlers (todo: change all pipeline\n> handlers) during buffer setup operations, to decide if the Stream's\n> internal memory has to be exported to applications, or the Stream\n> should prepare to use buffers whose memory is allocated elsewhere.\n\nI think you can drop the TODO now as it seems all pipeline handlers are \nnow supprted, right?\n\n> \n> To support the last use case, a translation mechanism between the external\n> buffers provided by applications and internal ones used by pipeline\n> handlers to feed the video device will be implemented on top of this\n> change.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp     | 31 +++++++++++++++++++++++-\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp |  9 ++++++-\n>  src/libcamera/pipeline/uvcvideo.cpp      |  8 +++++-\n>  src/libcamera/pipeline/vimc.cpp          |  8 +++++-\n>  4 files changed, 52 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 2de0892138a8..6f14da1f8c70 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -71,6 +71,7 @@ public:\n>  \n>  \tint importBuffers(BufferPool *pool);\n>  \tint exportBuffers(ImgUOutput *output, BufferPool *pool);\n> +\tint reserveDmabufBuffers(ImgUOutput *output, BufferPool *pool);\n>  \tvoid freeBuffers();\n>  \n>  \tint start();\n> @@ -624,7 +625,11 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\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 (stream->memoryType() == ExternalMemory)\n> +\t\t\tret = imgu->reserveDmabufBuffers(dev,\n> +\t\t\t\t\t\t\t &stream->bufferPool());\n\nI would s/reserveDmabufBuffers/importBuffers/ to match the logic in \nother pipeline handlers.\n\n> +\t\telse\n> +\t\t\tret = imgu->exportBuffers(dev, &stream->bufferPool());\n>  \t\tif (ret)\n>  \t\t\tgoto error;\n>  \t}\n> @@ -1153,6 +1158,30 @@ int ImgUDevice::exportBuffers(ImgUOutput *output, BufferPool *pool)\n>  \treturn 0;\n>  }\n>  \n> +/**\n> + * \\brief Reserve buffers in \\a output from the provided \\a pool\n> + * \\param[in] output The ImgU output device\n> + * \\param[in] pool The buffer pool used to reserve buffers in \\a output\n> + *\n> + * Reserve a number of buffers equal to the number of buffers in \\a pool\n> + * in the \\a output device to prepare for streaming operations using buffers\n> + * whose memory has been reserved elsewhere identified with DMABUF file\n> + * descriptors.\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int ImgUDevice::reserveDmabufBuffers(ImgUOutput *output, BufferPool *pool)\n> +{\n> +\tint ret = output->dev->importBuffers(pool);\n> +\tif (ret) {\n> +\t\tLOG(IPU3, Error) << \"Failed to import buffer in \"\n> +\t\t\t\t << output->name << \" ImgU device\";\n> +\t\treturn ret;\n> +\t}\n> +\n> +\treturn 0;\n> +}\n> +\n>  /**\n>   * \\brief Release buffers for all the ImgU video devices\n>   */\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 4a5898d25f91..dbb61a21354d 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -319,7 +319,14 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera,\n>  \t\t\t\t\t   const std::set<Stream *> &streams)\n>  {\n>  \tStream *stream = *streams.begin();\n> -\treturn video_->exportBuffers(&stream->bufferPool());\n> +\tint ret;\n> +\n> +\tif (stream->memoryType() == InternalMemory)\n> +\t\tret = video_->exportBuffers(&stream->bufferPool());\n> +\telse\n> +\t\tret = video_->importBuffers(&stream->bufferPool());\n> +\n> +\treturn ret;\n>  }\n>  \n>  int PipelineHandlerRkISP1::freeBuffers(Camera *camera,\n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index 72313cfd246f..5b3c79dda6dd 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -197,10 +197,16 @@ int PipelineHandlerUVC::allocateBuffers(Camera *camera,\n>  \tUVCCameraData *data = cameraData(camera);\n>  \tStream *stream = *streams.begin();\n>  \tconst StreamConfiguration &cfg = stream->configuration();\n> +\tint ret;\n>  \n>  \tLOG(UVC, Debug) << \"Requesting \" << cfg.bufferCount << \" buffers\";\n>  \n> -\treturn data->video_->exportBuffers(&stream->bufferPool());\n> +\tif (stream->memoryType() == InternalMemory)\n> +\t\tret = data->video_->exportBuffers(&stream->bufferPool());\n> +\telse\n> +\t\tret = data->video_->importBuffers(&stream->bufferPool());\n> +\n> +\treturn ret;\n>  }\n>  \n>  int PipelineHandlerUVC::freeBuffers(Camera *camera,\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index f8a58be060bb..c67bdb0ecbff 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -199,10 +199,16 @@ int PipelineHandlerVimc::allocateBuffers(Camera *camera,\n>  \tVimcCameraData *data = cameraData(camera);\n>  \tStream *stream = *streams.begin();\n>  \tconst StreamConfiguration &cfg = stream->configuration();\n> +\tint ret;\n>  \n>  \tLOG(VIMC, Debug) << \"Requesting \" << cfg.bufferCount << \" buffers\";\n>  \n> -\treturn data->video_->exportBuffers(&stream->bufferPool());\n> +\tif (stream->memoryType() == InternalMemory)\n> +\t\tret = data->video_->exportBuffers(&stream->bufferPool());\n> +\telse\n> +\t\tret = data->video_->importBuffers(&stream->bufferPool());\n> +\n> +\treturn ret;\n>  }\n>  \n>  int PipelineHandlerVimc::freeBuffers(Camera *camera,\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-x231.google.com (mail-lj1-x231.google.com\n\t[IPv6:2a00:1450:4864:20::231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CCBE761568\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  6 Jul 2019 13:45:53 +0200 (CEST)","by mail-lj1-x231.google.com with SMTP id i21so11587512ljj.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 06 Jul 2019 04:45:53 -0700 (PDT)","from localhost (customer-145-14-112-32.stosn.net. [145.14.112.32])\n\tby smtp.gmail.com with ESMTPSA id\n\tp13sm2350041ljc.39.2019.07.06.04.45.52\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tSat, 06 Jul 2019 04:45:52 -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=/04zHAjjChSImaUPl/IluCV9N7Qyx4aCcwvMxGvTz20=;\n\tb=uHM4+7hD1AJy3XUtjwXlVjGTt0KNmij2nxWe4AAEIZU4+LP5Il2B3NgunuBWGXTU0P\n\teuzi2Zhgk1wde5xKHsbtRbMaVv8sKnidCdpkuqiccNcQ1QFEBlGItujHCcxKCsOkOeWO\n\tV9sfnSpSanvFv4ovPdwigWfrkeSkrzC85h5G6MIzCVmIfDaKUBnsfjKWq9VMomhtz2wT\n\tzqIHT37mOQB6OA89mzkZEG1zD+QIycFGo/R5hIjA9BpVtbHhb5wn/TVgt3D5u9cjJ3nw\n\tZfrZBIy6u2O43Ek67GkCgkZYxZOTFzFRuygXgSD7oV+eO/iaWwTWo/RJJKKSHV7X/dM3\n\tvjWQ==","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=/04zHAjjChSImaUPl/IluCV9N7Qyx4aCcwvMxGvTz20=;\n\tb=YiilT8M29qvI0LfRptjqy111LclYwwRGbsOYNluev57dATaAXAdTH1DNXO23+u+tPv\n\tTP3U2Gdwa/oBd1eXz2zUeoIggNB8NRrX4xKFpWehPQdOK6Wc0zbauCShaulNxgLwAEBX\n\tuOAQK1WQFuxreWsyeKS44m3RlzESljs9wyyXsmdn3c30pHcAkegpCpnbyJebpMS53Yrl\n\tagrKFabuourfjGsBX5BXK4/HqIimKex7FOFhfb8Vx8NG0HBwkFsr53QtKl/ZaCqcjdL1\n\t6iu/YBYeIK8ujXUsmdVwsJBepJ16fpjf9+kRkmjPmbL6KAcZDy0kBVHOcnoC4gP6lsv8\n\tiVRA==","X-Gm-Message-State":"APjAAAXxsbe6x3dI6yvIUZdoROGsZP+Gd0o3KZC+zW5J23d0X5aQmHVA\n\tAwFbgxwvhRuoG8RA10mIeqBKdzi4leM=","X-Google-Smtp-Source":"APXvYqxsHPiqc1U9Is66DlDlL12YabTQlKqTas/qWj3viXHqPheQUQOidoGbLDzcpVkj5RndnDog8A==","X-Received":"by 2002:a2e:a171:: with SMTP id\n\tu17mr4830360ljl.209.1562413553350; \n\tSat, 06 Jul 2019 04:45:53 -0700 (PDT)","Date":"Sat, 6 Jul 2019 13:45:52 +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":"<20190706114552.GM17685@bigcity.dyn.berto.se>","References":"<20190704225334.26170-1-jacopo@jmondi.org>\n\t<20190704225334.26170-4-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":"<20190704225334.26170-4-jacopo@jmondi.org>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH 3/9] libcamera: pipeline: Support\n\texternal buffers","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, 06 Jul 2019 11:45:54 -0000"}},{"id":2191,"web_url":"https://patchwork.libcamera.org/comment/2191/","msgid":"<e150de66-e6cb-9977-7f10-28966e1f7edc@ideasonboard.com>","date":"2019-07-08T10:55:32","subject":"Re: [libcamera-devel] [PATCH 3/9] libcamera: pipeline: Support\n\texternal buffers","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn 06/07/2019 12:45, Niklas Söderlund wrote:\n> Hi Jacopo,\n> \n> Thanks for your patch.\n> \n> On 2019-07-05 00:53:28 +0200, Jacopo Mondi wrote:\n>> Add support for use external buffers to libcamera pipeline handlers.\n>>\n>> Use the memory type flag in pipeline handlers (todo: change all pipeline\n>> handlers) during buffer setup operations, to decide if the Stream's\n>> internal memory has to be exported to applications, or the Stream\n>> should prepare to use buffers whose memory is allocated elsewhere.\n> \n> I think you can drop the TODO now as it seems all pipeline handlers are \n> now supprted, right?\n> \n>>\n>> To support the last use case, a translation mechanism between the external\n>> buffers provided by applications and internal ones used by pipeline\n>> handlers to feed the video device will be implemented on top of this\n>> change.\n>>\n>> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n>> ---\n>>  src/libcamera/pipeline/ipu3/ipu3.cpp     | 31 +++++++++++++++++++++++-\n>>  src/libcamera/pipeline/rkisp1/rkisp1.cpp |  9 ++++++-\n>>  src/libcamera/pipeline/uvcvideo.cpp      |  8 +++++-\n>>  src/libcamera/pipeline/vimc.cpp          |  8 +++++-\n>>  4 files changed, 52 insertions(+), 4 deletions(-)\n>>\n>> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> index 2de0892138a8..6f14da1f8c70 100644\n>> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> @@ -71,6 +71,7 @@ public:\n>>  \n>>  \tint importBuffers(BufferPool *pool);\n>>  \tint exportBuffers(ImgUOutput *output, BufferPool *pool);\n>> +\tint reserveDmabufBuffers(ImgUOutput *output, BufferPool *pool);\n>>  \tvoid freeBuffers();\n>>  \n>>  \tint start();\n>> @@ -624,7 +625,11 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\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 (stream->memoryType() == ExternalMemory)\n>> +\t\t\tret = imgu->reserveDmabufBuffers(dev,\n>> +\t\t\t\t\t\t\t &stream->bufferPool());\n> \n> I would s/reserveDmabufBuffers/importBuffers/ to match the logic in \n> other pipeline handlers.\n\n\nI concur.\n\nAnother option could be to move the common code between importing and\nexporting to a private function called something like\nsetupInternalBuffers(), then call that at the beginning of two functions\ncalled allocateBuffers() and importBuffers()?\n\nthen allocateBuffers() would still be named appropriately?\n\n\n\n\n> \n>> +\t\telse\n>> +\t\t\tret = imgu->exportBuffers(dev, &stream->bufferPool());\n>>  \t\tif (ret)\n>>  \t\t\tgoto error;\n>>  \t}\n>> @@ -1153,6 +1158,30 @@ int ImgUDevice::exportBuffers(ImgUOutput *output, BufferPool *pool)\n>>  \treturn 0;\n>>  }\n>>  \n>> +/**\n>> + * \\brief Reserve buffers in \\a output from the provided \\a pool\n>> + * \\param[in] output The ImgU output device\n>> + * \\param[in] pool The buffer pool used to reserve buffers in \\a output\n>> + *\n>> + * Reserve a number of buffers equal to the number of buffers in \\a pool\n>> + * in the \\a output device to prepare for streaming operations using buffers\n>> + * whose memory has been reserved elsewhere identified with DMABUF file\n>> + * descriptors.\n>> + *\n>> + * \\return 0 on success or a negative error code otherwise\n>> + */\n>> +int ImgUDevice::reserveDmabufBuffers(ImgUOutput *output, BufferPool *pool)\n>> +{\n>> +\tint ret = output->dev->importBuffers(pool);\n>> +\tif (ret) {\n>> +\t\tLOG(IPU3, Error) << \"Failed to import buffer in \"\n>> +\t\t\t\t << output->name << \" ImgU device\";\n>> +\t\treturn ret;\n>> +\t}\n>> +\n>> +\treturn 0;\n>> +}\n>> +\n>>  /**\n>>   * \\brief Release buffers for all the ImgU video devices\n>>   */\n>> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n>> index 4a5898d25f91..dbb61a21354d 100644\n>> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n>> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n>> @@ -319,7 +319,14 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera,\n>>  \t\t\t\t\t   const std::set<Stream *> &streams)\n>>  {\n>>  \tStream *stream = *streams.begin();\n>> -\treturn video_->exportBuffers(&stream->bufferPool());\n>> +\tint ret;\n>> +\n>> +\tif (stream->memoryType() == InternalMemory)\n>> +\t\tret = video_->exportBuffers(&stream->bufferPool());\n>> +\telse\n>> +\t\tret = video_->importBuffers(&stream->bufferPool());\n>> +\n>> +\treturn ret;\n>>  }\n>>  \n>>  int PipelineHandlerRkISP1::freeBuffers(Camera *camera,\n>> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n>> index 72313cfd246f..5b3c79dda6dd 100644\n>> --- a/src/libcamera/pipeline/uvcvideo.cpp\n>> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n>> @@ -197,10 +197,16 @@ int PipelineHandlerUVC::allocateBuffers(Camera *camera,\n>>  \tUVCCameraData *data = cameraData(camera);\n>>  \tStream *stream = *streams.begin();\n>>  \tconst StreamConfiguration &cfg = stream->configuration();\n>> +\tint ret;\n>>  \n>>  \tLOG(UVC, Debug) << \"Requesting \" << cfg.bufferCount << \" buffers\";\n>>  \n>> -\treturn data->video_->exportBuffers(&stream->bufferPool());\n>> +\tif (stream->memoryType() == InternalMemory)\n>> +\t\tret = data->video_->exportBuffers(&stream->bufferPool());\n>> +\telse\n>> +\t\tret = data->video_->importBuffers(&stream->bufferPool());\n>> +\n>> +\treturn ret;\n>>  }\n>>  \n>>  int PipelineHandlerUVC::freeBuffers(Camera *camera,\n>> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n>> index f8a58be060bb..c67bdb0ecbff 100644\n>> --- a/src/libcamera/pipeline/vimc.cpp\n>> +++ b/src/libcamera/pipeline/vimc.cpp\n>> @@ -199,10 +199,16 @@ int PipelineHandlerVimc::allocateBuffers(Camera *camera,\n>>  \tVimcCameraData *data = cameraData(camera);\n>>  \tStream *stream = *streams.begin();\n>>  \tconst StreamConfiguration &cfg = stream->configuration();\n>> +\tint ret;\n>>  \n>>  \tLOG(VIMC, Debug) << \"Requesting \" << cfg.bufferCount << \" buffers\";\n>>  \n>> -\treturn data->video_->exportBuffers(&stream->bufferPool());\n>> +\tif (stream->memoryType() == InternalMemory)\n>> +\t\tret = data->video_->exportBuffers(&stream->bufferPool());\n>> +\telse\n>> +\t\tret = data->video_->importBuffers(&stream->bufferPool());\n>> +\n>> +\treturn ret;\n>>  }\n>>  \n>>  int PipelineHandlerVimc::freeBuffers(Camera *camera,\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\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 00EE860C1C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Jul 2019 12:55:35 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4CA8556A;\n\tMon,  8 Jul 2019 12:55:35 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562583335;\n\tbh=XhwLu0k7BopF8zblZwOo5pncnINHkDyFsLsCxxM49V8=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=v++tAkjKa5NkFWdfHfy4Cl7bgj+wpnzONzMuSE9B1QoZYEn6c+q5Rpn2hBbpCwuup\n\tAshzz0CnOpqTIl68IqWk8pSTKgz3Lap+DwJTP1ZuCSn1xYWC4ETPlrZWujd6N+LIPN\n\tdPjxzNAaWxYrk5EXZvXCvARIuYY2NNpJ3W8v4P4Q=","Reply-To":"kieran.bingham@ideasonboard.com","To":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>,\n\tJacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","References":"<20190704225334.26170-1-jacopo@jmondi.org>\n\t<20190704225334.26170-4-jacopo@jmondi.org>\n\t<20190706114552.GM17685@bigcity.dyn.berto.se>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqD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DkT4qMA+4q1y/dWwshSKi/uwVZNycuLsz+\n\t+OD8xPNCsMTqeUkAKfbD8xW4LCay3r/dD2ckoxRxtMD9eOAyu5wYzo/ydIPTh1QEj9SYyvp8\n\tO0g6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU\n\tRCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA\n\tJxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<e150de66-e6cb-9977-7f10-28966e1f7edc@ideasonboard.com>","Date":"Mon, 8 Jul 2019 11:55:32 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.7.1","MIME-Version":"1.0","In-Reply-To":"<20190706114552.GM17685@bigcity.dyn.berto.se>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 3/9] libcamera: pipeline: Support\n\texternal buffers","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, 08 Jul 2019 10:55:36 -0000"}},{"id":2200,"web_url":"https://patchwork.libcamera.org/comment/2200/","msgid":"<20190710093805.jxlzmku4pprgnjbd@uno.localdomain>","date":"2019-07-10T09:38:05","subject":"Re: [libcamera-devel] [PATCH 3/9] libcamera: pipeline: Support\n\texternal buffers","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Sat, Jul 06, 2019 at 01:45:52PM +0200, Niklas Söderlund wrote:\n> Hi Jacopo,\n>\n> Thanks for your patch.\n>\n> On 2019-07-05 00:53:28 +0200, Jacopo Mondi wrote:\n> > Add support for use external buffers to libcamera pipeline handlers.\n> >\n> > Use the memory type flag in pipeline handlers (todo: change all pipeline\n> > handlers) during buffer setup operations, to decide if the Stream's\n> > internal memory has to be exported to applications, or the Stream\n> > should prepare to use buffers whose memory is allocated elsewhere.\n>\n> I think you can drop the TODO now as it seems all pipeline handlers are\n> now supprted, right?\n>\n> >\n> > To support the last use case, a translation mechanism between the external\n> > buffers provided by applications and internal ones used by pipeline\n> > handlers to feed the video device will be implemented on top of this\n> > change.\n> >\n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > ---\n> >  src/libcamera/pipeline/ipu3/ipu3.cpp     | 31 +++++++++++++++++++++++-\n> >  src/libcamera/pipeline/rkisp1/rkisp1.cpp |  9 ++++++-\n> >  src/libcamera/pipeline/uvcvideo.cpp      |  8 +++++-\n> >  src/libcamera/pipeline/vimc.cpp          |  8 +++++-\n> >  4 files changed, 52 insertions(+), 4 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> > index 2de0892138a8..6f14da1f8c70 100644\n> > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> > @@ -71,6 +71,7 @@ public:\n> >\n> >  \tint importBuffers(BufferPool *pool);\n> >  \tint exportBuffers(ImgUOutput *output, BufferPool *pool);\n> > +\tint reserveDmabufBuffers(ImgUOutput *output, BufferPool *pool);\n> >  \tvoid freeBuffers();\n> >\n> >  \tint start();\n> > @@ -624,7 +625,11 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\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 (stream->memoryType() == ExternalMemory)\n> > +\t\t\tret = imgu->reserveDmabufBuffers(dev,\n> > +\t\t\t\t\t\t\t &stream->bufferPool());\n>\n> I would s/reserveDmabufBuffers/importBuffers/ to match the logic in\n> other pipeline handlers.\n>\n\nIf not that ImgU::importBuffers() already exists, and import CIO2\nbuffers into the ImgU input.\n\nBut yes, reserveDmabufBuffers is incredibl ugly, but I wanted to\nconvey the idea that 'import' actually just reserve buffers in the\nvideo device.\n\nSo I've now renamed importBuffers() in importInputBuffers() and made\nthis new one importOutputBuffers().\n\nThanks\n   j\n\n> > +\t\telse\n> > +\t\t\tret = imgu->exportBuffers(dev, &stream->bufferPool());\n> >  \t\tif (ret)\n> >  \t\t\tgoto error;\n> >  \t}\n> > @@ -1153,6 +1158,30 @@ int ImgUDevice::exportBuffers(ImgUOutput *output, BufferPool *pool)\n> >  \treturn 0;\n> >  }\n> >\n> > +/**\n> > + * \\brief Reserve buffers in \\a output from the provided \\a pool\n> > + * \\param[in] output The ImgU output device\n> > + * \\param[in] pool The buffer pool used to reserve buffers in \\a output\n> > + *\n> > + * Reserve a number of buffers equal to the number of buffers in \\a pool\n> > + * in the \\a output device to prepare for streaming operations using buffers\n> > + * whose memory has been reserved elsewhere identified with DMABUF file\n> > + * descriptors.\n> > + *\n> > + * \\return 0 on success or a negative error code otherwise\n> > + */\n> > +int ImgUDevice::reserveDmabufBuffers(ImgUOutput *output, BufferPool *pool)\n> > +{\n> > +\tint ret = output->dev->importBuffers(pool);\n> > +\tif (ret) {\n> > +\t\tLOG(IPU3, Error) << \"Failed to import buffer in \"\n> > +\t\t\t\t << output->name << \" ImgU device\";\n> > +\t\treturn ret;\n> > +\t}\n> > +\n> > +\treturn 0;\n> > +}\n> > +\n> >  /**\n> >   * \\brief Release buffers for all the ImgU video devices\n> >   */\n> > diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > index 4a5898d25f91..dbb61a21354d 100644\n> > --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > @@ -319,7 +319,14 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera,\n> >  \t\t\t\t\t   const std::set<Stream *> &streams)\n> >  {\n> >  \tStream *stream = *streams.begin();\n> > -\treturn video_->exportBuffers(&stream->bufferPool());\n> > +\tint ret;\n> > +\n> > +\tif (stream->memoryType() == InternalMemory)\n> > +\t\tret = video_->exportBuffers(&stream->bufferPool());\n> > +\telse\n> > +\t\tret = video_->importBuffers(&stream->bufferPool());\n> > +\n> > +\treturn ret;\n> >  }\n> >\n> >  int PipelineHandlerRkISP1::freeBuffers(Camera *camera,\n> > diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> > index 72313cfd246f..5b3c79dda6dd 100644\n> > --- a/src/libcamera/pipeline/uvcvideo.cpp\n> > +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> > @@ -197,10 +197,16 @@ int PipelineHandlerUVC::allocateBuffers(Camera *camera,\n> >  \tUVCCameraData *data = cameraData(camera);\n> >  \tStream *stream = *streams.begin();\n> >  \tconst StreamConfiguration &cfg = stream->configuration();\n> > +\tint ret;\n> >\n> >  \tLOG(UVC, Debug) << \"Requesting \" << cfg.bufferCount << \" buffers\";\n> >\n> > -\treturn data->video_->exportBuffers(&stream->bufferPool());\n> > +\tif (stream->memoryType() == InternalMemory)\n> > +\t\tret = data->video_->exportBuffers(&stream->bufferPool());\n> > +\telse\n> > +\t\tret = data->video_->importBuffers(&stream->bufferPool());\n> > +\n> > +\treturn ret;\n> >  }\n> >\n> >  int PipelineHandlerUVC::freeBuffers(Camera *camera,\n> > diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> > index f8a58be060bb..c67bdb0ecbff 100644\n> > --- a/src/libcamera/pipeline/vimc.cpp\n> > +++ b/src/libcamera/pipeline/vimc.cpp\n> > @@ -199,10 +199,16 @@ int PipelineHandlerVimc::allocateBuffers(Camera *camera,\n> >  \tVimcCameraData *data = cameraData(camera);\n> >  \tStream *stream = *streams.begin();\n> >  \tconst StreamConfiguration &cfg = stream->configuration();\n> > +\tint ret;\n> >\n> >  \tLOG(VIMC, Debug) << \"Requesting \" << cfg.bufferCount << \" buffers\";\n> >\n> > -\treturn data->video_->exportBuffers(&stream->bufferPool());\n> > +\tif (stream->memoryType() == InternalMemory)\n> > +\t\tret = data->video_->exportBuffers(&stream->bufferPool());\n> > +\telse\n> > +\t\tret = data->video_->importBuffers(&stream->bufferPool());\n> > +\n> > +\treturn ret;\n> >  }\n> >\n> >  int PipelineHandlerVimc::freeBuffers(Camera *camera,\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\n>\n> --\n> Regards,\n> Niklas Söderlund","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C0F3360C3A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Jul 2019 11:36:52 +0200 (CEST)","from uno.localdomain (softbank126163157105.bbtec.net\n\t[126.163.157.105]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 13613E0005;\n\tWed, 10 Jul 2019 09:36:50 +0000 (UTC)"],"X-Originating-IP":"126.163.157.105","Date":"Wed, 10 Jul 2019 11:38:05 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190710093805.jxlzmku4pprgnjbd@uno.localdomain>","References":"<20190704225334.26170-1-jacopo@jmondi.org>\n\t<20190704225334.26170-4-jacopo@jmondi.org>\n\t<20190706114552.GM17685@bigcity.dyn.berto.se>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"rl4wzncdoxwqw2n5\"","Content-Disposition":"inline","In-Reply-To":"<20190706114552.GM17685@bigcity.dyn.berto.se>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 3/9] libcamera: pipeline: Support\n\texternal buffers","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, 10 Jul 2019 09:36:52 -0000"}}]