[{"id":31392,"web_url":"https://patchwork.libcamera.org/comment/31392/","msgid":"<hrcza4e42yv4sm3paurxe4gfa2nczd3umlkg2rdc2xxrhxrzzb@bn2t5zmz6voz>","date":"2024-09-26T10:26:05","subject":"Re: [PATCH v12 1/7] 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 Harvey\n\nOn Tue, Sep 10, 2024 at 04:40:14AM GMT, Harvey Yang wrote:\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> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n> ---\n>  .../libcamera/internal/dma_buf_allocator.h    | 13 +++++\n>  src/libcamera/dma_buf_allocator.cpp           | 58 +++++++++++++++++++\n>  2 files changed, 71 insertions(+)\n>\n> diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\n> index d2a0a0d1..66d3b419 100644\n> --- a/include/libcamera/internal/dma_buf_allocator.h\n> +++ b/include/libcamera/internal/dma_buf_allocator.h\n> @@ -7,11 +7,17 @@\n>\n>  #pragma once\n>\n> +#include <memory>\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> @@ -28,7 +34,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 be6efb89..a49d1c60 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,58 @@ 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> + * Planes in a FrameBuffer are allocated with a single dma buf.\n> + * \\todo Add the option to allocate each plane with a dma buf respectively.\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.598.g6f2099f65c-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 47AF4C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 10:26:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 10AAE6350F;\n\tThu, 26 Sep 2024 12:26:10 +0200 (CEST)","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 9048B634F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 12:26:08 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6674F169;\n\tThu, 26 Sep 2024 12:24:40 +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=\"s6Wi3Ykc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727346280;\n\tbh=kFMuDmBJ9CiPofEbcFskffoSUHMcu5B6r0mztstUFS0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=s6Wi3YkcHzVNp81+3qmcLWvsZMD3x0VXeJnS6X9AwP+VqOTnSxX0YwY49GJ4oPcvE\n\tEUyK7ingEssrAluYJygN6PnSkBPsCKc9sMF44YdCvyzxt1TLzbXeZUlsvBvkc6DKSn\n\tyNNrX7X+zwoWsH8b1x6oKI3jcVIGpYW+chKS9ds4=","Date":"Thu, 26 Sep 2024 12:26:05 +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>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v12 1/7] libcamera: add DmaBufAllocator::exportBuffers()","Message-ID":"<hrcza4e42yv4sm3paurxe4gfa2nczd3umlkg2rdc2xxrhxrzzb@bn2t5zmz6voz>","References":"<20240910044834.2477701-1-chenghaoyang@google.com>\n\t<20240910044834.2477701-2-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240910044834.2477701-2-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>"}},{"id":31394,"web_url":"https://patchwork.libcamera.org/comment/31394/","msgid":"<y22zfb4gebvjp6vnuxvahyvaeg6gbob5ruwcfqpa6heq47eui3@jdtmz5bujgfk>","date":"2024-09-26T10:28:56","subject":"Re: [PATCH v12 1/7] libcamera: add DmaBufAllocator::exportBuffers()","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"One little nit\n\nOn Tue, Sep 10, 2024 at 04:40:14AM GMT, Harvey Yang wrote:\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> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  .../libcamera/internal/dma_buf_allocator.h    | 13 +++++\n>  src/libcamera/dma_buf_allocator.cpp           | 58 +++++++++++++++++++\n>  2 files changed, 71 insertions(+)\n>\n> diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\n> index d2a0a0d1..66d3b419 100644\n> --- a/include/libcamera/internal/dma_buf_allocator.h\n> +++ b/include/libcamera/internal/dma_buf_allocator.h\n> @@ -7,11 +7,17 @@\n>\n>  #pragma once\n>\n> +#include <memory>\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> @@ -28,7 +34,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 be6efb89..a49d1c60 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\nWhat is this used for ?\n\nYou need to include <libcamera/base/shared_fh.h> as well\n\nWith the above fixed/clarified you can retain my tag\n\n> +\n>  /**\n>   * \\file dma_buf_allocator.cpp\n>   * \\brief dma-buf allocator\n> @@ -205,4 +209,58 @@ 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> + * Planes in a FrameBuffer are allocated with a single dma buf.\n> + * \\todo Add the option to allocate each plane with a dma buf respectively.\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.598.g6f2099f65c-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 DABA8C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 10:29:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9415463511;\n\tThu, 26 Sep 2024 12:29:00 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A500A63502\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 12:28:59 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 684D2169;\n\tThu, 26 Sep 2024 12:27:31 +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=\"UvvbCvRE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727346451;\n\tbh=NNvuYTadS4QmV0Tm9+pq1elTMlsM8DeWLfHnYmJvcNw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=UvvbCvREeeVN+9WGU+kpUUTB8mLVRbKC1//G6QXedMxn7q2pBJYF5SHGPS/+G5bcC\n\tL5LdbOyv6v5wdD+9AEjrdGPZsP5SME716u/V0zBdReSsTFuOySdxaDO1aUdGSqGwzj\n\t6NPMSEQO1mEBtPU8rhLhXHRuE4gathrdXj4kJ2Z0=","Date":"Thu, 26 Sep 2024 12:28:56 +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>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v12 1/7] libcamera: add DmaBufAllocator::exportBuffers()","Message-ID":"<y22zfb4gebvjp6vnuxvahyvaeg6gbob5ruwcfqpa6heq47eui3@jdtmz5bujgfk>","References":"<20240910044834.2477701-1-chenghaoyang@google.com>\n\t<20240910044834.2477701-2-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240910044834.2477701-2-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>"}},{"id":31413,"web_url":"https://patchwork.libcamera.org/comment/31413/","msgid":"<CAC=wSGWGJvOpWKezT7W_9_Od0XQ3L5v=UXsi=sw_ZxVyifqZew@mail.gmail.com>","date":"2024-09-26T16:32:03","subject":"Re: [PATCH v12 1/7] libcamera: add DmaBufAllocator::exportBuffers()","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Thanks Jacopo,\n\nOn Thu, Sep 26, 2024 at 6:29 PM Jacopo Mondi\n<jacopo.mondi@ideasonboard.com> wrote:\n>\n> One little nit\n>\n> On Tue, Sep 10, 2024 at 04:40:14AM GMT, Harvey Yang wrote:\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> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >  .../libcamera/internal/dma_buf_allocator.h    | 13 +++++\n> >  src/libcamera/dma_buf_allocator.cpp           | 58 +++++++++++++++++++\n> >  2 files changed, 71 insertions(+)\n> >\n> > diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\n> > index d2a0a0d1..66d3b419 100644\n> > --- a/include/libcamera/internal/dma_buf_allocator.h\n> > +++ b/include/libcamera/internal/dma_buf_allocator.h\n> > @@ -7,11 +7,17 @@\n> >\n> >  #pragma once\n> >\n> > +#include <memory>\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> > @@ -28,7 +34,14 @@ public:\n> >       bool isValid() const { return providerHandle_.isValid(); }\n> >       UniqueFD alloc(const char *name, std::size_t size);\n> >\n> > +     int exportBuffers(unsigned int count,\n> > +                       const std::vector<unsigned int> &frameSize,\n> > +                       std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n> > +\n> >  private:\n> > +     std::unique_ptr<FrameBuffer> createBuffer(\n> > +             std::string name, const std::vector<unsigned int> &frameSizes);\n> > +\n> >       UniqueFD allocFromHeap(const char *name, std::size_t size);\n> >       UniqueFD allocFromUDmaBuf(const char *name, std::size_t size);\n> >       UniqueFD providerHandle_;\n> > diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp\n> > index be6efb89..a49d1c60 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> What is this used for ?\n>\n> You need to include <libcamera/base/shared_fh.h> as well\n>\n> With the above fixed/clarified you can retain my tag\n\nBoth done.\n\n\n>\n> > +\n> >  /**\n> >   * \\file dma_buf_allocator.cpp\n> >   * \\brief dma-buf allocator\n> > @@ -205,4 +209,58 @@ UniqueFD DmaBufAllocator::alloc(const char *name, std::size_t size)\n> >               return 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> > + * Planes in a FrameBuffer are allocated with a single dma buf.\n> > + * \\todo Add the option to allocate each plane with a dma buf respectively.\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> > +                                const std::vector<unsigned int> &frameSizes,\n> > +                                std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n> > +{\n> > +     for (unsigned int i = 0; i < count; ++i) {\n> > +             std::unique_ptr<FrameBuffer> buffer =\n> > +                     createBuffer(\"frame-\" + std::to_string(i), frameSizes);\n> > +             if (!buffer) {\n> > +                     LOG(DmaBufAllocator, Error) << \"Unable to create buffer\";\n> > +\n> > +                     buffers->clear();\n> > +                     return -EINVAL;\n> > +             }\n> > +\n> > +             buffers->push_back(std::move(buffer));\n> > +     }\n> > +\n> > +     return count;\n> > +}\n> > +\n> > +std::unique_ptr<FrameBuffer>\n> > +DmaBufAllocator::createBuffer(std::string name,\n> > +                           const std::vector<unsigned int> &frameSizes)\n> > +{\n> > +     std::vector<FrameBuffer::Plane> planes;\n> > +\n> > +     unsigned int bufferSize = 0, offset = 0;\n> > +     for (auto frameSize : frameSizes)\n> > +             bufferSize += frameSize;\n> > +\n> > +     SharedFD fd(alloc(name.c_str(), bufferSize));\n> > +     if (!fd.isValid())\n> > +             return nullptr;\n> > +\n> > +     for (auto frameSize : frameSizes) {\n> > +             planes.emplace_back(FrameBuffer::Plane{ fd, offset, frameSize });\n> > +             offset += frameSize;\n> > +     }\n> > +\n> > +     return std::make_unique<FrameBuffer>(planes);\n> > +}\n> > +\n> >  } /* namespace libcamera */\n> > --\n> > 2.46.0.598.g6f2099f65c-goog\n> >\n\n\n\n--\nBR,\nHarvey Yang","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 24215C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 16:32:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CADAC6350F;\n\tThu, 26 Sep 2024 18:32:42 +0200 (CEST)","from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com\n\t[IPv6:2a00:1450:4864:20::12f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 65893634F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 18:32:41 +0200 (CEST)","by mail-lf1-x12f.google.com with SMTP id\n\t2adb3069b0e04-536552fcc07so18774e87.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 09:32:41 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"njl0DFlM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727368361; x=1727973161;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=qTqtzoeDo9M/8tcEOkV88HrOhS0Gw/R7kstzzOdd4nY=;\n\tb=njl0DFlMnrGYEdvMk6YxsO+7B7w6x7g3VJ4iDwg4jA9LHkl3KzdkamH2v0FXiAaPZT\n\tNHJzuB+FNl0LANtPp+eU1RPW6XlxvwnX0dAZ5aEB8y8q+7EaNqgxeRCPa6TT6M1VlucO\n\thfouVCYwSQ4gJgsBdPZ02Q8FjVja62NrhDIxrNlSYhN3mKOt13F4pEMce84WEoVFfvTD\n\tDpnNOGXbgWQPE2UVQRLrzRH9UsdBasF2FipT0Bkms2MP3sLHgJzdXu4aNuRjTINeQ8mI\n\tz7b2CRjY2kuV901go6Lf0YZUNtCaWHih9fYhELSXQnhbEtzfg3wwz7o/S46WIZXNebnH\n\toZPA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727368361; x=1727973161;\n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=qTqtzoeDo9M/8tcEOkV88HrOhS0Gw/R7kstzzOdd4nY=;\n\tb=SWgYMmUZN6gdPOz24ADsrR15wum0cKbuYOa4gT0SgNKBwd2LgFXf2AKhhXI2AT3wQh\n\takt9ZFzovn7da+NshEQ7WSxxRfFfxOtkGqqUwULKBwQhVhE2mD5hxvw2uADyrlJIOvpa\n\tW6rJIXEk5YAY7aGzM2V7MAVOMNDgZV5EdSU70p+g0usjLXe+0lyd/brbemloiJYXmhHo\n\taisvXq9qWZnzYUpjiW20WxhQrCUFyIZ4/lcXfM/uHcUcnzXkc9TaQ3WsZknmCse+W4p1\n\trn5qteAtbUYWXHRWVOT+khUMzJSenbUWKnxr2xlR1hziB3lNSQbXiwp1IfoiPhIYDjwe\n\tIL6g==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCXlcDit+zX0abMP4ZF8+6DHziR3ZSaacUSskB0LIbUrnoE3hoH6aqrr54ppNj5815Y7bKlqc5gx6gQYpeY2EYc=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YzSjFkEhC1YRd1ZN64HE2n7oAOD2G4eKEepW66GwXVn7BAlClEd\n\tL+EKYVJ6tAIrXlEhYRXHBP0qaQJPDV79KvzCWnHDptmx8WX8OeKk2nrgxZLxcRKfq4xLaQki63f\n\tJ4it/QuFTQG3234ZaN2JNxlFX7ia5bH4uziHU","X-Google-Smtp-Source":"AGHT+IHL9sMXzvKQ/j+3zMDxTHA8akMnIU42kd++XYCTOCZHhfHbquoolYxhrgz3c0DVoJ2bp0j1pWxTX4OgkfSEtpE=","X-Received":"by 2002:a05:6512:3baa:b0:52c:dd94:73f3 with SMTP id\n\t2adb3069b0e04-53898617862mr297947e87.3.1727368360326; Thu, 26 Sep 2024\n\t09:32:40 -0700 (PDT)","MIME-Version":"1.0","References":"<20240910044834.2477701-1-chenghaoyang@google.com>\n\t<20240910044834.2477701-2-chenghaoyang@google.com>\n\t<y22zfb4gebvjp6vnuxvahyvaeg6gbob5ruwcfqpa6heq47eui3@jdtmz5bujgfk>","In-Reply-To":"<y22zfb4gebvjp6vnuxvahyvaeg6gbob5ruwcfqpa6heq47eui3@jdtmz5bujgfk>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Fri, 27 Sep 2024 00:32:03 +0800","Message-ID":"<CAC=wSGWGJvOpWKezT7W_9_Od0XQ3L5v=UXsi=sw_ZxVyifqZew@mail.gmail.com>","Subject":"Re: [PATCH v12 1/7] libcamera: add DmaBufAllocator::exportBuffers()","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Harvey Yang <chenghaoyang@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org, \n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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>"}}]