[{"id":18583,"web_url":"https://patchwork.libcamera.org/comment/18583/","msgid":"<CAO5uPHN7vH6_SWhAyxSouRXn5afCLFYR0tSNnvdPATRqqbSmqQ@mail.gmail.com>","date":"2021-08-06T05:54:21","subject":"Re: [libcamera-devel] [PATCH] libcamera: framebuffer: Return plane\n\tbegin address by MappedBuffer::maps()","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"content":"While I remove a manual address computation in Thumbnail\nhttps://git.linuxtv.org/libcamera.git/tree/src/android/jpeg/thumbnailer.cpp#n64,\nI noticed there might be a misunderstanding of\nFrameBuffer::Plane::length meaning.\nNot only to clarify the meaning but also discuss a better approach, I\nfiled https://bugs.libcamera.org/show_bug.cgi?id=72.\n\nRegards,\n-Hiro\n\nOn Fri, Aug 6, 2021 at 2:50 AM Hirokazu Honda <hiroh@chromium.org> wrote:\n>\n> MappedBuffer::maps() returns std::vector<MappedBuffer::Plane>.\n> Plane has the address, but the address points the beginning of the\n> buffer containing the plane.\n> This makes the Plane point the beginning of the plane. So\n> MappedBuffer::maps()[i].data() returns the address of i-th plane.\n>\n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> ---\n>  include/libcamera/internal/framebuffer.h |  1 +\n>  src/libcamera/framebuffer.cpp            | 41 +++++++++++++++++-------\n>  2 files changed, 31 insertions(+), 11 deletions(-)\n>\n> diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\n> index 8c187adf..2eb3b7c9 100644\n> --- a/include/libcamera/internal/framebuffer.h\n> +++ b/include/libcamera/internal/framebuffer.h\n> @@ -36,6 +36,7 @@ protected:\n>\n>         int error_;\n>         std::vector<Plane> maps_;\n> +       std::vector<Plane> chunks_;\n>\n>  private:\n>         LIBCAMERA_DISABLE_COPY(MappedBuffer)\n> diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\n> index a59e93fb..8231c1df 100644\n> --- a/src/libcamera/framebuffer.cpp\n> +++ b/src/libcamera/framebuffer.cpp\n> @@ -310,6 +310,7 @@ MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n>  {\n>         error_ = other.error_;\n>         maps_ = std::move(other.maps_);\n> +       chunks_ = std::move(other.chunks_);\n>         other.error_ = -ENOENT;\n>\n>         return *this;\n> @@ -317,8 +318,8 @@ MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n>\n>  MappedBuffer::~MappedBuffer()\n>  {\n> -       for (Plane &map : maps_)\n> -               munmap(map.data(), map.size());\n> +       for (Plane &chunk : chunks_)\n> +               munmap(chunk.data(), chunk.size());\n>  }\n>\n>  /**\n> @@ -381,18 +382,36 @@ MappedBuffer::~MappedBuffer()\n>   */\n>  MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, int flags)\n>  {\n> +       if (buffer->planes().empty())\n> +               return;\n>         maps_.reserve(buffer->planes().size());\n>\n> +       /*\n> +        * Below assumes planes are in the same buffer and planes are\n> +        * consecutive.\n> +        * \\todo remove this assumption.\n> +        */\n> +       const int fd = buffer->planes()[0].fd.fd();\n> +       const off_t length = lseek(fd, 0, SEEK_END);\n> +       if (length < 0) {\n> +               error_ = -errno;\n> +               LOG(Buffer, Error) << \"Failed to lseek buffer\";\n> +               return;\n> +       }\n> +\n> +       void *address = mmap(nullptr, length, flags, MAP_SHARED, fd, 0);\n> +       if (address == MAP_FAILED) {\n> +               error_ = -errno;\n> +               LOG(Buffer, Error) << \"Failed to mmap plane\";\n> +               return;\n> +       }\n> +       chunks_ = { MappedBuffer::Plane(static_cast<uint8_t *>(address),\n> +                                       static_cast<size_t>(length)) };\n> +       size_t offset = 0;\n>         for (const FrameBuffer::Plane &plane : buffer->planes()) {\n> -               void *address = mmap(nullptr, plane.length, flags,\n> -                                    MAP_SHARED, plane.fd.fd(), 0);\n> -               if (address == MAP_FAILED) {\n> -                       error_ = -errno;\n> -                       LOG(Buffer, Error) << \"Failed to mmap plane\";\n> -                       break;\n> -               }\n> -\n> -               maps_.emplace_back(static_cast<uint8_t *>(address), plane.length);\n> +               maps_.emplace_back(static_cast<uint8_t *>(address) + offset,\n> +                                  plane.length);\n> +               offset += plane.length;\n>         }\n>  }\n>\n> --\n> 2.32.0.554.ge1b32706d8-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 8D8E9C3235\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Aug 2021 05:54:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C31126880D;\n\tFri,  6 Aug 2021 07:54:33 +0200 (CEST)","from mail-ed1-x533.google.com (mail-ed1-x533.google.com\n\t[IPv6:2a00:1450:4864:20::533])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E1F66026C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Aug 2021 07:54:32 +0200 (CEST)","by mail-ed1-x533.google.com with SMTP id d6so11549451edt.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 05 Aug 2021 22:54:32 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"I72PHx/p\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to;\n\tbh=lkQaRs8j2wipcRCyewpubBA1sFqqdNFmURTywAplHn0=;\n\tb=I72PHx/p2j83/vYo9Py/m/fytRHk+l7llPTTlRBFaKGgXVMj1BsZiD24Tgt33noZln\n\tp/ZUuRciWh3KNQ+rCl11dY6BY48E85v4fASlTvwxjQ7HMLoy6EpeocH0mTMKuC90kdHy\n\t5Y5uJUhvJIrJ99AatdKM9XiWXLd7LkiRKlx9Q=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to;\n\tbh=lkQaRs8j2wipcRCyewpubBA1sFqqdNFmURTywAplHn0=;\n\tb=PzSvepCGul4JO3m/r5GvxZvxfQ+gLXMjuKGI81g84jOt9rEfCEWBH2UYbAyCh8kKlf\n\t+BLJRy115MYy0G+c/tBJJGyPsPPpDvITDJR/aJ5zBlPb71T5qJnYU9NDjuCu1qlOyzV+\n\tHGGaU+0OUyuiF6+0+q7Ckaqfy4/Xu4pBJ9Xd0yagwYtoxxWIo7zhuZplBGa1h/Z4kGmq\n\tWiYnYXWOz1QnCuxfc4GcgmFvnXWetyuw+Yj4Rq49/rUJjhwnj1YDmUdHYkz65vOhSNXn\n\tYhzW/Mv3tPLj37NZVU7h979NfI/Yco1n09uDQOjCxbhr3sqZ2TNFpsu+RofjeILn10tC\n\tx0CQ==","X-Gm-Message-State":"AOAM530jibo301hJ81t9Cvh8t8FM2lJVmx2h8In1LoTAf8JL1o+tvXp1\n\t3TKYpbMTDUjnklN6NzS/8r6jA2rCOCWcYBTOuo+zoOfGIAVqKA==","X-Google-Smtp-Source":"ABdhPJwmlL6iFi3cvmmlrQaIh+mOR2M8sEuzjdQSqjeTt7AQkNbnYy7bb9RyecWvLpDH5vTsidZP0c+ktmDHESZDhxE=","X-Received":"by 2002:aa7:c816:: with SMTP id\n\ta22mr10991410edt.202.1628229271579; \n\tThu, 05 Aug 2021 22:54:31 -0700 (PDT)","MIME-Version":"1.0","References":"<20210805174955.1579287-1-hiroh@chromium.org>","In-Reply-To":"<20210805174955.1579287-1-hiroh@chromium.org>","From":"Hirokazu Honda <hiroh@chromium.org>","Date":"Fri, 6 Aug 2021 14:54:21 +0900","Message-ID":"<CAO5uPHN7vH6_SWhAyxSouRXn5afCLFYR0tSNnvdPATRqqbSmqQ@mail.gmail.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>, \n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH] libcamera: framebuffer: Return plane\n\tbegin address by MappedBuffer::maps()","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":18598,"web_url":"https://patchwork.libcamera.org/comment/18598/","msgid":"<723ddf1e-fab8-2fdc-7245-c80571329362@ideasonboard.com>","date":"2021-08-06T13:18:10","subject":"Re: [libcamera-devel] [PATCH] libcamera: framebuffer: Return plane\n\tbegin address by MappedBuffer::maps()","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Hiro,\n\nOn 05/08/2021 18:49, Hirokazu Honda wrote:\n> MappedBuffer::maps() returns std::vector<MappedBuffer::Plane>.\n> Plane has the address, but the address points the beginning of the\n> buffer containing the plane.\n> This makes the Plane point the beginning of the plane. So\n> MappedBuffer::maps()[i].data() returns the address of i-th plane.\n\nIf we can handle the logic in MappedBuffer to get the correct addresses\nthat would certainly be beneficial indeed, so this sounds like good\ndevelopment.\n\n\n> \n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> ---\n>  include/libcamera/internal/framebuffer.h |  1 +\n>  src/libcamera/framebuffer.cpp            | 41 +++++++++++++++++-------\n>  2 files changed, 31 insertions(+), 11 deletions(-)\n> \n> diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\n> index 8c187adf..2eb3b7c9 100644\n> --- a/include/libcamera/internal/framebuffer.h\n> +++ b/include/libcamera/internal/framebuffer.h\n> @@ -36,6 +36,7 @@ protected:\n>  \n>  \tint error_;\n>  \tstd::vector<Plane> maps_;\n> +\tstd::vector<Plane> chunks_;\n>  \n>  private:\n>  \tLIBCAMERA_DISABLE_COPY(MappedBuffer)\n> diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\n> index a59e93fb..8231c1df 100644\n> --- a/src/libcamera/framebuffer.cpp\n> +++ b/src/libcamera/framebuffer.cpp\n> @@ -310,6 +310,7 @@ MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n>  {\n>  \terror_ = other.error_;\n>  \tmaps_ = std::move(other.maps_);\n> +\tchunks_ = std::move(other.chunks_);\n>  \tother.error_ = -ENOENT;\n>  \n>  \treturn *this;\n> @@ -317,8 +318,8 @@ MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n>  \n>  MappedBuffer::~MappedBuffer()\n>  {\n> -\tfor (Plane &map : maps_)\n> -\t\tmunmap(map.data(), map.size());\n> +\tfor (Plane &chunk : chunks_)\n> +\t\tmunmap(chunk.data(), chunk.size());\n>  }\n>  \n>  /**\n> @@ -381,18 +382,36 @@ MappedBuffer::~MappedBuffer()\n>   */\n>  MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, int flags)\n>  {\n> +\tif (buffer->planes().empty())\n> +\t\treturn;\n\nCan we have a buffer with zero planes? Is this something that should\ngenerate an Error or Warning message?\n\n(Or if it really implies there's a bug, a Fatal?)\n\n\n>  \tmaps_.reserve(buffer->planes().size());\n>  \n> +\t/*\n> +\t * Below assumes planes are in the same buffer and planes are\n> +\t * consecutive.\n> +\t * \\todo remove this assumption.\n\nTo do that, will we need to store the PixelFormat information as part of\nthe FrameBuffer? Or at least some additional data there so that we know\nit's layout?\n\n\nAnd - now I've seen Laurent posted a patch to expose a Format for that\npurpose...\n\n\n\n> +\t */\n> +\tconst int fd = buffer->planes()[0].fd.fd();\n> +\tconst off_t length = lseek(fd, 0, SEEK_END);\n> +\tif (length < 0) {\n> +\t\terror_ = -errno;\n> +\t\tLOG(Buffer, Error) << \"Failed to lseek buffer\";\n> +\t\treturn;\n> +\t}\n> +\n> +\tvoid *address = mmap(nullptr, length, flags, MAP_SHARED, fd, 0);\n> +\tif (address == MAP_FAILED) {\n> +\t\terror_ = -errno;\n> +\t\tLOG(Buffer, Error) << \"Failed to mmap plane\";\n> +\t\treturn;\n> +\t}\n> +\tchunks_ = { MappedBuffer::Plane(static_cast<uint8_t *>(address),\n> +\t\t\t\t\tstatic_cast<size_t>(length)) };\n> +\tsize_t offset = 0;\n>  \tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n> -\t\tvoid *address = mmap(nullptr, plane.length, flags,\n> -\t\t\t\t     MAP_SHARED, plane.fd.fd(), 0);\n> -\t\tif (address == MAP_FAILED) {\n> -\t\t\terror_ = -errno;\n> -\t\t\tLOG(Buffer, Error) << \"Failed to mmap plane\";\n> -\t\t\tbreak;\n> -\t\t}\n> -\n> -\t\tmaps_.emplace_back(static_cast<uint8_t *>(address), plane.length);\n> +\t\tmaps_.emplace_back(static_cast<uint8_t *>(address) + offset,\n> +\t\t\t\t   plane.length);\n> +\t\toffset += plane.length;\n>  \t}\n>  }\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 23BD6BD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Aug 2021 13:18:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8C6E960267;\n\tFri,  6 Aug 2021 15:18:15 +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 AAA8160266\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Aug 2021 15:18:13 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1089D4FB;\n\tFri,  6 Aug 2021 15:18:13 +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=\"ZWSSbUZS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628255893;\n\tbh=Aob3hvnj5RTKNLn+s/7n+Gt3Do4kX50T8ATyn18H9tA=;\n\th=To:References:From:Subject:Date:In-Reply-To:From;\n\tb=ZWSSbUZS74d+yQIhEkR2XBd9AuUoDCU1sFUtmNqyIOg556KJ4NmGlgxb6SYfICxNi\n\ttqS/ca1nDY/o1Nsvzc+n9CcnUmT2ZxDxxJqzl8fvsAyuGv8qvL8IiFn4fuuq8BiDUb\n\tzFHx+3wGl7kDdXOuMUMV2tVh8MtFzekXxxYhn5s0=","To":"Hirokazu Honda <hiroh@chromium.org>, libcamera-devel@lists.libcamera.org,\n\tlaurent.pinchart@ideasonboard.com","References":"<20210805174955.1579287-1-hiroh@chromium.org>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<723ddf1e-fab8-2fdc-7245-c80571329362@ideasonboard.com>","Date":"Fri, 6 Aug 2021 14:18:10 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<20210805174955.1579287-1-hiroh@chromium.org>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH] libcamera: framebuffer: Return plane\n\tbegin address by MappedBuffer::maps()","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":18606,"web_url":"https://patchwork.libcamera.org/comment/18606/","msgid":"<YRBtubZKzfThmKzi@pendragon.ideasonboard.com>","date":"2021-08-08T23:50:17","subject":"Re: [libcamera-devel] [PATCH] libcamera: framebuffer: Return plane\n\tbegin address by MappedBuffer::maps()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hello,\n\nOn Fri, Aug 06, 2021 at 02:18:10PM +0100, Kieran Bingham wrote:\n> On 05/08/2021 18:49, Hirokazu Honda wrote:\n> > MappedBuffer::maps() returns std::vector<MappedBuffer::Plane>.\n> > Plane has the address, but the address points the beginning of the\n> > buffer containing the plane.\n> > This makes the Plane point the beginning of the plane. So\n> > MappedBuffer::maps()[i].data() returns the address of i-th plane.\n> \n> If we can handle the logic in MappedBuffer to get the correct addresses\n> that would certainly be beneficial indeed, so this sounds like good\n> development.\n> \n> > Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> > ---\n> >  include/libcamera/internal/framebuffer.h |  1 +\n> >  src/libcamera/framebuffer.cpp            | 41 +++++++++++++++++-------\n> >  2 files changed, 31 insertions(+), 11 deletions(-)\n> > \n> > diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\n> > index 8c187adf..2eb3b7c9 100644\n> > --- a/include/libcamera/internal/framebuffer.h\n> > +++ b/include/libcamera/internal/framebuffer.h\n> > @@ -36,6 +36,7 @@ protected:\n> >  \n> >  \tint error_;\n> >  \tstd::vector<Plane> maps_;\n> > +\tstd::vector<Plane> chunks_;\n> >  \n> >  private:\n> >  \tLIBCAMERA_DISABLE_COPY(MappedBuffer)\n> > diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\n> > index a59e93fb..8231c1df 100644\n> > --- a/src/libcamera/framebuffer.cpp\n> > +++ b/src/libcamera/framebuffer.cpp\n> > @@ -310,6 +310,7 @@ MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n> >  {\n> >  \terror_ = other.error_;\n> >  \tmaps_ = std::move(other.maps_);\n> > +\tchunks_ = std::move(other.chunks_);\n> >  \tother.error_ = -ENOENT;\n> >  \n> >  \treturn *this;\n> > @@ -317,8 +318,8 @@ MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n> >  \n> >  MappedBuffer::~MappedBuffer()\n> >  {\n> > -\tfor (Plane &map : maps_)\n> > -\t\tmunmap(map.data(), map.size());\n> > +\tfor (Plane &chunk : chunks_)\n> > +\t\tmunmap(chunk.data(), chunk.size());\n\nThe names are a bit confusing, I would expect maps_ to contained the\nmapped memory. How about doing that, and renaming chunks_ to planes_ ?\n\n> >  }\n> >  \n> >  /**\n> > @@ -381,18 +382,36 @@ MappedBuffer::~MappedBuffer()\n> >   */\n> >  MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, int flags)\n> >  {\n> > +\tif (buffer->planes().empty())\n> > +\t\treturn;\n> \n> Can we have a buffer with zero planes? Is this something that should\n> generate an Error or Warning message?\n> \n> (Or if it really implies there's a bug, a Fatal?)\n\nIt's not supposed to happen, so I think an ASSERT() would be enough.\n\n> >  \tmaps_.reserve(buffer->planes().size());\n> >  \n> > +\t/*\n> > +\t * Below assumes planes are in the same buffer and planes are\n> > +\t * consecutive.\n> > +\t * \\todo remove this assumption.\n> \n> To do that, will we need to store the PixelFormat information as part of\n> the FrameBuffer? Or at least some additional data there so that we know\n> it's layout?\n>\n> And - now I've seen Laurent posted a patch to expose a Format for that\n> purpose...\n\nI'd really like to avoid coupling FrameBuffer and FrameFormat. What we\nneed if an offset field in FrameBuffer::Plane. With that,\nMappedFrameBuffer can check if the fds in different planes are\nidentical, and if so, map the fd once only and use the offsets to\ncompute addresses. I think that would be enough.\n\nUntil we get that, could we verify that the assertion holds with an\nASSERT() here ? An ASSERT(buffer->planes().size() == 1) should suffice.\n\n> > +\t */\n> > +\tconst int fd = buffer->planes()[0].fd.fd();\n> > +\tconst off_t length = lseek(fd, 0, SEEK_END);\n> > +\tif (length < 0) {\n> > +\t\terror_ = -errno;\n> > +\t\tLOG(Buffer, Error) << \"Failed to lseek buffer\";\n> > +\t\treturn;\n> > +\t}\n> > +\n> > +\tvoid *address = mmap(nullptr, length, flags, MAP_SHARED, fd, 0);\n> > +\tif (address == MAP_FAILED) {\n> > +\t\terror_ = -errno;\n> > +\t\tLOG(Buffer, Error) << \"Failed to mmap plane\";\n> > +\t\treturn;\n> > +\t}\n> > +\tchunks_ = { MappedBuffer::Plane(static_cast<uint8_t *>(address),\n> > +\t\t\t\t\tstatic_cast<size_t>(length)) };\n> > +\tsize_t offset = 0;\n> >  \tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n> > -\t\tvoid *address = mmap(nullptr, plane.length, flags,\n> > -\t\t\t\t     MAP_SHARED, plane.fd.fd(), 0);\n> > -\t\tif (address == MAP_FAILED) {\n> > -\t\t\terror_ = -errno;\n> > -\t\t\tLOG(Buffer, Error) << \"Failed to mmap plane\";\n> > -\t\t\tbreak;\n> > -\t\t}\n> > -\n> > -\t\tmaps_.emplace_back(static_cast<uint8_t *>(address), plane.length);\n> > +\t\tmaps_.emplace_back(static_cast<uint8_t *>(address) + offset,\n> > +\t\t\t\t   plane.length);\n> > +\t\toffset += plane.length;\n> >  \t}\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 0893FBD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  8 Aug 2021 23:50:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 70D2568823;\n\tMon,  9 Aug 2021 01:50:21 +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 F0F376026C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  9 Aug 2021 01:50:18 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 62202466;\n\tMon,  9 Aug 2021 01:50:18 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"CIHdGxB5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628466618;\n\tbh=MU5VkN7JBiN26S7PHxCwJK0J/SyxD805N1Ht1zrLme0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=CIHdGxB5WfZzqv5HmI7m3q6biI80ThGbTA+1IlWd1lAJJ64wHpFiBNvpyY16TDnSj\n\t8np7KR+BrRmNcGGWNNcq7Yk/kHp65ZH9s/mBKufjNDqRRX7fwEsPlbqZ3oLNmYjnvY\n\tQUw08nSpQK9hF5vfKJbIscoN5wl0Y9D0RToNzAbs=","Date":"Mon, 9 Aug 2021 02:50:17 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YRBtubZKzfThmKzi@pendragon.ideasonboard.com>","References":"<20210805174955.1579287-1-hiroh@chromium.org>\n\t<723ddf1e-fab8-2fdc-7245-c80571329362@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<723ddf1e-fab8-2fdc-7245-c80571329362@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: framebuffer: Return plane\n\tbegin address by MappedBuffer::maps()","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]