Show a patch.

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

{
    "id": 19103,
    "url": "https://patchwork.libcamera.org/api/patches/19103/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19103/",
    "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": "<20231006132000.23504-2-naush@raspberrypi.com>",
    "date": "2023-10-06T13:19:41",
    "name": "[libcamera-devel,01/20] pipeline: rpi: Add RequiresMmap flag to RPi::Stream",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "ded0f12f9794eec3d25cd8b6e081d82ceaff4545",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19103/mbox/",
    "series": [
        {
            "id": 4047,
            "url": "https://patchwork.libcamera.org/api/series/4047/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4047",
            "date": "2023-10-06T13:19:40",
            "name": "Raspberry Pi: Preliminary PiSP support",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4047/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19103/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19103/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 0D819C3273\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Oct 2023 13:20:01 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 85AE562961;\n\tFri,  6 Oct 2023 15:20:00 +0200 (CEST)",
            "from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E7F961DDD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Oct 2023 15:19:58 +0200 (CEST)",
            "by mail-wm1-x330.google.com with SMTP id\n\t5b1f17b1804b1-40684f53d11so20300385e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 06 Oct 2023 06:19:58 -0700 (PDT)",
            "from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tm8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.19.55\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 06 Oct 2023 06:19:56 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1696598400;\n\tbh=PTdXqvjKTLp5hBTDZKjThMbqL+JhV6U3F7jqTNlXD4k=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=OpZQuODdQYuF4a7t5pI5T4PZdv8z+YEhKgzJI8pibKqxZBWWFus+hxHH1jvtGRhiH\n\tB4w/aU9Mn+Tm8Rnwkmo4GkWEqPzj0IeDgyp8uKH09W6pa3YuIhbolVSIhGBZ/qsFh5\n\tYpuDrzIje0zQXaY0iz+jhTdKDHS50XK5K0ncrgZiHu0Idc2MhIK65pV+UisS3qy6WL\n\tq+F4p7h6PU4dlrEr678bR9F9zqNMWd4h1GXD73No7teDRJ5PrWEGq/XHqssLX7Q6j3\n\t+rUkJT0Qc/r/+nHI4+MtQ5n1Kl8seu39fW+cDylNFuGl/Y+fvIP/zP6al8u0aXPcm8\n\tIhuSCgMJA053g==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1696598397; x=1697203197;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=uUCSwDkBt9yq+OpvYGFTB+hE9KGM3RBoxwzATHS+2C8=;\n\tb=LaSco4vz+FqQHsPOH6bLWJSC77jYFQsqTdHoJr9yoNYX2Kb0bLD7/s1FROafmLD+qw\n\trEjOzgieRPTkJWwoWwWl5DV4WVEPRWqzJgj6HTWtieevOBU8ykv02Lnsjff7vpg4ZGSZ\n\tVIaBloqgB8jrnAwGxbClu1bn2KhoKFV+yCU02a4yogcx6dw+DqrsbRrxdJzZ9TyiS2pF\n\tt6cjgczZzzkc7dCUWtTg6toaLICFZvmlyf9wSc7P0b+bwzuy83EKxIx4TiRd+srTwA4x\n\tqZFHiqdWxZzg0I04wIPlfWzJecqNKesX1nc5cjJLpi3ZN12gEvgRAc9uAyj3UT9ZJw1B\n\teqag=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"LaSco4vz\"; dkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1696598397; x=1697203197;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=uUCSwDkBt9yq+OpvYGFTB+hE9KGM3RBoxwzATHS+2C8=;\n\tb=nVAXuNFF315ovbNoljdmqkWEw+USHZZgXVGEruomPaWDZvQuDwmJT9vWDMzu/TqA4X\n\t4nPWGvzD4NTNZbUMms0iIRI1yx1O7memBsJSo6+zE8yLXlHZqfgZTBkIPHs59DHpNXWv\n\t0cIXa5BDssCXUlkg2NLdc4JoK4bpHIvK5bZSrUrUg6OwurpOV0PflTBypkc29JUz+0nn\n\tuK/CJ6A+JvZp+ybLqXJqF6DsV23ybncXPA8KoFkD71axOFt8OnemP1U8jfJs+8jKtCal\n\tDWcAbACduFWHW4W5DfNEvZBHxMRdCzjuFjAOKz51V4+3Q/TVXx8l5DOHLbPIMdKs+Tv5\n\tKJEw==",
        "X-Gm-Message-State": "AOJu0YyJ7BbCSOWyUOsCwHNk7OUW5LFZLC8Mdh/cLx76vhgi2o1VeGoq\n\t2h2XZDx4W3yqyxP4QdWN8FWJGgmAiOJdo+/sBeZiHA==",
        "X-Google-Smtp-Source": "AGHT+IHbzKG6XEX2wIwAQDKWZaLpb8rUOAMRO/3pCSJNyBKS2/oLkb5xSaYjnxwrKmwmlXePcXKVRQ==",
        "X-Received": "by 2002:a7b:c456:0:b0:402:eab3:b4e9 with SMTP id\n\tl22-20020a7bc456000000b00402eab3b4e9mr8017203wmi.33.1696598397297; \n\tFri, 06 Oct 2023 06:19:57 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  6 Oct 2023 14:19:41 +0100",
        "Message-Id": "<20231006132000.23504-2-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20231006132000.23504-1-naush@raspberrypi.com>",
        "References": "<20231006132000.23504-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 01/20] pipeline: rpi: Add RequiresMmap\n\tflag to RPi::Stream",
        "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>",
        "From": "Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Naushir Patuck <naush@raspberrypi.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add a new RequiresMmap flag to the RPi::Stream class indicating that\nbuffers handled by the stream must be mmapped after allocation and\ncached internally.\n\nAdd a new member function getBuffer(id) which can be used to obtain the\nmapped buffers for a given buffer id.\n\nAdd a new member function acquireBuffer() which can be used to obtain\nany mapped buffer that has not already been acquired by the caller.\n\nAs a drive-by, add the <algorithm> header to rpi_stream.cpp as it is\nneeded for the std::find_if() function.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/rpi/common/pipeline_base.cpp     |  2 +-\n .../pipeline/rpi/common/rpi_stream.cpp        | 50 +++++++++++++++++--\n .../pipeline/rpi/common/rpi_stream.h          | 32 +++++++++++-\n src/libcamera/pipeline/rpi/vc4/vc4.cpp        |  6 +--\n 4 files changed, 81 insertions(+), 9 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex fad710a63c46..825eae80d014 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -888,7 +888,7 @@ void PipelineHandlerBase::mapBuffers(Camera *camera, const BufferMap &buffers, u\n \t */\n \tfor (auto const &it : buffers) {\n \t\tbufferIds.push_back(IPABuffer(mask | it.first,\n-\t\t\t\t\t      it.second->planes()));\n+\t\t\t\t\t      it.second.buffer->planes()));\n \t\tdata->bufferIds_.insert(mask | it.first);\n \t}\n \ndiff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\nindex 7319f510a371..83c2205f7ca0 100644\n--- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n+++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n@@ -6,6 +6,10 @@\n  */\n #include \"rpi_stream.h\"\n \n+#include <algorithm>\n+#include <tuple>\n+#include <utility>\n+\n #include <libcamera/base/log.h>\n \n /* Maximum number of buffer slots to allocate in the V4L2 device driver. */\n@@ -17,8 +21,13 @@ LOG_DEFINE_CATEGORY(RPISTREAM)\n \n namespace RPi {\n \n+const BufferObject Stream::errorBufferObject{ nullptr, false };\n+\n void Stream::setFlags(StreamFlags flags)\n {\n+\t/* We don't want dynamic mmapping. */\n+\tASSERT(!(flags & StreamFlag::RequiresMmap));\n+\n \tflags_ |= flags;\n \n \t/* Import streams cannot be external. */\n@@ -27,6 +36,9 @@ void Stream::setFlags(StreamFlags flags)\n \n void Stream::clearFlags(StreamFlags flags)\n {\n+\t/* We don't want dynamic mmapping. */\n+\tASSERT(!(flags & StreamFlag::RequiresMmap));\n+\n \tflags_ &= ~flags;\n }\n \n@@ -56,7 +68,7 @@ void Stream::resetBuffers()\n void Stream::setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n {\n \tfor (auto const &buffer : *buffers)\n-\t\tbufferMap_.emplace(++id_, buffer.get());\n+\t\tbufferEmplace(++id_, buffer.get());\n }\n \n const BufferMap &Stream::getBuffers() const\n@@ -71,7 +83,7 @@ unsigned int Stream::getBufferId(FrameBuffer *buffer) const\n \n \t/* Find the buffer in the map, and return the buffer id. */\n \tauto it = std::find_if(bufferMap_.begin(), bufferMap_.end(),\n-\t\t\t       [&buffer](auto const &p) { return p.second == buffer; });\n+\t\t\t       [&buffer](auto const &p) { return p.second.buffer == buffer; });\n \n \tif (it == bufferMap_.end())\n \t\treturn 0;\n@@ -81,7 +93,7 @@ unsigned int Stream::getBufferId(FrameBuffer *buffer) const\n \n void Stream::setExportedBuffer(FrameBuffer *buffer)\n {\n-\tbufferMap_.emplace(++id_, buffer);\n+\tbufferEmplace(++id_, buffer);\n }\n \n int Stream::prepareBuffers(unsigned int count)\n@@ -180,6 +192,27 @@ void Stream::returnBuffer(FrameBuffer *buffer)\n \t}\n }\n \n+const BufferObject &Stream::getBuffer(unsigned int id)\n+{\n+\tauto const &it = bufferMap_.find(id);\n+\tif (it == bufferMap_.end())\n+\t\treturn errorBufferObject;\n+\n+\treturn it->second;\n+}\n+\n+const BufferObject &Stream::acquireBuffer()\n+{\n+\t/* No id provided, so pick up the next available buffer if possible. */\n+\tif (availableBuffers_.empty())\n+\t\treturn errorBufferObject;\n+\n+\tunsigned int id = getBufferId(availableBuffers_.front());\n+\tavailableBuffers_.pop();\n+\n+\treturn getBuffer(id);\n+}\n+\n int Stream::queueAllBuffers()\n {\n \tint ret;\n@@ -204,6 +237,17 @@ void Stream::releaseBuffers()\n \tclearBuffers();\n }\n \n+void Stream::bufferEmplace(unsigned int id, FrameBuffer *buffer)\n+{\n+\tif (flags_ & StreamFlag::RequiresMmap) {\n+\t\tbufferMap_.emplace(std::piecewise_construct, std::forward_as_tuple(id),\n+\t\t\t\t   std::forward_as_tuple(buffer, true));\n+\t} else {\n+\t\tbufferMap_.emplace(std::piecewise_construct, std::forward_as_tuple(id),\n+\t\t\t\t   std::forward_as_tuple(buffer, false));\n+\t}\n+}\n+\n void Stream::clearBuffers()\n {\n \tavailableBuffers_ = std::queue<FrameBuffer *>{};\ndiff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h\nindex 889b499782a4..861e9c8e7dab 100644\n--- a/src/libcamera/pipeline/rpi/common/rpi_stream.h\n+++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n@@ -7,22 +7,23 @@\n \n #pragma once\n \n+#include <optional>\n #include <queue>\n #include <string>\n #include <unordered_map>\n #include <vector>\n \n #include <libcamera/base/flags.h>\n+\n #include <libcamera/stream.h>\n \n+#include \"libcamera/internal/mapped_framebuffer.h\"\n #include \"libcamera/internal/v4l2_videodevice.h\"\n \n namespace libcamera {\n \n namespace RPi {\n \n-using BufferMap = std::unordered_map<unsigned int, FrameBuffer *>;\n-\n enum BufferMask {\n \tMaskID\t\t\t= 0x00ffff,\n \tMaskStats\t\t= 0x010000,\n@@ -30,6 +31,21 @@ enum BufferMask {\n \tMaskBayerData\t\t= 0x040000,\n };\n \n+struct BufferObject {\n+\tBufferObject(FrameBuffer *b, bool requiresMmap)\n+\t\t: buffer(b), mapped(std::nullopt)\n+\t{\n+\t\tif (requiresMmap)\n+\t\t\tmapped = std::make_optional<MappedFrameBuffer>\n+\t\t\t\t\t(b, MappedFrameBuffer::MapFlag::ReadWrite);\n+\t}\n+\n+\tFrameBuffer *buffer;\n+\tstd::optional<MappedFrameBuffer> mapped;\n+};\n+\n+using BufferMap = std::unordered_map<unsigned int, BufferObject>;\n+\n /*\n  * Device stream abstraction for either an internal or external stream.\n  * Used for both Unicam and the ISP.\n@@ -49,6 +65,11 @@ public:\n \t\t * buffers might be provided by (and returned to) the application.\n \t\t */\n \t\tExternal\t= (1 << 1),\n+\t\t/*\n+\t\t * Indicates that the stream buffers need to be mmaped and returned\n+\t\t * to the pipeline handler when requested.\n+\t\t */\n+\t\tRequiresMmap\t= (1 << 2),\n \t};\n \n \tusing StreamFlags = Flags<StreamFlag>;\n@@ -82,10 +103,17 @@ public:\n \tint queueBuffer(FrameBuffer *buffer);\n \tvoid returnBuffer(FrameBuffer *buffer);\n \n+\tconst BufferObject &getBuffer(unsigned int id);\n+\tconst BufferObject &acquireBuffer();\n+\n \tint queueAllBuffers();\n \tvoid releaseBuffers();\n \n+\t/* For error handling. */\n+\tstatic const BufferObject errorBufferObject;\n+\n private:\n+\tvoid bufferEmplace(unsigned int id, FrameBuffer *buffer);\n \tvoid clearBuffers();\n \tint queueToDevice(FrameBuffer *buffer);\n \ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex c189abaabc87..bc90d6324777 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -825,7 +825,7 @@ void Vc4CameraData::processStatsComplete(const ipa::RPi::BufferIds &buffers)\n \tif (!isRunning())\n \t\treturn;\n \n-\tFrameBuffer *buffer = isp_[Isp::Stats].getBuffers().at(buffers.stats & RPi::MaskID);\n+\tFrameBuffer *buffer = isp_[Isp::Stats].getBuffers().at(buffers.stats & RPi::MaskID).buffer;\n \n \thandleStreamBuffer(buffer, &isp_[Isp::Stats]);\n \n@@ -842,7 +842,7 @@ void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers)\n \tif (!isRunning())\n \t\treturn;\n \n-\tbuffer = unicam_[Unicam::Image].getBuffers().at(bayer & RPi::MaskID);\n+\tbuffer = unicam_[Unicam::Image].getBuffers().at(bayer & RPi::MaskID).buffer;\n \tLOG(RPI, Debug) << \"Input re-queue to ISP, buffer id \" << (bayer & RPi::MaskID)\n \t\t\t<< \", timestamp: \" << buffer->metadata().timestamp;\n \n@@ -850,7 +850,7 @@ void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers)\n \tispOutputCount_ = 0;\n \n \tif (sensorMetadata_ && embeddedId) {\n-\t\tbuffer = unicam_[Unicam::Embedded].getBuffers().at(embeddedId & RPi::MaskID);\n+\t\tbuffer = unicam_[Unicam::Embedded].getBuffers().at(embeddedId & RPi::MaskID).buffer;\n \t\thandleStreamBuffer(buffer, &unicam_[Unicam::Embedded]);\n \t}\n \n",
    "prefixes": [
        "libcamera-devel",
        "01/20"
    ]
}