[{"id":30937,"web_url":"https://patchwork.libcamera.org/comment/30937/","msgid":"<kdcnrnq5btbt5ksdqe25ed5xdbgwp3p7ju6s5sp2fqx7wnxiqc@dvsppflq2qlr>","date":"2024-08-28T08:17:51","subject":"Re: [PATCH v9.1 1/8] libcamera: add DmaBufAllocator::exportBuffers()","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi\n\n if you really want to send vX.y updates (which I would only suggest\nfor smaller updates when a series is very close to be collected) you\nhave to reply to the original patch using the --in-reply-to= option of\ngit-send-email. Please don't send updates like this as a standlone\nseries otherwise collecting and appling them gets hard for reviewers.\n\nNot a big deal, I guess you'll need a new version of the series anyway.\n\nThanks\n  j\n\nOn Tue, Aug 27, 2024 at 03:33:38PM GMT, Harvey Yang wrote:\n\n> Add a helper function exportBuffers in DmaBufAllocator to make it easier\n> to use.\n>\n> It'll be used in Virtual Pipeline Handler and SoftwareIsp.\n>\n> Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> ---\n>  .../libcamera/internal/dma_buf_allocator.h    | 12 ++++\n>  src/libcamera/dma_buf_allocator.cpp           | 55 +++++++++++++++++++\n>  2 files changed, 67 insertions(+)\n>\n> diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\n> index 36ec1696b..49122ed95 100644\n> --- a/include/libcamera/internal/dma_buf_allocator.h\n> +++ b/include/libcamera/internal/dma_buf_allocator.h\n> @@ -7,13 +7,18 @@\n>\n>  #pragma once\n>\n> +#include <memory>\n>  #include <stddef.h>\n> +#include <string>\n> +#include <vector>\n>\n>  #include <libcamera/base/flags.h>\n>  #include <libcamera/base/unique_fd.h>\n>\n>  namespace libcamera {\n>\n> +class FrameBuffer;\n> +\n>  class DmaBufAllocator\n>  {\n>  public:\n> @@ -30,7 +35,14 @@ public:\n>  \tbool isValid() const { return providerHandle_.isValid(); }\n>  \tUniqueFD alloc(const char *name, std::size_t size);\n>\n> +\tint exportBuffers(unsigned int count,\n> +\t\t\t  const std::vector<unsigned int> &frameSize,\n> +\t\t\t  std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n> +\n>  private:\n> +\tstd::unique_ptr<FrameBuffer> createBuffer(\n> +\t\tstd::string name, const std::vector<unsigned int> &frameSizes);\n> +\n>  \tUniqueFD allocFromHeap(const char *name, std::size_t size);\n>  \tUniqueFD allocFromUDmaBuf(const char *name, std::size_t size);\n>  \tUniqueFD providerHandle_;\n> diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp\n> index be6efb89f..d2ac175f0 100644\n> --- a/src/libcamera/dma_buf_allocator.cpp\n> +++ b/src/libcamera/dma_buf_allocator.cpp\n> @@ -23,6 +23,10 @@\n>  #include <libcamera/base/log.h>\n>  #include <libcamera/base/memfd.h>\n>\n> +#include <libcamera/framebuffer.h>\n> +\n> +#include \"libcamera/internal/formats.h\"\n> +\n>  /**\n>   * \\file dma_buf_allocator.cpp\n>   * \\brief dma-buf allocator\n> @@ -205,4 +209,55 @@ UniqueFD DmaBufAllocator::alloc(const char *name, std::size_t size)\n>  \t\treturn allocFromHeap(name, size);\n>  }\n>\n> +/**\n> + * \\brief Allocate and export buffers from the DmaBufAllocator\n> + * \\param[in] count The number of requested FrameBuffers\n> + * \\param[in] frameSizes The sizes of planes in each FrameBuffer\n> + * \\param[out] buffers Array of buffers successfully allocated\n> + *\n> + * \\return The number of allocated buffers on success or a negative error code\n> + * otherwise\n> + */\n> +int DmaBufAllocator::exportBuffers(unsigned int count,\n> +\t\t\t\t   const std::vector<unsigned int> &frameSizes,\n> +\t\t\t\t   std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n> +{\n> +\tfor (unsigned int i = 0; i < count; ++i) {\n> +\t\tstd::unique_ptr<FrameBuffer> buffer =\n> +\t\t\tcreateBuffer(\"frame-\" + std::to_string(i), frameSizes);\n> +\t\tif (!buffer) {\n> +\t\t\tLOG(DmaBufAllocator, Error) << \"Unable to create buffer\";\n> +\n> +\t\t\tbuffers->clear();\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\n> +\t\tbuffers->push_back(std::move(buffer));\n> +\t}\n> +\n> +\treturn count;\n> +}\n> +\n> +std::unique_ptr<FrameBuffer>\n> +DmaBufAllocator::createBuffer(std::string name,\n> +\t\t\t      const std::vector<unsigned int> &frameSizes)\n> +{\n> +\tstd::vector<FrameBuffer::Plane> planes;\n> +\n> +\tunsigned int bufferSize = 0, offset = 0;\n> +\tfor (auto frameSize : frameSizes)\n> +\t\tbufferSize += frameSize;\n> +\n> +\tSharedFD fd(alloc(name.c_str(), bufferSize));\n> +\tif (!fd.isValid())\n> +\t\treturn nullptr;\n> +\n> +\tfor (auto frameSize : frameSizes) {\n> +\t\tplanes.emplace_back(FrameBuffer::Plane{ fd, offset, frameSize });\n> +\t\toffset += frameSize;\n> +\t}\n> +\n> +\treturn std::make_unique<FrameBuffer>(planes);\n> +}\n> +\n>  } /* namespace libcamera */\n> --\n> 2.46.0.295.g3b9ea8a38a-goog\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0BA23C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Aug 2024 08:17:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AB35B63460;\n\tWed, 28 Aug 2024 10:17:57 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 951A161903\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Aug 2024 10:17:55 +0200 (CEST)","from ideasonboard.com (mob-5-90-141-165.net.vodafone.it\n\t[5.90.141.165])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BE008220;\n\tWed, 28 Aug 2024 10:16:47 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"AAZbfwQf\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1724833007;\n\tbh=0ka2Z+JY2f5R3HLEndVFwOXoUHlWzFOpVGYONiJxZtM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=AAZbfwQfPR+rCo1zVqfR6TqQlMfiOZxa9EX3bwMwiUyZQBCWYgKnorThO59vVeDbC\n\tBHsV+foIakHOV+iv8aSHHAhYFxgUsNxM1lu1WXrNTwes8Tp2FzZqIqTwT3Ei5ujbFD\n\tjY7TdW85hKbUYOsCFnXzIShvPiNLi2JvlBLrPDJk=","Date":"Wed, 28 Aug 2024 10:17:51 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Harvey Yang <chenghaoyang@chromium.org>","Cc":"libcamera-devel@lists.libcamera.org,\n\tHarvey Yang <chenghaoyang@google.com>","Subject":"Re: [PATCH v9.1 1/8] libcamera: add DmaBufAllocator::exportBuffers()","Message-ID":"<kdcnrnq5btbt5ksdqe25ed5xdbgwp3p7ju6s5sp2fqx7wnxiqc@dvsppflq2qlr>","References":"<20240827153349.2893413-1-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240827153349.2893413-1-chenghaoyang@google.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]