Patch Detail
Show a patch.
GET /api/patches/13260/?format=api
{ "id": 13260, "url": "https://patchwork.libcamera.org/api/patches/13260/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13260/", "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": "<20210809132929.1824114-4-kieran.bingham@ideasonboard.com>", "date": "2021-08-09T13:29:29", "name": "[libcamera-devel,v3,3/3] libcamera: MappedFrameBuffer: Use typed Flags<MapFlags>", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "ee39408a58994205cf6a200ccbbb529836fd2cf7", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13260/mbox/", "series": [ { "id": 2321, "url": "https://patchwork.libcamera.org/api/series/2321/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2321", "date": "2021-08-09T13:29:26", "name": "MappedFrameBuffer: Move its own component.", "version": 3, "mbox": "https://patchwork.libcamera.org/series/2321/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13260/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13260/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 72BF5C3240\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 9 Aug 2021 13:29:38 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 10E2A6888F;\n\tMon, 9 Aug 2021 15:29:37 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 364F6687EB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 9 Aug 2021 15:29:34 +0200 (CEST)", "from Monstersaurus.local\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 E4038466;\n\tMon, 9 Aug 2021 15:29:33 +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=\"MyxhvDJl\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628515774;\n\tbh=iUclvwjcSIfmMFqvje7WD4iCW7ht+/NxdX9uVklz3uA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=MyxhvDJluQJpd7zIhuTEAxp62z7ouySlNu+2fug/ZhR/xLuf+Gj32ZXqyQQGgvtg0\n\tN14hNdB5HNF6bh6L4KPvZF1NXcoVARN2SeDcvCqi4KLha19cU7p2to1QRG/AgnqckU\n\ttJfkBK5cslun6LFx5VRZOCXJWA3AlBye1qU9ACPQ=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "To": "libcamera devel <libcamera-devel@lists.libcamera.org>", "Date": "Mon, 9 Aug 2021 14:29:29 +0100", "Message-Id": "<20210809132929.1824114-4-kieran.bingham@ideasonboard.com>", "X-Mailer": "git-send-email 2.30.2", "In-Reply-To": "<20210809132929.1824114-1-kieran.bingham@ideasonboard.com>", "References": "<20210809132929.1824114-1-kieran.bingham@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 3/3] libcamera: MappedFrameBuffer: Use\n\ttyped Flags<MapFlags>", "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": "Remove the need for callers to reference PROT_READ/PROT_WRITE directly\nfrom <sys/mman.h> by instead exposing the Read/Write mapping options as\nflags from the MappedFrameBuffer class itself.\n\nWhile here, introduce the <stdint.h> header which is required for the\nuint8_t as part of the Plane.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv2\n - Use fully scoped enum class\n - Swap MapMode and MapModes\n - s/mmap_flags/mmapFlags/\n - Remove and fix documentation regarding the modes\n - add LIBCAMERA_FLAGS_ENABLE_OPERATORS()\n\nv3:\n - Remove no longer necessary sys/mman.h inclusions throughout\n - fix documentation\n - rename MapMode as MapFlag and MapModes as MapFlags\n---\n .../libcamera/internal/mapped_framebuffer.h | 15 ++++++--\n src/android/jpeg/encoder_libjpeg.cpp | 3 +-\n src/android/jpeg/thumbnailer.cpp | 2 +-\n src/android/yuv/post_processor_yuv.cpp | 2 +-\n src/ipa/ipu3/ipu3.cpp | 3 +-\n src/ipa/raspberrypi/raspberrypi.cpp | 3 +-\n src/libcamera/framebuffer.cpp | 1 -\n src/libcamera/mapped_framebuffer.cpp | 34 ++++++++++++++++---\n test/mapped-buffer.cpp | 6 ++--\n 9 files changed, 51 insertions(+), 18 deletions(-)", "diff": "diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h\nindex 41e587364260..68c8a43c35dc 100644\n--- a/include/libcamera/internal/mapped_framebuffer.h\n+++ b/include/libcamera/internal/mapped_framebuffer.h\n@@ -7,10 +7,11 @@\n #ifndef __LIBCAMERA_INTERNAL_MAPPED_FRAMEBUFFER_H__\n #define __LIBCAMERA_INTERNAL_MAPPED_FRAMEBUFFER_H__\n \n-#include <sys/mman.h>\n+#include <stdint.h>\n #include <vector>\n \n #include <libcamera/base/class.h>\n+#include <libcamera/base/flags.h>\n #include <libcamera/base/span.h>\n \n #include <libcamera/framebuffer.h>\n@@ -44,9 +45,19 @@ private:\n class MappedFrameBuffer : public MappedBuffer\n {\n public:\n-\tMappedFrameBuffer(const FrameBuffer *buffer, int flags);\n+\tenum class MapFlag {\n+\t\tRead = 0 << 1,\n+\t\tWrite = 1 << 1,\n+\t\tReadWrite = Read | Write,\n+\t};\n+\n+\tusing MapFlags = Flags<MapFlag>;\n+\n+\tMappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags);\n };\n \n+LIBCAMERA_FLAGS_ENABLE_OPERATORS(MappedFrameBuffer::MapFlag)\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_INTERNAL_MAPPED_FRAMEBUFFER_H__ */\ndiff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex 372018d2207f..a7a636011045 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -12,7 +12,6 @@\n #include <iostream>\n #include <sstream>\n #include <string.h>\n-#include <sys/mman.h>\n #include <unistd.h>\n #include <vector>\n \n@@ -182,7 +181,7 @@ void EncoderLibJpeg::compressNV(Span<const uint8_t> frame)\n int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,\n \t\t\t Span<const uint8_t> exifData, unsigned int quality)\n {\n-\tMappedFrameBuffer frame(&source, PROT_READ);\n+\tMappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);\n \tif (!frame.isValid()) {\n \t\tLOG(JPEG, Error) << \"Failed to map FrameBuffer : \"\n \t\t\t\t << strerror(frame.error());\ndiff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp\nindex 535e2cece914..79d83926af5c 100644\n--- a/src/android/jpeg/thumbnailer.cpp\n+++ b/src/android/jpeg/thumbnailer.cpp\n@@ -41,7 +41,7 @@ void Thumbnailer::createThumbnail(const FrameBuffer &source,\n \t\t\t\t const Size &targetSize,\n \t\t\t\t std::vector<unsigned char> *destination)\n {\n-\tMappedFrameBuffer frame(&source, PROT_READ);\n+\tMappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);\n \tif (!frame.isValid()) {\n \t\tLOG(Thumbnailer, Error)\n \t\t\t<< \"Failed to map FrameBuffer : \"\ndiff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp\nindex 509d4244d614..3e793a580377 100644\n--- a/src/android/yuv/post_processor_yuv.cpp\n+++ b/src/android/yuv/post_processor_yuv.cpp\n@@ -57,7 +57,7 @@ int PostProcessorYuv::process(const FrameBuffer &source,\n \tif (!isValidBuffers(source, *destination))\n \t\treturn -EINVAL;\n \n-\tconst MappedFrameBuffer sourceMapped(&source, PROT_READ);\n+\tconst MappedFrameBuffer sourceMapped(&source, MappedFrameBuffer::MapFlag::Read);\n \tif (!sourceMapped.isValid()) {\n \t\tLOG(YUV, Error) << \"Failed to mmap camera frame buffer\";\n \t\treturn -EINVAL;\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 2647bf2f3b96..10093acdad30 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -6,7 +6,6 @@\n */\n \n #include <stdint.h>\n-#include <sys/mman.h>\n \n #include <linux/intel-ipu3.h>\n #include <linux/v4l2-controls.h>\n@@ -211,7 +210,7 @@ void IPAIPU3::mapBuffers(const std::vector<IPABuffer> &buffers)\n \tfor (const IPABuffer &buffer : buffers) {\n \t\tconst FrameBuffer fb(buffer.planes);\n \t\tbuffers_.emplace(buffer.id,\n-\t\t\t\t MappedFrameBuffer(&fb, PROT_READ | PROT_WRITE));\n+\t\t\t\t MappedFrameBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite));\n \t}\n }\n \ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 76f67dd4567a..592e2fe41617 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -411,7 +411,8 @@ void IPARPi::mapBuffers(const std::vector<IPABuffer> &buffers)\n {\n \tfor (const IPABuffer &buffer : buffers) {\n \t\tconst FrameBuffer fb(buffer.planes);\n-\t\tbuffers_.emplace(buffer.id, MappedFrameBuffer(&fb, PROT_READ | PROT_WRITE));\n+\t\tbuffers_.emplace(buffer.id,\n+\t\t\t\t MappedFrameBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite));\n \t}\n }\n \ndiff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\nindex 3d98affb20f9..2223e24321ca 100644\n--- a/src/libcamera/framebuffer.cpp\n+++ b/src/libcamera/framebuffer.cpp\n@@ -10,7 +10,6 @@\n \n #include <errno.h>\n #include <string.h>\n-#include <sys/mman.h>\n #include <unistd.h>\n \n #include <libcamera/base/log.h>\ndiff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp\nindex 0e30fc542154..5a70c18147f2 100644\n--- a/src/libcamera/mapped_framebuffer.cpp\n+++ b/src/libcamera/mapped_framebuffer.cpp\n@@ -142,21 +142,45 @@ MappedBuffer::~MappedBuffer()\n * \\brief Map a FrameBuffer using the MappedBuffer interface\n */\n \n+/**\n+ * \\enum MappedFrameBuffer::MapFlag\n+ * \\brief Specify the mapping mode for the FrameBuffer\n+ * \\var MappedFrameBuffer::Read\n+ * \\brief Create a read-only mapping\n+ * \\var MappedFrameBuffer::Write\n+ * \\brief Create a write-only mapping\n+ * \\var MappedFrameBuffer::ReadWrite\n+ * \\brief Create a mapping that can be both read and written\n+ */\n+\n+/**\n+ * \\typedef MappedFrameBuffer::MapFlags\n+ * \\brief A bitwise combination of MappedFrameBuffer::MapFlag values\n+ */\n+\n /**\n * \\brief Map all planes of a FrameBuffer\n * \\param[in] buffer FrameBuffer to be mapped\n * \\param[in] flags Protection flags to apply to map\n *\n- * Construct an object to map a frame buffer for CPU access.\n- * The flags are passed directly to mmap and should be either PROT_READ,\n- * PROT_WRITE, or a bitwise-or combination of both.\n+ * Construct an object to map a frame buffer for CPU access. The mapping can be\n+ * made as Read only, Write only or support Read and Write operations by setting\n+ * the MapFlag flags accordingly.\n */\n-MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, int flags)\n+MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)\n {\n \tmaps_.reserve(buffer->planes().size());\n \n+\tint mmapFlags = 0;\n+\n+\tif (flags & MapFlag::Read)\n+\t\tmmapFlags |= PROT_READ;\n+\n+\tif (flags & MapFlag::Write)\n+\t\tmmapFlags |= PROT_WRITE;\n+\n \tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n-\t\tvoid *address = mmap(nullptr, plane.length, flags,\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;\ndiff --git a/test/mapped-buffer.cpp b/test/mapped-buffer.cpp\nindex a3d1511b74ce..97571945cbca 100644\n--- a/test/mapped-buffer.cpp\n+++ b/test/mapped-buffer.cpp\n@@ -71,7 +71,7 @@ protected:\n \t\tconst std::unique_ptr<FrameBuffer> &buffer = allocator_->buffers(stream_).front();\n \t\tstd::vector<MappedBuffer> maps;\n \n-\t\tMappedFrameBuffer map(buffer.get(), PROT_READ);\n+\t\tMappedFrameBuffer map(buffer.get(), MappedFrameBuffer::MapFlag::Read);\n \t\tif (!map.isValid()) {\n \t\t\tcout << \"Failed to successfully map buffer\" << endl;\n \t\t\treturn TestFail;\n@@ -90,13 +90,13 @@ protected:\n \t\t}\n \n \t\t/* Test for multiple successful maps on the same buffer. */\n-\t\tMappedFrameBuffer write_map(buffer.get(), PROT_WRITE);\n+\t\tMappedFrameBuffer write_map(buffer.get(), MappedFrameBuffer::MapFlag::Write);\n \t\tif (!write_map.isValid()) {\n \t\t\tcout << \"Failed to map write buffer\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tMappedFrameBuffer rw_map(buffer.get(), PROT_READ | PROT_WRITE);\n+\t\tMappedFrameBuffer rw_map(buffer.get(), MappedFrameBuffer::MapFlag::ReadWrite);\n \t\tif (!rw_map.isValid()) {\n \t\t\tcout << \"Failed to map RW buffer\" << endl;\n \t\t\treturn TestFail;\n", "prefixes": [ "libcamera-devel", "v3", "3/3" ] }