Show a patch.

GET /api/1.1/patches/13259/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13259,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13259/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13259/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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-3-kieran.bingham@ideasonboard.com>",
    "date": "2021-08-09T13:29:28",
    "name": "[libcamera-devel,v3,2/3] libcamera: Give MappedFrameBuffer its own implementation",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "7133b61cde56dee4209a32e3d44ccfb3f86af4f5",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/1.1/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13259/mbox/",
    "series": [
        {
            "id": 2321,
            "url": "https://patchwork.libcamera.org/api/1.1/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/13259/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13259/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 EC3E6C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  9 Aug 2021 13:29:37 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5C18368855;\n\tMon,  9 Aug 2021 15:29:36 +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 04EA960269\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 A0FA94A1;\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=\"rpGhScOT\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628515773;\n\tbh=Fu0NlCAT9MHZKEb6kLV3KSvWeBaZ650is12SCtVSmUA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=rpGhScOTJZbIMowIQcVaQDENBkGka0f8vhi//2M279C+REWMrwmTCLmTfUndcdl3S\n\tmMPX3PRMmPIxB3AtKiPnFz1gF1d+h/TZUAGHi6M+rocLN4x6Z3OooabdPZwk9qgRdL\n\tg2Tej4tTLglPyuVpA7RBkhJWeRiZ2mpDDcKz6ufY=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Mon,  9 Aug 2021 14:29:28 +0100",
        "Message-Id": "<20210809132929.1824114-3-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 2/3] libcamera: Give MappedFrameBuffer\n\tits own implementation",
        "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": "The MappedFrameBuffer is a convenience feature which sits on top of the\nFrameBuffer and facilitates mapping it to CPU accessible memory with\nmmap.\n\nThis implementation is internal and currently sits in the same internal\nfiles as the internal FrameBuffer, thus exposing those internals to\nusers of the MappedFramebuffer implementation.\n\nMove the MappedFrameBuffer and MappedBuffer implementation to its own\nimplementation files, and fix the sources throughout to use that\naccordingly.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/framebuffer.h      |  36 ----\n .../libcamera/internal/mapped_framebuffer.h   |  52 ++++++\n include/libcamera/internal/meson.build        |   1 +\n src/android/camera_device.h                   |   2 -\n src/android/camera_stream.cpp                 |   2 +\n src/android/camera_stream.h                   |   2 -\n src/android/jpeg/encoder_libjpeg.cpp          |   1 +\n src/android/jpeg/encoder_libjpeg.h            |   1 -\n src/android/jpeg/post_processor_jpeg.h        |   2 -\n src/android/jpeg/thumbnailer.cpp              |   2 +\n src/android/jpeg/thumbnailer.h                |   2 +-\n src/android/mm/generic_camera_buffer.cpp      |   3 +-\n src/android/post_processor.h                  |   2 -\n src/android/yuv/post_processor_yuv.cpp        |   1 +\n src/ipa/ipu3/ipu3.cpp                         |   2 +-\n src/ipa/raspberrypi/raspberrypi.cpp           |   2 +-\n src/libcamera/framebuffer.cpp                 | 145 ---------------\n src/libcamera/mapped_framebuffer.cpp          | 171 ++++++++++++++++++\n src/libcamera/meson.build                     |   1 +\n test/mapped-buffer.cpp                        |   2 +-\n 20 files changed, 237 insertions(+), 195 deletions(-)\n create mode 100644 include/libcamera/internal/mapped_framebuffer.h\n create mode 100644 src/libcamera/mapped_framebuffer.cpp",
    "diff": "diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\nindex 8c187adf70c7..1352578a6cfb 100644\n--- a/include/libcamera/internal/framebuffer.h\n+++ b/include/libcamera/internal/framebuffer.h\n@@ -7,46 +7,10 @@\n #ifndef __LIBCAMERA_INTERNAL_FRAMEBUFFER_H__\n #define __LIBCAMERA_INTERNAL_FRAMEBUFFER_H__\n \n-#include <sys/mman.h>\n-#include <vector>\n-\n-#include <libcamera/base/class.h>\n-#include <libcamera/base/span.h>\n-\n #include <libcamera/framebuffer.h>\n \n namespace libcamera {\n \n-class MappedBuffer\n-{\n-public:\n-\tusing Plane = Span<uint8_t>;\n-\n-\t~MappedBuffer();\n-\n-\tMappedBuffer(MappedBuffer &&other);\n-\tMappedBuffer &operator=(MappedBuffer &&other);\n-\n-\tbool isValid() const { return error_ == 0; }\n-\tint error() const { return error_; }\n-\tconst std::vector<Plane> &maps() const { return maps_; }\n-\n-protected:\n-\tMappedBuffer();\n-\n-\tint error_;\n-\tstd::vector<Plane> maps_;\n-\n-private:\n-\tLIBCAMERA_DISABLE_COPY(MappedBuffer)\n-};\n-\n-class MappedFrameBuffer : public MappedBuffer\n-{\n-public:\n-\tMappedFrameBuffer(const FrameBuffer *buffer, int flags);\n-};\n-\n class FrameBuffer::Private : public Extensible::Private\n {\n \tLIBCAMERA_DECLARE_PUBLIC(FrameBuffer)\ndiff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h\nnew file mode 100644\nindex 000000000000..41e587364260\n--- /dev/null\n+++ b/include/libcamera/internal/mapped_framebuffer.h\n@@ -0,0 +1,52 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * mapped_framebuffer.h - Frame buffer memory mapping support\n+ */\n+#ifndef __LIBCAMERA_INTERNAL_MAPPED_FRAMEBUFFER_H__\n+#define __LIBCAMERA_INTERNAL_MAPPED_FRAMEBUFFER_H__\n+\n+#include <sys/mman.h>\n+#include <vector>\n+\n+#include <libcamera/base/class.h>\n+#include <libcamera/base/span.h>\n+\n+#include <libcamera/framebuffer.h>\n+\n+namespace libcamera {\n+\n+class MappedBuffer\n+{\n+public:\n+\tusing Plane = Span<uint8_t>;\n+\n+\t~MappedBuffer();\n+\n+\tMappedBuffer(MappedBuffer &&other);\n+\tMappedBuffer &operator=(MappedBuffer &&other);\n+\n+\tbool isValid() const { return error_ == 0; }\n+\tint error() const { return error_; }\n+\tconst std::vector<Plane> &maps() const { return maps_; }\n+\n+protected:\n+\tMappedBuffer();\n+\n+\tint error_;\n+\tstd::vector<Plane> maps_;\n+\n+private:\n+\tLIBCAMERA_DISABLE_COPY(MappedBuffer)\n+};\n+\n+class MappedFrameBuffer : public MappedBuffer\n+{\n+public:\n+\tMappedFrameBuffer(const FrameBuffer *buffer, int flags);\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_INTERNAL_MAPPED_FRAMEBUFFER_H__ */\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex dac1a2d36fa8..665fd6de4ed3 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -28,6 +28,7 @@ libcamera_internal_headers = files([\n     'ipa_module.h',\n     'ipa_proxy.h',\n     'ipc_unixsocket.h',\n+    'mapped_framebuffer.h',\n     'media_device.h',\n     'media_object.h',\n     'pipeline_handler.h',\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 089a6204605e..dd9aebba7553 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -24,8 +24,6 @@\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n-#include \"libcamera/internal/framebuffer.h\"\n-\n #include \"camera_capabilities.h\"\n #include \"camera_metadata.h\"\n #include \"camera_stream.h\"\ndiff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\nindex bf4a7b41a70a..61b441830e18 100644\n--- a/src/android/camera_stream.cpp\n+++ b/src/android/camera_stream.cpp\n@@ -7,6 +7,8 @@\n \n #include \"camera_stream.h\"\n \n+#include <sys/mman.h>\n+\n #include \"camera_buffer.h\"\n #include \"camera_device.h\"\n #include \"camera_metadata.h\"\ndiff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\nindex 629d9e00e08d..2dab6c3a37d1 100644\n--- a/src/android/camera_stream.h\n+++ b/src/android/camera_stream.h\n@@ -19,8 +19,6 @@\n #include <libcamera/geometry.h>\n #include <libcamera/pixel_format.h>\n \n-#include \"libcamera/internal/framebuffer.h\"\n-\n class CameraDevice;\n class CameraMetadata;\n class PostProcessor;\ndiff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex e6358ca9466f..372018d2207f 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -23,6 +23,7 @@\n #include <libcamera/pixel_format.h>\n \n #include \"libcamera/internal/formats.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n using namespace libcamera;\n \ndiff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\nindex 14bf89223982..61fbd1a69278 100644\n--- a/src/android/jpeg/encoder_libjpeg.h\n+++ b/src/android/jpeg/encoder_libjpeg.h\n@@ -10,7 +10,6 @@\n #include \"encoder.h\"\n \n #include \"libcamera/internal/formats.h\"\n-#include \"libcamera/internal/framebuffer.h\"\n \n #include <jpeglib.h>\n \ndiff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h\nindex 5c399be9eb6a..6fd3102229ab 100644\n--- a/src/android/jpeg/post_processor_jpeg.h\n+++ b/src/android/jpeg/post_processor_jpeg.h\n@@ -13,8 +13,6 @@\n \n #include <libcamera/geometry.h>\n \n-#include \"libcamera/internal/framebuffer.h\"\n-\n class CameraDevice;\n \n class PostProcessorJpeg : public PostProcessor\ndiff --git a/src/android/jpeg/thumbnailer.cpp b/src/android/jpeg/thumbnailer.cpp\nindex 5cb00744a688..535e2cece914 100644\n--- a/src/android/jpeg/thumbnailer.cpp\n+++ b/src/android/jpeg/thumbnailer.cpp\n@@ -11,6 +11,8 @@\n \n #include <libcamera/formats.h>\n \n+#include \"libcamera/internal/mapped_framebuffer.h\"\n+\n using namespace libcamera;\n \n LOG_DEFINE_CATEGORY(Thumbnailer)\ndiff --git a/src/android/jpeg/thumbnailer.h b/src/android/jpeg/thumbnailer.h\nindex 68cbf74329a9..4d086c4943b0 100644\n--- a/src/android/jpeg/thumbnailer.h\n+++ b/src/android/jpeg/thumbnailer.h\n@@ -7,10 +7,10 @@\n #ifndef __ANDROID_JPEG_THUMBNAILER_H__\n #define __ANDROID_JPEG_THUMBNAILER_H__\n \n+#include <libcamera/framebuffer.h>\n #include <libcamera/geometry.h>\n \n #include \"libcamera/internal/formats.h\"\n-#include \"libcamera/internal/framebuffer.h\"\n \n class Thumbnailer\n {\ndiff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\nindex 2a4b77ea5236..b3af194c21dd 100644\n--- a/src/android/mm/generic_camera_buffer.cpp\n+++ b/src/android/mm/generic_camera_buffer.cpp\n@@ -7,11 +7,12 @@\n \n #include \"../camera_buffer.h\"\n \n+#include <sys/mman.h>\n #include <unistd.h>\n \n #include <libcamera/base/log.h>\n \n-#include \"libcamera/internal/framebuffer.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n using namespace libcamera;\n \ndiff --git a/src/android/post_processor.h b/src/android/post_processor.h\nindex 689f85d9d3b8..ab2b2c606fd0 100644\n--- a/src/android/post_processor.h\n+++ b/src/android/post_processor.h\n@@ -10,8 +10,6 @@\n #include <libcamera/framebuffer.h>\n #include <libcamera/stream.h>\n \n-#include \"libcamera/internal/framebuffer.h\"\n-\n #include \"camera_buffer.h\"\n \n class CameraMetadata;\ndiff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp\nindex 772e805b32cc..509d4244d614 100644\n--- a/src/android/yuv/post_processor_yuv.cpp\n+++ b/src/android/yuv/post_processor_yuv.cpp\n@@ -16,6 +16,7 @@\n #include <libcamera/pixel_format.h>\n \n #include \"libcamera/internal/formats.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n using namespace libcamera;\n \ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 71698d36e50f..2647bf2f3b96 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -20,7 +20,7 @@\n #include <libcamera/ipa/ipu3_ipa_interface.h>\n #include <libcamera/request.h>\n \n-#include \"libcamera/internal/framebuffer.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n #include \"ipu3_agc.h\"\n #include \"ipu3_awb.h\"\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 48e11c699f29..76f67dd4567a 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -28,7 +28,7 @@\n #include <libcamera/ipa/raspberrypi_ipa_interface.h>\n #include <libcamera/request.h>\n \n-#include \"libcamera/internal/framebuffer.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n #include \"agc_algorithm.hpp\"\n #include \"agc_status.h\"\ndiff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\nindex a59e93fbdf91..3d98affb20f9 100644\n--- a/src/libcamera/framebuffer.cpp\n+++ b/src/libcamera/framebuffer.cpp\n@@ -251,149 +251,4 @@ Request *FrameBuffer::request() const\n  * indicate that the metadata is invalid.\n  */\n \n-/**\n- * \\class MappedBuffer\n- * \\brief Provide an interface to support managing memory mapped buffers\n- *\n- * The MappedBuffer interface provides access to a set of MappedPlanes which\n- * are available for access by the CPU.\n- *\n- * This class is not meant to be constructed directly, but instead derived\n- * classes should be used to implement the correct mapping of a source buffer.\n- *\n- * This allows treating CPU accessible memory through a generic interface\n- * regardless of whether it originates from a libcamera FrameBuffer or other\n- * source.\n- */\n-\n-/**\n- * \\typedef MappedBuffer::Plane\n- * \\brief A mapped region of memory accessible to the CPU\n- *\n- * The MappedBuffer::Plane uses the Span interface to describe the mapped memory\n- * region.\n- */\n-\n-/**\n- * \\brief Construct an empty MappedBuffer\n- */\n-MappedBuffer::MappedBuffer()\n-\t: error_(0)\n-{\n-}\n-\n-/**\n- * \\brief Move constructor, construct the MappedBuffer with the contents of \\a\n- * other using move semantics\n- * \\param[in] other The other MappedBuffer\n- *\n- * Moving a MappedBuffer moves the mappings contained in the \\a other to the new\n- * MappedBuffer and invalidates the \\a other.\n- *\n- * No mappings are unmapped or destroyed in this process.\n- */\n-MappedBuffer::MappedBuffer(MappedBuffer &&other)\n-{\n-\t*this = std::move(other);\n-}\n-\n-/**\n- * \\brief Move assignment operator, replace the mappings with those of \\a other\n-* \\param[in] other The other MappedBuffer\n- *\n- * Moving a MappedBuffer moves the mappings contained in the \\a other to the new\n- * MappedBuffer and invalidates the \\a other.\n- *\n- * No mappings are unmapped or destroyed in this process.\n- */\n-MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n-{\n-\terror_ = other.error_;\n-\tmaps_ = std::move(other.maps_);\n-\tother.error_ = -ENOENT;\n-\n-\treturn *this;\n-}\n-\n-MappedBuffer::~MappedBuffer()\n-{\n-\tfor (Plane &map : maps_)\n-\t\tmunmap(map.data(), map.size());\n-}\n-\n-/**\n- * \\fn MappedBuffer::isValid()\n- * \\brief Check if the MappedBuffer instance is valid\n- * \\return True if the MappedBuffer has valid mappings, false otherwise\n- */\n-\n-/**\n- * \\fn MappedBuffer::error()\n- * \\brief Retrieve the map error status\n- *\n- * This function retrieves the error status from the MappedBuffer.\n- * The error status is a negative number as defined by errno.h. If\n- * no error occurred, this function returns 0.\n- *\n- * \\return The map error code\n- */\n-\n-/**\n- * \\fn MappedBuffer::maps()\n- * \\brief Retrieve the mapped planes\n- *\n- * This function retrieves the successfully mapped planes stored as a vector\n- * of Span<uint8_t> to provide access to the mapped memory.\n- *\n- * \\return A vector of the mapped planes\n- */\n-\n-/**\n- * \\var MappedBuffer::error_\n- * \\brief Stores the error value if present\n- *\n- * MappedBuffer derived classes shall set this to a negative value as defined\n- * by errno.h if an error occured during the mapping process.\n- */\n-\n-/**\n- * \\var MappedBuffer::maps_\n- * \\brief Stores the internal mapped planes\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-\n-/**\n- * \\class MappedFrameBuffer\n- * \\brief Map a FrameBuffer using the MappedBuffer interface\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- */\n-MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, int flags)\n-{\n-\tmaps_.reserve(buffer->planes().size());\n-\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}\n-}\n-\n } /* namespace libcamera */\ndiff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp\nnew file mode 100644\nindex 000000000000..0e30fc542154\n--- /dev/null\n+++ b/src/libcamera/mapped_framebuffer.cpp\n@@ -0,0 +1,171 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * mapped_framebuffer.cpp - Mapped Framebuffer support\n+ */\n+\n+#include \"libcamera/internal/mapped_framebuffer.h\"\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>\n+\n+/**\n+ * \\file libcamera/internal/mapped_framebuffer.h\n+ * \\brief Frame buffer memory mapping support\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(Buffer)\n+\n+/**\n+ * \\class MappedBuffer\n+ * \\brief Provide an interface to support managing memory mapped buffers\n+ *\n+ * The MappedBuffer interface provides access to a set of MappedPlanes which\n+ * are available for access by the CPU.\n+ *\n+ * This class is not meant to be constructed directly, but instead derived\n+ * classes should be used to implement the correct mapping of a source buffer.\n+ *\n+ * This allows treating CPU accessible memory through a generic interface\n+ * regardless of whether it originates from a libcamera FrameBuffer or other\n+ * source.\n+ */\n+\n+/**\n+ * \\typedef MappedBuffer::Plane\n+ * \\brief A mapped region of memory accessible to the CPU\n+ *\n+ * The MappedBuffer::Plane uses the Span interface to describe the mapped memory\n+ * region.\n+ */\n+\n+/**\n+ * \\brief Construct an empty MappedBuffer\n+ */\n+MappedBuffer::MappedBuffer()\n+\t: error_(0)\n+{\n+}\n+\n+/**\n+ * \\brief Move constructor, construct the MappedBuffer with the contents of \\a\n+ * other using move semantics\n+ * \\param[in] other The other MappedBuffer\n+ *\n+ * Moving a MappedBuffer moves the mappings contained in the \\a other to the new\n+ * MappedBuffer and invalidates the \\a other.\n+ *\n+ * No mappings are unmapped or destroyed in this process.\n+ */\n+MappedBuffer::MappedBuffer(MappedBuffer &&other)\n+{\n+\t*this = std::move(other);\n+}\n+\n+/**\n+ * \\brief Move assignment operator, replace the mappings with those of \\a other\n+* \\param[in] other The other MappedBuffer\n+ *\n+ * Moving a MappedBuffer moves the mappings contained in the \\a other to the new\n+ * MappedBuffer and invalidates the \\a other.\n+ *\n+ * No mappings are unmapped or destroyed in this process.\n+ */\n+MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n+{\n+\terror_ = other.error_;\n+\tmaps_ = std::move(other.maps_);\n+\tother.error_ = -ENOENT;\n+\n+\treturn *this;\n+}\n+\n+MappedBuffer::~MappedBuffer()\n+{\n+\tfor (Plane &map : maps_)\n+\t\tmunmap(map.data(), map.size());\n+}\n+\n+/**\n+ * \\fn MappedBuffer::isValid()\n+ * \\brief Check if the MappedBuffer instance is valid\n+ * \\return True if the MappedBuffer has valid mappings, false otherwise\n+ */\n+\n+/**\n+ * \\fn MappedBuffer::error()\n+ * \\brief Retrieve the map error status\n+ *\n+ * This function retrieves the error status from the MappedBuffer.\n+ * The error status is a negative number as defined by errno.h. If\n+ * no error occurred, this function returns 0.\n+ *\n+ * \\return The map error code\n+ */\n+\n+/**\n+ * \\fn MappedBuffer::maps()\n+ * \\brief Retrieve the mapped planes\n+ *\n+ * This function retrieves the successfully mapped planes stored as a vector\n+ * of Span<uint8_t> to provide access to the mapped memory.\n+ *\n+ * \\return A vector of the mapped planes\n+ */\n+\n+/**\n+ * \\var MappedBuffer::error_\n+ * \\brief Stores the error value if present\n+ *\n+ * MappedBuffer derived classes shall set this to a negative value as defined\n+ * by errno.h if an error occured during the mapping process.\n+ */\n+\n+/**\n+ * \\var MappedBuffer::maps_\n+ * \\brief Stores the internal mapped planes\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+\n+/**\n+ * \\class MappedFrameBuffer\n+ * \\brief Map a FrameBuffer using the MappedBuffer interface\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+ */\n+MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, int flags)\n+{\n+\tmaps_.reserve(buffer->planes().size());\n+\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}\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 4f08580157f9..e9230b983aeb 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -28,6 +28,7 @@ libcamera_sources = files([\n     'ipc_pipe.cpp',\n     'ipc_pipe_unixsocket.cpp',\n     'ipc_unixsocket.cpp',\n+    'mapped_framebuffer.cpp',\n     'media_device.cpp',\n     'media_object.cpp',\n     'pipeline_handler.cpp',\ndiff --git a/test/mapped-buffer.cpp b/test/mapped-buffer.cpp\nindex c9479194cb68..a3d1511b74ce 100644\n--- a/test/mapped-buffer.cpp\n+++ b/test/mapped-buffer.cpp\n@@ -9,7 +9,7 @@\n \n #include <libcamera/framebuffer_allocator.h>\n \n-#include \"libcamera/internal/framebuffer.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n #include \"camera_test.h\"\n #include \"test.h\"\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "2/3"
    ]
}