{"id":13217,"url":"https://patchwork.libcamera.org/api/1.1/patches/13217/?format=json","web_url":"https://patchwork.libcamera.org/patch/13217/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210805174955.1579287-1-hiroh@chromium.org>","date":"2021-08-05T17:49:55","name":"[libcamera-devel] libcamera: framebuffer: Return plane begin address by MappedBuffer::maps()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6eddb6153a2a3a50d72b0cbe33778f0459dd9010","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13217/mbox/","series":[{"id":2311,"url":"https://patchwork.libcamera.org/api/1.1/series/2311/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2311","date":"2021-08-05T17:49:55","name":"[libcamera-devel] libcamera: framebuffer: Return plane begin address by MappedBuffer::maps()","version":1,"mbox":"https://patchwork.libcamera.org/series/2311/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13217/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13217/checks/","tags":{},"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 1194FC3235\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  5 Aug 2021 17:50:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 65E39687CF;\n\tThu,  5 Aug 2021 19:50:05 +0200 (CEST)","from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com\n\t[IPv6:2607:f8b0:4864:20::102d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B399B6026D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  5 Aug 2021 19:50:03 +0200 (CEST)","by mail-pj1-x102d.google.com with SMTP id\n\ts22-20020a17090a1c16b0290177caeba067so16750565pjs.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 05 Aug 2021 10:50:03 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:490b:61c8:a52a:e6eb])\n\tby smtp.gmail.com with ESMTPSA id\n\tp3sm9975460pjt.0.2021.08.05.10.50.00\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 05 Aug 2021 10:50:01 -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=\"WyhT1Vlg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; h=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=MNAgr7Dyt5On5utIViZLsalHOVlmLlfJl1tTuhzm4w8=;\n\tb=WyhT1VlgdzQGWlvktpq0g2mZJ8CnaeIugSBJIt0tL+V43rKNUIxWwcJynpGJhfy0YR\n\tVKGlgNX3v8D7zju1gSD/pkkjcUNVptWlk+ASbx47bPvaX9VhgcRS1SXbMR0sOV0xnGEr\n\txcfRdCzgWbgCR61kjs0YTkOjtMe8bsWmL4J8s=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=MNAgr7Dyt5On5utIViZLsalHOVlmLlfJl1tTuhzm4w8=;\n\tb=mrVhBz1Ez359A8nmjGz0N93rTkirNctLdXg4pmjI1T2rp1eIFrXY/d/G3+zbEGQzst\n\tezLv0X5bJ1pTOdR8uzlEpMWMj6bBMUTj+ztTrQdmGgdtWcveTCZ7iCNwdQGXaYYTgiZo\n\t5u+WsIqjhRjyKwdZ7Vu6UGiVnRUn2XtiHgSZOAUuyG5W7WWuJtn+IrKo4G1M7rg4ptS9\n\tR4ZCqOd0fUR0EY5vSb2BzVqH9R1IHwA3kuHg+kXANKJ4TZ4UfOtGI4wEY/Ovr4ENyn/4\n\tDOx4IR3MvxyNRc4E/wKWMjkcnsHDAi18X/zVnthSwGVfq+H8Jmc9fiTtoVBrWMfG+Q0L\n\tdxyw==","X-Gm-Message-State":"AOAM530pvsfQsxcsLJW22QuS+Sax4zRPgmEo7P4Mi8jgphFs/0vg496y\n\tmx5pk7/+6e87XHXXgCFrW9SK5oMu68lZXA==","X-Google-Smtp-Source":"ABdhPJy6GSZqgLcMiZ/uO8G1VatzaW88/1UfaobMbo6xK6VbNuan1/9YhdgsbDnQBUFu6JAcrPoAzw==","X-Received":"by 2002:a65:6a01:: with SMTP id m1mr820616pgu.201.1628185801812; \n\tThu, 05 Aug 2021 10:50:01 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org,\n\tlaurent.pinchart@ideasonboard.com","Date":"Fri,  6 Aug 2021 02:49:55 +0900","Message-Id":"<20210805174955.1579287-1-hiroh@chromium.org>","X-Mailer":"git-send-email 2.32.0.554.ge1b32706d8-goog","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[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>"},"content":"MappedBuffer::maps() returns std::vector<MappedBuffer::Plane>.\nPlane has the address, but the address points the beginning of the\nbuffer containing the plane.\nThis makes the Plane point the beginning of the plane. So\nMappedBuffer::maps()[i].data() returns the address of i-th plane.\n\nSigned-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(-)","diff":"diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\nindex 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)\ndiff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\nindex 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 \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+\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","prefixes":["libcamera-devel"]}