Patch Detail
Show a patch.
GET /api/patches/13446/?format=api
{ "id": 13446, "url": "https://patchwork.libcamera.org/api/patches/13446/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13446/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210823131221.1034059-4-hiroh@chromium.org>", "date": "2021-08-23T13:12:14", "name": "[libcamera-devel,RFC,v2,03/10] libcamera: mapped_framebuffer: Return plane begin address by MappedBuffer::maps()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "8dda3212f3db0f1bf9731453ecdbc7b3355fbc0c", "submitter": { "id": 63, "url": "https://patchwork.libcamera.org/api/people/63/?format=api", "name": "Hirokazu Honda", "email": "hiroh@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13446/mbox/", "series": [ { "id": 2386, "url": "https://patchwork.libcamera.org/api/series/2386/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2386", "date": "2021-08-23T13:12:11", "name": "Add offset to FrameBuffer::Plane", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2386/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13446/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13446/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 5DF1FBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 13:12:41 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 176E5688A3;\n\tMon, 23 Aug 2021 15:12:41 +0200 (CEST)", "from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com\n\t[IPv6:2607:f8b0:4864:20::42c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BF23C688C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 15:12:39 +0200 (CEST)", "by mail-pf1-x42c.google.com with SMTP id x16so15329422pfh.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 06:12:39 -0700 (PDT)", "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:184e:5d20:8fcb:dfcd])\n\tby smtp.gmail.com with ESMTPSA id\n\tj4sm18596891pgi.6.2021.08.23.06.12.35\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 23 Aug 2021 06:12:37 -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=\"EvERI/W8\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=ZwsyyHFiY04CFGEw0wUYmKMJlrRZiA5UN0Tdo4rWxBU=;\n\tb=EvERI/W8q4o7QkXNGu/8SzpiEMwSUrDLZ9oSc0NC2kyxPTBFFBXzUu74mWcjC6ZOgG\n\tpSxsmkRm9Fh0Bv2Yxu0b7ybS+C5YeZS/8k3K9h/SUKQoQUcoKx5p6yFRLpPjFmHgEyAO\n\tvYdvdqnec0BJBdf/GZJE3q1N6sIl3K2IrN9t0=", "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:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=ZwsyyHFiY04CFGEw0wUYmKMJlrRZiA5UN0Tdo4rWxBU=;\n\tb=OXTWikkdP9i8ZypGR1rEny25MPiH07IxDb42HfMVweUUEF0TE6U8Zc4ZRXsmcwNvxi\n\t1Vj2x/idiDoxDDQsKEkd9POTl2qyzeAgkR0r7fxhNrZ/u6Nb6QRAYpVdKC3Ephkm3DlL\n\t1R6CUcVGSLqwRUnHBOEOIdHJ8lEHSvU0AQi5Cnueo7JfuHCU5XrGTW6FeN154jSj9JXS\n\tSSvbsC5rpXYqe23ZR/qLJFkBTA4rOGodfnXMP3agmk8IwFG1mCIFWEn71NEVmBtrFbp5\n\t0rQwQhWmNtBthKuN/sQjmJg+TQ0FZldNTsRK9Y07UHx/l5GXn+qs5Sy4d8s7dlsBlHbJ\n\t03iw==", "X-Gm-Message-State": "AOAM5304aNENyyVIrA8uEHSd/yKyGvQL3XZHugD4YR8j/ikrX9KrFUkb\n\tg3Uxeg2BPRb0yVdyIRvS3Z+q1157oBuUSA==", "X-Google-Smtp-Source": "ABdhPJzFZoEtrEiR527Q2qIq74zanQkGXRlj8L6MspVg/Lon7lWelKdSqFcn+Y6sHkniasG/p57Etw==", "X-Received": "by 2002:a63:d0d:: with SMTP id\n\tc13mr31926493pgl.294.1629724358022; \n\tMon, 23 Aug 2021 06:12:38 -0700 (PDT)", "From": "Hirokazu Honda <hiroh@chromium.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 23 Aug 2021 22:12:14 +0900", "Message-Id": "<20210823131221.1034059-4-hiroh@chromium.org>", "X-Mailer": "git-send-email 2.33.0.rc2.250.ged5fa647cd-goog", "In-Reply-To": "<20210823131221.1034059-1-hiroh@chromium.org>", "References": "<20210823131221.1034059-1-hiroh@chromium.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC PATCH v2 03/10] libcamera:\n\tmapped_framebuffer: Return plane begin address by\n\tMappedBuffer::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 .../libcamera/internal/mapped_framebuffer.h | 4 +-\n src/libcamera/mapped_framebuffer.cpp | 69 ++++++++++++++++---\n 2 files changed, 62 insertions(+), 11 deletions(-)", "diff": "diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h\nindex 3401a9fc..42479541 100644\n--- a/include/libcamera/internal/mapped_framebuffer.h\n+++ b/include/libcamera/internal/mapped_framebuffer.h\n@@ -30,12 +30,14 @@ public:\n \n \tbool isValid() const { return error_ == 0; }\n \tint error() const { return error_; }\n-\tconst std::vector<Plane> &maps() const { return maps_; }\n+\t/* \\todo rename to planes(). */\n+\tconst std::vector<Plane> &maps() const { return planes_; }\n \n protected:\n \tMappedBuffer();\n \n \tint error_;\n+\tstd::vector<Plane> planes_;\n \tstd::vector<Plane> maps_;\n \n private:\ndiff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp\nindex 2ebe9fdb..03425dea 100644\n--- a/src/libcamera/mapped_framebuffer.cpp\n+++ b/src/libcamera/mapped_framebuffer.cpp\n@@ -7,8 +7,11 @@\n \n #include \"libcamera/internal/mapped_framebuffer.h\"\n \n+#include <algorithm>\n #include <errno.h>\n+#include <map>\n #include <sys/mman.h>\n+#include <unistd.h>\n \n #include <libcamera/base/log.h>\n \n@@ -79,6 +82,7 @@ MappedBuffer::MappedBuffer(MappedBuffer &&other)\n MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n {\n \terror_ = other.error_;\n+\tplanes_ = std::move(other.planes_);\n \tmaps_ = std::move(other.maps_);\n \tother.error_ = -ENOENT;\n \n@@ -127,10 +131,18 @@ MappedBuffer::~MappedBuffer()\n */\n \n /**\n- * \\var MappedBuffer::maps_\n+ * \\var MappedBuffer::planes_\n * \\brief Stores the internal mapped planes\n *\n * MappedBuffer derived classes shall store the mappings they create in this\n+ * vector which points the beginning of mapped plane addresses.\n+ */\n+\n+/**\n+ * \\var MappedBuffer::maps_\n+ * \\brief Stores the mapped buffer\n+ *\n+ * MappedBuffer derived classes shall store the mappings they create in this\n * vector which is parsed during destruct to unmap any memory mappings which\n * completed successfully.\n */\n@@ -167,7 +179,8 @@ MappedBuffer::~MappedBuffer()\n */\n MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)\n {\n-\tmaps_.reserve(buffer->planes().size());\n+\tASSERT(!buffer->planes().empty());\n+\tplanes_.reserve(buffer->planes().size());\n \n \tint mmapFlags = 0;\n \n@@ -177,17 +190,53 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)\n \tif (flags & MapFlag::Write)\n \t\tmmapFlags |= PROT_WRITE;\n \n+\tstruct MappedBufferInfo {\n+\t\tuint8_t *address = nullptr;\n+\t\tsize_t mapLength = 0;\n+\t\tsize_t dmabufLength = 0;\n+\t};\n+\tstd::map<int, MappedBufferInfo> mappedBuffers;\n+\tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n+\t\tconst int fd = plane.fd.fd();\n+\t\tif (mappedBuffers.find(fd) == mappedBuffers.end()) {\n+\t\t\tconst size_t length = lseek(fd, 0, SEEK_END);\n+\t\t\tmappedBuffers[fd] = MappedBufferInfo{ nullptr, 0, length };\n+\t\t}\n+\n+\t\tconst size_t length = mappedBuffers[fd].dmabufLength;\n+\n+\t\tif (plane.offset > length ||\n+\t\t plane.offset + plane.length > length) {\n+\t\t\tLOG(Buffer, Fatal) << \"plane is out of buffer: \"\n+\t\t\t\t\t << \"buffer length=\" << length\n+\t\t\t\t\t << \", plane offset=\" << plane.offset\n+\t\t\t\t\t << \", plane length=\" << plane.length;\n+\t\t\treturn;\n+\t\t}\n+\t\tsize_t &mapLength = mappedBuffers[fd].mapLength;\n+\t\tmapLength = std::max(mapLength,\n+\t\t\t\t static_cast<size_t>(plane.offset + plane.length));\n+\t}\n+\n \tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n-\t\tvoid *address = mmap(nullptr, plane.length, mmapFlags,\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\t\t\t << strerror(-error_);\n-\t\t\tbreak;\n+\t\tconst int fd = plane.fd.fd();\n+\t\tauto &info = mappedBuffers[fd];\n+\t\tif (!info.address) {\n+\t\t\tinfo.address =\n+\t\t\t\tstatic_cast<uint8_t *>(\n+\t\t\t\t\tmmap(nullptr, info.mapLength, mmapFlags,\n+\t\t\t\t\t MAP_SHARED, fd, 0));\n+\t\t\tif (info.address == MAP_FAILED) {\n+\t\t\t\terror_ = -errno;\n+\t\t\t\tLOG(Buffer, Error) << \"Failed to mmap plane: \"\n+\t\t\t\t\t\t << strerror(-error_);\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\tmaps_.emplace_back(info.address, info.mapLength);\n \t\t}\n \n-\t\tmaps_.emplace_back(static_cast<uint8_t *>(address), plane.length);\n+\t\tplanes_.emplace_back(info.address + plane.offset, plane.length);\n \t}\n }\n \n", "prefixes": [ "libcamera-devel", "RFC", "v2", "03/10" ] }