[{"id":27108,"web_url":"https://patchwork.libcamera.org/comment/27108/","msgid":"<20230516103213.5hlrg3e2tdrxbzhe@lati>","date":"2023-05-16T10:32:13","subject":"Re: [libcamera-devel] [PATCH v5 3/3] libcamera: Add\n\texportFrameBuffers in HeapAllocator","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, May 16, 2023 at 08:03:19AM +0000, Harvey Yang via libcamera-devel wrote:\n> From: Cheng-Hao Yang <chenghaoyang@chromium.org>\n>\n> Add a helper function exportFrameBuffers in HeapAllocator to make it\n> easier to use.\n>\n> Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> ---\n>  include/libcamera/internal/heap_allocator.h |  9 +++\n>  src/libcamera/heap_allocator.cpp            | 61 +++++++++++++++++++++\n>  2 files changed, 70 insertions(+)\n>\n> diff --git a/include/libcamera/internal/heap_allocator.h b/include/libcamera/internal/heap_allocator.h\n> index d061fdce..b6488fbc 100644\n> --- a/include/libcamera/internal/heap_allocator.h\n> +++ b/include/libcamera/internal/heap_allocator.h\n> @@ -8,12 +8,16 @@\n>  #pragma once\n>\n>  #include <stddef.h>\n> +#include <vector>\n>\n>  #include <libcamera/base/unique_fd.h>\n>\n>  namespace libcamera {\n>\n> +class Camera;\n> +class FrameBuffer;\n>  class Heap;\n> +class Stream;\n>\n>  class HeapAllocator\n>  {\n> @@ -23,7 +27,12 @@ public:\n>  \tbool isValid() const;\n>  \tUniqueFD alloc(const char *name, std::size_t size);\n>\n> +\tint exportFrameBuffers(Camera *camera, Stream *stream,\n> +\t\t\t       std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n> +\n>  private:\n> +\tstd::unique_ptr<FrameBuffer> createBuffer(Stream *stream);\n> +\n>  \tstd::unique_ptr<Heap> heap_;\n>  };\n>\n> diff --git a/src/libcamera/heap_allocator.cpp b/src/libcamera/heap_allocator.cpp\n> index 682a7e01..ce3a815d 100644\n> --- a/src/libcamera/heap_allocator.cpp\n> +++ b/src/libcamera/heap_allocator.cpp\n> @@ -21,6 +21,12 @@\n>\n>  #include <libcamera/base/log.h>\n>\n> +#include <libcamera/camera.h>\n> +#include <libcamera/framebuffer.h>\n> +#include <libcamera/stream.h>\n> +\n> +#include \"libcamera/internal/formats.h\"\n> +\n>  namespace libcamera {\n>\n>  /*\n> @@ -231,4 +237,59 @@ UniqueFD HeapAllocator::alloc(const char *name, std::size_t size)\n>  \treturn heap_->alloc(name, size);\n>  }\n>\n> +int HeapAllocator::exportFrameBuffers([[maybe_unused]] Camera *camera, Stream *stream,\n> +\t\t\t\t      std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n> +{\n> +\tunsigned int count = stream->configuration().bufferCount;\n> +\n> +\t/** \\todo Support multiplanar allocations */\n> +\n> +\tfor (unsigned i = 0; i < count; ++i) {\n> +\t\tstd::unique_ptr<FrameBuffer> buffer = createBuffer(stream);\n> +\t\tif (!buffer) {\n> +\t\t\tLOG(HeapAllocator, 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> HeapAllocator::createBuffer(Stream *stream)\n> +{\n> +\tstd::vector<FrameBuffer::Plane> planes;\n> +\n> +\tunsigned int frameSize = stream->configuration().frameSize;\n> +\tint pageSize = getpagesize();\n> +\t// Allocation size need to be a direct multiple of |pageSize|.\n\nno c++ style comments, please\n\n> +\tunsigned int numPage = (frameSize + pageSize - 1) / pageSize;\n> +\n> +\tUniqueFD fd = alloc(\"FrameBuffer\", numPage * pageSize);\n> +\tif (!fd.isValid())\n> +\t\treturn nullptr;\n> +\n\nAnd I would add here a comment as reported in the review of v4\n\nCan be fixed when applying\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n> +\tauto info = PixelFormatInfo::info(stream->configuration().pixelFormat);\n> +\tSharedFD shared_fd(std::move(fd));\n> +\tunsigned int offset = 0;\n> +\tfor (size_t i = 0; i < info.planes.size(); ++i) {\n> +\t\tunsigned int planeSize = info.planeSize(stream->configuration().size, i);\n> +\t\tif (planeSize == 0)\n> +\t\t\tcontinue;\n> +\n> +\t\tFrameBuffer::Plane plane;\n> +\t\tplane.fd = shared_fd;\n> +\t\tplane.offset = offset;\n> +\t\tplane.length = planeSize;\n> +\t\tplanes.push_back(std::move(plane));\n> +\n> +\t\toffset += planeSize;\n> +\t}\n> +\n> +\treturn std::make_unique<FrameBuffer>(planes);\n> +}\n> +\n>  } /* namespace libcamera */\n> --\n> 2.40.1.606.ga4b1b128d6-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 13956C3284\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 May 2023 10:32:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 717C16285F;\n\tTue, 16 May 2023 12:32:19 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 52167627D1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 May 2023 12:32:17 +0200 (CEST)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D22CF4DB;\n\tTue, 16 May 2023 12:32:05 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1684233139;\n\tbh=Ap9H2ZlzKmPvw/8dvnPiIaku/FHa9Di52Nknx8GFihM=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=Si3uZdr2UlZ9+7TUZUav3lvn0qLY4nUnFf8PhhF03zqPta1Gxd12ONSMejBQ8Eisd\n\tYK0/IJEeva0wt3QnHNqFftYqj1iTts83JwpIiVjsCuWw+qLeD4mGAy/3YScf4Lnsnj\n\tEwd2fWoN4uVxr5aTUvSz0Mrva6Qc0fSxsDiTc3K8KTWxEif1rgcd0Xtcb7PiZj2F66\n\tIaimZKGb1GmD+5Z6TeO3kCbDZ1g/Qa/N+pnsY6pPHCbtAMf72PJAkNbFeM5zRoaK1O\n\tp1Ga7WrR5OpQ1KrfNuPbBWCEs/1x44J/dKr4XUfClau6owYJkxHo8q+GIjM9anvf1K\n\t9LCF2KiI9pZMw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1684233126;\n\tbh=Ap9H2ZlzKmPvw/8dvnPiIaku/FHa9Di52Nknx8GFihM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=WB6msLfMm3sd5a97RlF8hLE6C9FsVnaP6OlL7zkteIpAwyz/efrJTs9a8TmrYWfLr\n\tzpY0yiKJmr0mVTgS/ImheNG1O0ImqUs4V7muMdvLq8osO1rHFkiBOOIfJU2mVGR0Jw\n\tLCpHD+8goTSC1oKRTMSsxYgvBq+qxJRxCUkVTzvY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"WB6msLfM\"; dkim-atps=neutral","Date":"Tue, 16 May 2023 12:32:13 +0200","To":"Harvey Yang <chenghaoyang@chromium.org>","Message-ID":"<20230516103213.5hlrg3e2tdrxbzhe@lati>","References":"<20230516080459.711347-1-chenghaoyang@google.com>\n\t<20230516080459.711347-4-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230516080459.711347-4-chenghaoyang@google.com>","Subject":"Re: [libcamera-devel] [PATCH v5 3/3] libcamera: Add\n\texportFrameBuffers in HeapAllocator","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27123,"web_url":"https://patchwork.libcamera.org/comment/27123/","msgid":"<CAEB1ahsqqrsA4_Mv6izHfjj1=fS=Dv3PDZFrsbAihN6eYBTiXw@mail.gmail.com>","date":"2023-05-22T08:36:32","subject":"Re: [libcamera-devel] [PATCH v5 3/3] libcamera: Add\n\texportFrameBuffers in HeapAllocator","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/people/117/","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"content":"Thanks Jacopo.\n\nOn Tue, May 16, 2023 at 6:32 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nwrote:\n\n> Hi Harvey\n>\n> On Tue, May 16, 2023 at 08:03:19AM +0000, Harvey Yang via libcamera-devel\n> wrote:\n> > From: Cheng-Hao Yang <chenghaoyang@chromium.org>\n> >\n> > Add a helper function exportFrameBuffers in HeapAllocator to make it\n> > easier to use.\n> >\n> > Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> > ---\n> >  include/libcamera/internal/heap_allocator.h |  9 +++\n> >  src/libcamera/heap_allocator.cpp            | 61 +++++++++++++++++++++\n> >  2 files changed, 70 insertions(+)\n> >\n> > diff --git a/include/libcamera/internal/heap_allocator.h\n> b/include/libcamera/internal/heap_allocator.h\n> > index d061fdce..b6488fbc 100644\n> > --- a/include/libcamera/internal/heap_allocator.h\n> > +++ b/include/libcamera/internal/heap_allocator.h\n> > @@ -8,12 +8,16 @@\n> >  #pragma once\n> >\n> >  #include <stddef.h>\n> > +#include <vector>\n> >\n> >  #include <libcamera/base/unique_fd.h>\n> >\n> >  namespace libcamera {\n> >\n> > +class Camera;\n> > +class FrameBuffer;\n> >  class Heap;\n> > +class Stream;\n> >\n> >  class HeapAllocator\n> >  {\n> > @@ -23,7 +27,12 @@ public:\n> >       bool isValid() const;\n> >       UniqueFD alloc(const char *name, std::size_t size);\n> >\n> > +     int exportFrameBuffers(Camera *camera, Stream *stream,\n> > +                            std::vector<std::unique_ptr<FrameBuffer>>\n> *buffers);\n> > +\n> >  private:\n> > +     std::unique_ptr<FrameBuffer> createBuffer(Stream *stream);\n> > +\n> >       std::unique_ptr<Heap> heap_;\n> >  };\n> >\n> > diff --git a/src/libcamera/heap_allocator.cpp\n> b/src/libcamera/heap_allocator.cpp\n> > index 682a7e01..ce3a815d 100644\n> > --- a/src/libcamera/heap_allocator.cpp\n> > +++ b/src/libcamera/heap_allocator.cpp\n> > @@ -21,6 +21,12 @@\n> >\n> >  #include <libcamera/base/log.h>\n> >\n> > +#include <libcamera/camera.h>\n> > +#include <libcamera/framebuffer.h>\n> > +#include <libcamera/stream.h>\n> > +\n> > +#include \"libcamera/internal/formats.h\"\n> > +\n> >  namespace libcamera {\n> >\n> >  /*\n> > @@ -231,4 +237,59 @@ UniqueFD HeapAllocator::alloc(const char *name,\n> std::size_t size)\n> >       return heap_->alloc(name, size);\n> >  }\n> >\n> > +int HeapAllocator::exportFrameBuffers([[maybe_unused]] Camera *camera,\n> Stream *stream,\n> > +\n>  std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n> > +{\n> > +     unsigned int count = stream->configuration().bufferCount;\n> > +\n> > +     /** \\todo Support multiplanar allocations */\n> > +\n> > +     for (unsigned i = 0; i < count; ++i) {\n> > +             std::unique_ptr<FrameBuffer> buffer = createBuffer(stream);\n> > +             if (!buffer) {\n> > +                     LOG(HeapAllocator, Error) << \"Unable to create\n> 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> HeapAllocator::createBuffer(Stream *stream)\n> > +{\n> > +     std::vector<FrameBuffer::Plane> planes;\n> > +\n> > +     unsigned int frameSize = stream->configuration().frameSize;\n> > +     int pageSize = getpagesize();\n> > +     // Allocation size need to be a direct multiple of |pageSize|.\n>\n> no c++ style comments, please\n>\n>\nYou mean to use \"/**\" and \"*/\", right?\n\n\n> > +     unsigned int numPage = (frameSize + pageSize - 1) / pageSize;\n> > +\n> > +     UniqueFD fd = alloc(\"FrameBuffer\", numPage * pageSize);\n> > +     if (!fd.isValid())\n> > +             return nullptr;\n> > +\n>\n> And I would add here a comment as reported in the review of v4\n>\n> Can be fixed when applying\n>\n\nYou mean the todo of the dedicated fd for each plane, right?\n\n\n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n>\n> Thanks\n>   j\n>\n> > +     auto info =\n> PixelFormatInfo::info(stream->configuration().pixelFormat);\n> > +     SharedFD shared_fd(std::move(fd));\n> > +     unsigned int offset = 0;\n> > +     for (size_t i = 0; i < info.planes.size(); ++i) {\n> > +             unsigned int planeSize =\n> info.planeSize(stream->configuration().size, i);\n> > +             if (planeSize == 0)\n> > +                     continue;\n> > +\n> > +             FrameBuffer::Plane plane;\n> > +             plane.fd = shared_fd;\n> > +             plane.offset = offset;\n> > +             plane.length = planeSize;\n> > +             planes.push_back(std::move(plane));\n> > +\n> > +             offset += planeSize;\n> > +     }\n> > +\n> > +     return std::make_unique<FrameBuffer>(planes);\n> > +}\n> > +\n> >  } /* namespace libcamera */\n> > --\n> > 2.40.1.606.ga4b1b128d6-goog\n> >\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 B6C27C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 May 2023 08:36:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6CD5462861;\n\tMon, 22 May 2023 10:36:45 +0200 (CEST)","from mail-vk1-xa2f.google.com (mail-vk1-xa2f.google.com\n\t[IPv6:2607:f8b0:4864:20::a2f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6E74160536\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 May 2023 10:36:44 +0200 (CEST)","by mail-vk1-xa2f.google.com with SMTP id\n\t71dfb90a1353d-456f19307f6so1488775e0c.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 May 2023 01:36:44 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1684744605;\n\tbh=4lH6CAD6KCcLwnCXfghMFpFEA9TiXotelmI/B9Ay71s=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=n/VhdOIaG/F8V9NgJaxaOMgfFu7tqD+fJ2c9oAMhvyquqZNmFfV9qIDkLzWgrvrbw\n\t5LN4BZ4DFV5uUaqcZkcp+sl+3LcTMC2VuTNE+eyGSdvUZDws6+oObnBtw94Vz4oTZS\n\tDvY5ycplMjEdUO6b/FnH9DfkjWOaUGGMCdOD6fHP+oInL9SjQCL6P5uksAyJgpN+TW\n\t7++AiNi43w+rqpp91Y6HnKwTIk0R3HFhjS4ThAYbKA4P8fmB4rjHkvc+nFuflKwuCo\n\tAFHHCl+DAmSL3oMksTTWcX29pk64NeNDwR5iir3cfE25gjCKEyXkXQhyFQngq9VXjN\n\tbi0Se6e5n/KnQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1684744603; x=1687336603;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=OwpxZrklXZKq94o6IBTpZmFf5fm0loUCRGhQwPbHwGI=;\n\tb=AGu22Dd/jhTM+PxtviCaWekh0+EhlPUBc6XhCsyuiQQvAenemLcAhBgFDdJpfVpj7h\n\t4eWyrtCVKOOx4AcySx2t4NK6FjPZbdo4vYkchf/oOucsSpil3/c9BVXubq0ta3cbqIVS\n\t6f9s0w+d5q4Oj1aUNjWTVB7I0qJLprJXMdCLY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"AGu22Dd/\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1684744603; x=1687336603;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=OwpxZrklXZKq94o6IBTpZmFf5fm0loUCRGhQwPbHwGI=;\n\tb=Xx10uNFC9x7+XBaH7xzcLoEewjbzWLZBHlanUy3/4vzD1O7LFwceVYN2ByNbj+Onhz\n\tp2mL1wcriL5eaX8HTl1B98RZGz9/v0sj7F1lINdDapyuX+pQi3eGHJ+aCx5s4HNXWYaD\n\tdZIC2dYsoy8+XKv5Yb8Lj4YxJCy6rbi9mzw1klUpg6QNMsW/DVmmB6gkEzX5ldg9m2Vl\n\t8tzK0jRUTBN1X6+ocQLTQaGlduorPhv2aRhPqMDBCaQ9pbknN4O7tjRDDZXdUKnllp/4\n\t3ZovEziMwjMHixy+eh/wgh7YZilxuNdsqply0mMUVTCxTROMt0brXmhkNfZwgzVXDtX5\n\tYfNg==","X-Gm-Message-State":"AC+VfDwLLeXNgFbYlZ73I7ei/kUk9cukYnEVug5VeLSrK1ArdDf7BGDd\n\tFzwfJA5ZU7lDHtRQ97s/aauLsEg/Te9JYcAT4QHS2aGErEpcQFe51XU=","X-Google-Smtp-Source":"ACHHUZ4EqpG99M/Mmtu0SSXlY4dGVMFBn4VnNdi8eXjGhEHEsYe5cQjTdD6RrCwB1Eh/J4SEVuSMloos322eDAhwQ1E=","X-Received":"by 2002:a67:fb0c:0:b0:42c:6fd8:a44d with SMTP id\n\td12-20020a67fb0c000000b0042c6fd8a44dmr1889724vsr.31.1684744603177;\n\tMon, 22 May 2023 01:36:43 -0700 (PDT)","MIME-Version":"1.0","References":"<20230516080459.711347-1-chenghaoyang@google.com>\n\t<20230516080459.711347-4-chenghaoyang@google.com>\n\t<20230516103213.5hlrg3e2tdrxbzhe@lati>","In-Reply-To":"<20230516103213.5hlrg3e2tdrxbzhe@lati>","Date":"Mon, 22 May 2023 16:36:32 +0800","Message-ID":"<CAEB1ahsqqrsA4_Mv6izHfjj1=fS=Dv3PDZFrsbAihN6eYBTiXw@mail.gmail.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"0000000000009c2bf905fc442be7\"","Subject":"Re: [libcamera-devel] [PATCH v5 3/3] libcamera: Add\n\texportFrameBuffers in HeapAllocator","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>","From":"Cheng-Hao Yang via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Cheng-Hao Yang <chenghaoyang@chromium.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27128,"web_url":"https://patchwork.libcamera.org/comment/27128/","msgid":"<aczl3murkeisw4df4xg34qyn6kdxlwoap2ugrbxezcr6kmnhho@b2kusr4dcdoc>","date":"2023-05-22T13:19:46","subject":"Re: [libcamera-devel] [PATCH v5 3/3] libcamera: Add\n\texportFrameBuffers in HeapAllocator","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hello Harvey\n\nOn Mon, May 22, 2023 at 04:36:32PM +0800, Cheng-Hao Yang via libcamera-devel wrote:\n> Thanks Jacopo.\n>\n> On Tue, May 16, 2023 at 6:32 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> wrote:\n>\n> > Hi Harvey\n> >\n> > On Tue, May 16, 2023 at 08:03:19AM +0000, Harvey Yang via libcamera-devel\n> > wrote:\n> > > From: Cheng-Hao Yang <chenghaoyang@chromium.org>\n> > >\n> > > Add a helper function exportFrameBuffers in HeapAllocator to make it\n> > > easier to use.\n> > >\n> > > Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> > > ---\n> > >  include/libcamera/internal/heap_allocator.h |  9 +++\n> > >  src/libcamera/heap_allocator.cpp            | 61 +++++++++++++++++++++\n> > >  2 files changed, 70 insertions(+)\n> > >\n> > > diff --git a/include/libcamera/internal/heap_allocator.h\n> > b/include/libcamera/internal/heap_allocator.h\n> > > index d061fdce..b6488fbc 100644\n> > > --- a/include/libcamera/internal/heap_allocator.h\n> > > +++ b/include/libcamera/internal/heap_allocator.h\n> > > @@ -8,12 +8,16 @@\n> > >  #pragma once\n> > >\n> > >  #include <stddef.h>\n> > > +#include <vector>\n> > >\n> > >  #include <libcamera/base/unique_fd.h>\n> > >\n> > >  namespace libcamera {\n> > >\n> > > +class Camera;\n> > > +class FrameBuffer;\n> > >  class Heap;\n> > > +class Stream;\n> > >\n> > >  class HeapAllocator\n> > >  {\n> > > @@ -23,7 +27,12 @@ public:\n> > >       bool isValid() const;\n> > >       UniqueFD alloc(const char *name, std::size_t size);\n> > >\n> > > +     int exportFrameBuffers(Camera *camera, Stream *stream,\n> > > +                            std::vector<std::unique_ptr<FrameBuffer>>\n> > *buffers);\n> > > +\n> > >  private:\n> > > +     std::unique_ptr<FrameBuffer> createBuffer(Stream *stream);\n> > > +\n> > >       std::unique_ptr<Heap> heap_;\n> > >  };\n> > >\n> > > diff --git a/src/libcamera/heap_allocator.cpp\n> > b/src/libcamera/heap_allocator.cpp\n> > > index 682a7e01..ce3a815d 100644\n> > > --- a/src/libcamera/heap_allocator.cpp\n> > > +++ b/src/libcamera/heap_allocator.cpp\n> > > @@ -21,6 +21,12 @@\n> > >\n> > >  #include <libcamera/base/log.h>\n> > >\n> > > +#include <libcamera/camera.h>\n> > > +#include <libcamera/framebuffer.h>\n> > > +#include <libcamera/stream.h>\n> > > +\n> > > +#include \"libcamera/internal/formats.h\"\n> > > +\n> > >  namespace libcamera {\n> > >\n> > >  /*\n> > > @@ -231,4 +237,59 @@ UniqueFD HeapAllocator::alloc(const char *name,\n> > std::size_t size)\n> > >       return heap_->alloc(name, size);\n> > >  }\n> > >\n> > > +int HeapAllocator::exportFrameBuffers([[maybe_unused]] Camera *camera,\n> > Stream *stream,\n> > > +\n> >  std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n> > > +{\n> > > +     unsigned int count = stream->configuration().bufferCount;\n> > > +\n> > > +     /** \\todo Support multiplanar allocations */\n> > > +\n> > > +     for (unsigned i = 0; i < count; ++i) {\n> > > +             std::unique_ptr<FrameBuffer> buffer = createBuffer(stream);\n> > > +             if (!buffer) {\n> > > +                     LOG(HeapAllocator, Error) << \"Unable to create\n> > 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> HeapAllocator::createBuffer(Stream *stream)\n> > > +{\n> > > +     std::vector<FrameBuffer::Plane> planes;\n> > > +\n> > > +     unsigned int frameSize = stream->configuration().frameSize;\n> > > +     int pageSize = getpagesize();\n> > > +     // Allocation size need to be a direct multiple of |pageSize|.\n> >\n> > no c++ style comments, please\n> >\n> >\n> You mean to use \"/**\" and \"*/\", right?\n>\n\n/** is (one of the) doxygen markers\n\n/* is the single line comment stlye. */\n\n/*\n * while this one is a multi line comment\n * split on multiple lines.\n */\n\n>\n> > > +     unsigned int numPage = (frameSize + pageSize - 1) / pageSize;\n> > > +\n> > > +     UniqueFD fd = alloc(\"FrameBuffer\", numPage * pageSize);\n> > > +     if (!fd.isValid())\n> > > +             return nullptr;\n> > > +\n> >\n> > And I would add here a comment as reported in the review of v4\n> >\n> > Can be fixed when applying\n> >\n>\n> You mean the todo of the dedicated fd for each plane, right?\n>\n\nIf I recall correctly, yes :)\n\n>\n> > Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> >\n> > Thanks\n> >   j\n> >\n> > > +     auto info =\n> > PixelFormatInfo::info(stream->configuration().pixelFormat);\n> > > +     SharedFD shared_fd(std::move(fd));\n> > > +     unsigned int offset = 0;\n> > > +     for (size_t i = 0; i < info.planes.size(); ++i) {\n> > > +             unsigned int planeSize =\n> > info.planeSize(stream->configuration().size, i);\n> > > +             if (planeSize == 0)\n> > > +                     continue;\n> > > +\n> > > +             FrameBuffer::Plane plane;\n> > > +             plane.fd = shared_fd;\n> > > +             plane.offset = offset;\n> > > +             plane.length = planeSize;\n> > > +             planes.push_back(std::move(plane));\n> > > +\n> > > +             offset += planeSize;\n> > > +     }\n> > > +\n> > > +     return std::make_unique<FrameBuffer>(planes);\n> > > +}\n> > > +\n> > >  } /* namespace libcamera */\n> > > --\n> > > 2.40.1.606.ga4b1b128d6-goog\n> > >\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 96658C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 May 2023 13:19:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 03F4560545;\n\tMon, 22 May 2023 15:19:55 +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 6493A60536\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 May 2023 15:19:53 +0200 (CEST)","from ideasonboard.com (host-87-10-52-171.retail.telecomitalia.it\n\t[87.10.52.171])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4125A9DE;\n\tMon, 22 May 2023 15:19:35 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1684761595;\n\tbh=L6xXoYPjQpzsYMs+v2HUTV/nBRv9W1Io2AVmpnWiDaE=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=TUBQvCd52sv3NXj1usiQRA7SnypRmIH/Ui8NKKqD9dVgNZoRu1MbNNpVZDHo5E69Y\n\trlnzSh29f3Xr/oSPHqO5fXiX8p0O7K+FDZvAK0gF/6Y+1XPavfw8ux2Yoi5m+AdeRA\n\t/iD1/Idi/J3U134t6ITmGeq7Jn4rORsUrZrB3TImwY/XLOPWoUjV9ryQF7bmsIHdmH\n\tkd4uol3s0avlgeTNsfP2wvJnRpwZ+YMFDiZ3m1uvooktoQsjJa4RTxsyP/sOC+OaOu\n\tiVcvxzgf3X+OqVT12DbE07dsBRFQHlYRcPFvOZdOuyj/5A+mJQq+GBm6wPrQEhjdxN\n\t7ktqGUzvpXj0g==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1684761578;\n\tbh=L6xXoYPjQpzsYMs+v2HUTV/nBRv9W1Io2AVmpnWiDaE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ZT+uKrbGVLC0zmhAUJwRbqmcqedy+eR0SyX5PK63niTOPxbuQ8CxjW+Oe7iC42JVp\n\tzX5iyghLQ56eOen4Ir0PZ3g+71FDAbrhe6OektUXvAEgMmGEZpsFsQRUrxRJq6+sGl\n\t/4ALBJ8PG02xgzr4y2XziXX0Goj3UuXHSTm7faoE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ZT+uKrbG\"; dkim-atps=neutral","Date":"Mon, 22 May 2023 15:19:46 +0200","To":"Cheng-Hao Yang <chenghaoyang@chromium.org>","Message-ID":"<aczl3murkeisw4df4xg34qyn6kdxlwoap2ugrbxezcr6kmnhho@b2kusr4dcdoc>","References":"<20230516080459.711347-1-chenghaoyang@google.com>\n\t<20230516080459.711347-4-chenghaoyang@google.com>\n\t<20230516103213.5hlrg3e2tdrxbzhe@lati>\n\t<CAEB1ahsqqrsA4_Mv6izHfjj1=fS=Dv3PDZFrsbAihN6eYBTiXw@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<CAEB1ahsqqrsA4_Mv6izHfjj1=fS=Dv3PDZFrsbAihN6eYBTiXw@mail.gmail.com>","Subject":"Re: [libcamera-devel] [PATCH v5 3/3] libcamera: Add\n\texportFrameBuffers in HeapAllocator","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]