Show a patch.

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

{
    "id": 13381,
    "url": "https://patchwork.libcamera.org/api/patches/13381/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13381/",
    "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": "<20210818002208.13631-1-laurent.pinchart@ideasonboard.com>",
    "date": "2021-08-18T00:22:08",
    "name": "[libcamera-devel] qcam: Replace MappedBuffer with Span<uint8_t>",
    "commit_ref": "6f09680b256025923cedd50b5fd1a878af2dffd4",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "6b0602b3c75477206940b633de07dd2ea715d998",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13381/mbox/",
    "series": [
        {
            "id": 2367,
            "url": "https://patchwork.libcamera.org/api/series/2367/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2367",
            "date": "2021-08-18T00:22:08",
            "name": "[libcamera-devel] qcam: Replace MappedBuffer with Span<uint8_t>",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2367/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13381/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13381/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 45FF1BD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 Aug 2021 00:22:21 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A61CF6025D;\n\tWed, 18 Aug 2021 02:22:20 +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 447C86025D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Aug 2021 02:22:19 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C62B5499\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Aug 2021 02:22: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=\"rVDKKH0+\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629246138;\n\tbh=KR97woK/c+mtO4HHNAxOIlNk+fHe+8S2FCc5guFi148=;\n\th=From:To:Subject:Date:From;\n\tb=rVDKKH0+YrqmC2Q1V2EVKUroI84o1hXN7os0YVW24tYvXU+hCUstjyKaY7RI/IxRP\n\tRqi7JfID4mJfjD++1YMphMTty4mP/Qtbv3KsOxo7tN0+BRahAs78h7kFT3/fKMstvJ\n\tlypRob3r+jvhAcVb1974efk8HCXvDXYgIbke2NjM=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 18 Aug 2021 03:22:08 +0300",
        "Message-Id": "<20210818002208.13631-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.31.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH] qcam: Replace MappedBuffer with\n\tSpan<uint8_t>",
        "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 MappedBuffer structure is a custom container that binds a data\npointer with a length. This is exactly what Span is. Use it instead.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/qcam/main_window.cpp   | 17 +++++++++--------\n src/qcam/main_window.h     |  2 +-\n src/qcam/viewfinder.h      |  9 +++------\n src/qcam/viewfinder_gl.cpp |  5 +++--\n src/qcam/viewfinder_gl.h   |  2 +-\n src/qcam/viewfinder_qt.cpp |  5 +++--\n src/qcam/viewfinder_qt.h   |  2 +-\n 7 files changed, 21 insertions(+), 21 deletions(-)",
    "diff": "diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 39d034de6bb2..1adaae60d83b 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -474,7 +474,8 @@ int MainWindow::startCapture()\n \t\t\tconst FrameBuffer::Plane &plane = buffer->planes().front();\n \t\t\tvoid *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n \t\t\t\t\t    plane.fd.fd(), 0);\n-\t\t\tmappedBuffers_[buffer.get()] = { memory, plane.length };\n+\t\t\tmappedBuffers_[buffer.get()] = { static_cast<uint8_t *>(memory),\n+\t\t\t\t\t\t\t plane.length };\n \n \t\t\t/* Store buffers on the free list. */\n \t\t\tfreeBuffers_[stream].enqueue(buffer.get());\n@@ -537,8 +538,8 @@ error:\n \trequests_.clear();\n \n \tfor (auto &iter : mappedBuffers_) {\n-\t\tconst MappedBuffer &buffer = iter.second;\n-\t\tmunmap(buffer.memory, buffer.size);\n+\t\tconst Span<uint8_t> &buffer = iter.second;\n+\t\tmunmap(buffer.data(), buffer.size());\n \t}\n \tmappedBuffers_.clear();\n \n@@ -573,8 +574,8 @@ void MainWindow::stopCapture()\n \tcamera_->requestCompleted.disconnect(this, &MainWindow::requestComplete);\n \n \tfor (auto &iter : mappedBuffers_) {\n-\t\tconst MappedBuffer &buffer = iter.second;\n-\t\tmunmap(buffer.memory, buffer.size);\n+\t\tconst Span<uint8_t> &buffer = iter.second;\n+\t\tmunmap(buffer.data(), buffer.size());\n \t}\n \tmappedBuffers_.clear();\n \n@@ -673,10 +674,10 @@ void MainWindow::processRaw(FrameBuffer *buffer,\n \t\t\t\t\t\t\t\"DNG Files (*.dng)\");\n \n \tif (!filename.isEmpty()) {\n-\t\tconst MappedBuffer &mapped = mappedBuffers_[buffer];\n+\t\tconst Span<uint8_t> &mapped = mappedBuffers_[buffer];\n \t\tDNGWriter::write(filename.toStdString().c_str(), camera_.get(),\n \t\t\t\t rawStream_->configuration(), metadata, buffer,\n-\t\t\t\t mapped.memory);\n+\t\t\t\t mapped.data());\n \t}\n #endif\n \n@@ -753,7 +754,7 @@ void MainWindow::processViewfinder(FrameBuffer *buffer)\n \t\t<< \"fps:\" << Qt::fixed << qSetRealNumberPrecision(2) << fps;\n \n \t/* Render the frame on the viewfinder. */\n-\tviewfinder_->render(buffer, &mappedBuffers_[buffer]);\n+\tviewfinder_->render(buffer, mappedBuffers_[buffer]);\n }\n \n void MainWindow::queueRequest(FrameBuffer *buffer)\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 85d56ce49abe..6788de8ddde9 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -106,7 +106,7 @@ private:\n \tFrameBufferAllocator *allocator_;\n \n \tstd::unique_ptr<CameraConfiguration> config_;\n-\tstd::map<FrameBuffer *, MappedBuffer> mappedBuffers_;\n+\tstd::map<FrameBuffer *, Span<uint8_t>> mappedBuffers_;\n \n \t/* Capture state, buffers queue and statistics */\n \tbool isCapturing_;\ndiff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h\nindex 46747c227d0c..42d40f1f33f0 100644\n--- a/src/qcam/viewfinder.h\n+++ b/src/qcam/viewfinder.h\n@@ -11,14 +11,11 @@\n #include <QList>\n #include <QSize>\n \n+#include <libcamera/base/span.h>\n+\n #include <libcamera/formats.h>\n #include <libcamera/framebuffer.h>\n \n-struct MappedBuffer {\n-\tvoid *memory;\n-\tsize_t size;\n-};\n-\n class ViewFinder\n {\n public:\n@@ -27,7 +24,7 @@ public:\n \tvirtual const QList<libcamera::PixelFormat> &nativeFormats() const = 0;\n \n \tvirtual int setFormat(const libcamera::PixelFormat &format, const QSize &size) = 0;\n-\tvirtual void render(libcamera::FrameBuffer *buffer, MappedBuffer *map) = 0;\n+\tvirtual void render(libcamera::FrameBuffer *buffer, libcamera::Span<uint8_t> mem) = 0;\n \tvirtual void stop() = 0;\n \n \tvirtual QImage getCurrentImage() = 0;\ndiff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp\nindex add87db88207..40226601f9fd 100644\n--- a/src/qcam/viewfinder_gl.cpp\n+++ b/src/qcam/viewfinder_gl.cpp\n@@ -110,7 +110,8 @@ QImage ViewFinderGL::getCurrentImage()\n \treturn grabFramebuffer();\n }\n \n-void ViewFinderGL::render(libcamera::FrameBuffer *buffer, MappedBuffer *map)\n+void ViewFinderGL::render(libcamera::FrameBuffer *buffer,\n+\t\t\t  libcamera::Span<uint8_t> mem)\n {\n \tif (buffer->planes().size() != 1) {\n \t\tqWarning() << \"Multi-planar buffers are not supported\";\n@@ -120,7 +121,7 @@ void ViewFinderGL::render(libcamera::FrameBuffer *buffer, MappedBuffer *map)\n \tif (buffer_)\n \t\trenderComplete(buffer_);\n \n-\tdata_ = static_cast<unsigned char *>(map->memory);\n+\tdata_ = mem.data();\n \t/*\n \t * \\todo Get the stride from the buffer instead of computing it naively\n \t */\ndiff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h\nindex 4a0f8ca58f29..3334549e0be4 100644\n--- a/src/qcam/viewfinder_gl.h\n+++ b/src/qcam/viewfinder_gl.h\n@@ -39,7 +39,7 @@ public:\n \tconst QList<libcamera::PixelFormat> &nativeFormats() const override;\n \n \tint setFormat(const libcamera::PixelFormat &format, const QSize &size) override;\n-\tvoid render(libcamera::FrameBuffer *buffer, MappedBuffer *map) override;\n+\tvoid render(libcamera::FrameBuffer *buffer, libcamera::Span<uint8_t> mem) override;\n \tvoid stop() override;\n \n \tQImage getCurrentImage() override;\ndiff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp\nindex e436714c6bdb..efa1d412584b 100644\n--- a/src/qcam/viewfinder_qt.cpp\n+++ b/src/qcam/viewfinder_qt.cpp\n@@ -78,14 +78,15 @@ int ViewFinderQt::setFormat(const libcamera::PixelFormat &format,\n \treturn 0;\n }\n \n-void ViewFinderQt::render(libcamera::FrameBuffer *buffer, MappedBuffer *map)\n+void ViewFinderQt::render(libcamera::FrameBuffer *buffer,\n+\t\t\t  libcamera::Span<uint8_t> mem)\n {\n \tif (buffer->planes().size() != 1) {\n \t\tqWarning() << \"Multi-planar buffers are not supported\";\n \t\treturn;\n \t}\n \n-\tunsigned char *memory = static_cast<unsigned char *>(map->memory);\n+\tunsigned char *memory = mem.data();\n \tsize_t size = buffer->metadata().planes[0].bytesused;\n \n \t{\ndiff --git a/src/qcam/viewfinder_qt.h b/src/qcam/viewfinder_qt.h\nindex 501c72a70dec..1a569b9cee6e 100644\n--- a/src/qcam/viewfinder_qt.h\n+++ b/src/qcam/viewfinder_qt.h\n@@ -32,7 +32,7 @@ public:\n \tconst QList<libcamera::PixelFormat> &nativeFormats() const override;\n \n \tint setFormat(const libcamera::PixelFormat &format, const QSize &size) override;\n-\tvoid render(libcamera::FrameBuffer *buffer, MappedBuffer *map) override;\n+\tvoid render(libcamera::FrameBuffer *buffer, libcamera::Span<uint8_t> mem) override;\n \tvoid stop() override;\n \n \tQImage getCurrentImage() override;\n",
    "prefixes": [
        "libcamera-devel"
    ]
}