Show a patch.

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

{
    "id": 10250,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/10250/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/10250/",
    "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": "<20201026095356.442605-1-naush@raspberrypi.com>",
    "date": "2020-10-26T09:53:55",
    "name": "[libcamera-devel,1/2] pipeline: raspberrypi: Use MappedFrameBuffer for embedded data buffers",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "06949c84af2ed1ceb609f7860d3831ed5a80b961",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/10250/mbox/",
    "series": [
        {
            "id": 1415,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1415/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1415",
            "date": "2020-10-26T09:53:55",
            "name": "[libcamera-devel,1/2] pipeline: raspberrypi: Use MappedFrameBuffer for embedded data buffers",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1415/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/10250/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/10250/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 813CCBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 26 Oct 2020 09:54:01 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E31C561E30;\n\tMon, 26 Oct 2020 10:54:00 +0100 (CET)",
            "from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com\n\t[IPv6:2a00:1450:4864:20::32f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A3E146034D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 Oct 2020 10:53:59 +0100 (CET)",
            "by mail-wm1-x32f.google.com with SMTP id c194so10953976wme.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 Oct 2020 02:53:59 -0700 (PDT)",
            "from naushir-VirtualBox.pitowers.org\n\t([2a00:1098:3142:14:a00:27ff:fe4d:f6a2])\n\tby smtp.gmail.com with ESMTPSA id\n\tl8sm22157508wrn.28.2020.10.26.02.53.58\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 26 Oct 2020 02:53:58 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"LaE0/2oo\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=CPeLxGSn9vdBOn7byMXWKovikSEmSr5cXSb8TH9kCYo=;\n\tb=LaE0/2ooCy9Pz7g7I3t3lw7nR3JZcgz7ZAzpm7XUyead/Zv6JLBCKN3ggKS26KRqTK\n\tfwmlERKzxGg1+KaHa8DVtD+GjbgDzOp//MPiKB1smdzg7U0/F0zTTCyvbVEmENwyFW8P\n\tF8HBJuE4wxuP+OoTzVsUcwtlvG0Fq4L8/zoTyunn3GIySh4dvFkWktF/oGKG6CLbEHDx\n\tgsWb/zU/kbQGqeJzrd53Huqn/XR6ki2sf0jBaS8rjYELhNBKAU5WFbnP5bKXpbEq9kGL\n\t52mHkdNznLV3qmZroMLVM9fbfE8utjEvV1+Hy/HscZAbrRlSdNca6I9qR85mHsYtVVp6\n\tdv7A==",
        "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:mime-version\n\t:content-transfer-encoding;\n\tbh=CPeLxGSn9vdBOn7byMXWKovikSEmSr5cXSb8TH9kCYo=;\n\tb=o+bttx6CFaFbCdtHJa5n+AoqPpWkWg/hDbzTnGygEj+NY2xDLbYoR1czkqkuO5Zk/p\n\tN3NJxNqIcmVhqe5zfD+J9Z10DoW157JFIGoKzPq8/HsvXpcb7mTuvYezAKeFYXib5VRK\n\tnVnNvLDxIiWFHOo1Pr66oQdnRlpygWxW1ExAi4DoHmVouwCJOGAtEk1jPQFIsedvNzpI\n\tFshhol/WyLtekgO+d1SdKESNKOj5P7NXCZB2QMKz2LnbMR8PUTjFomMhSvv6UtsadESJ\n\tjjrA7ZylnQpsGNcDFNLBjeUz76n+x0eYsUaYZMQ4gDoqCnR5s1T0cqKVt7XdJmvb5Cgu\n\tauTw==",
        "X-Gm-Message-State": "AOAM530KpvHDFjz9aH8znVu9zeMM/NnbY4OZWbOtfpb0c3G3BWWiaD0R\n\tspp3HxE8HUDl1Z6nsgc9g/6iFjE5bmn4Yw==",
        "X-Google-Smtp-Source": "ABdhPJyx2AD76Lry/k01jSqQXGVPW9b9xjpMAow49OhiIrbPKflZf/mfvGfc3rwYMlk5qVkVcMCGfA==",
        "X-Received": "by 2002:a1c:9a46:: with SMTP id\n\tc67mr14545645wme.115.1603706038905; \n\tMon, 26 Oct 2020 02:53:58 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 26 Oct 2020 09:53:55 +0000",
        "Message-Id": "<20201026095356.442605-1-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH 1/2] pipeline: raspberrypi: Use\n\tMappedFrameBuffer for embedded data buffers",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Use a MappedFrameBuffer to mmap embedded data buffers for the pipeline\nhandler to use in the cases where the sensor does not fill it in. This\navoids the need to mmap and unmap on every frame.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 35 ++++++++++++++-----\n 1 file changed, 27 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex dd62dfc7..8817915b 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -24,6 +24,7 @@\n #include <linux/videodev2.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/buffer.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/ipa_manager.h\"\n@@ -165,6 +166,12 @@ public:\n \t/* Stores the ids of the buffers mapped in the IPA. */\n \tstd::unordered_set<unsigned int> ipaBuffers_;\n \n+\t/*\n+\t * Map of (internal) mmaped embedded data buffers, to avoid having to\n+\t * map/unmap on every frame.\n+\t */\n+\tstd::map<unsigned int, MappedFrameBuffer> mappedEmbeddedBuffers_;\n+\n \t/* DMAHEAP allocation helper. */\n \tRPi::DmaHeap dmaHeap_;\n \tFileDescriptor lsTable_;\n@@ -1040,6 +1047,15 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n \t\t\treturn ret;\n \t}\n \n+\tif (!data->sensorMetadata_) {\n+\t\tfor (auto const &it : data->unicam_[Unicam::Embedded].getBuffers()) {\n+\t\t\tdata->mappedEmbeddedBuffers_.emplace(std::piecewise_construct,\n+\t\t\t\t\t\t\t     std::forward_as_tuple(it.first),\n+\t\t\t\t\t\t\t     std::forward_as_tuple(\n+\t\t\t\t\t\t\t     MappedFrameBuffer(it.second, PROT_READ | PROT_WRITE)));\n+\t\t}\n+\t}\n+\n \t/*\n \t * Pass the stats and embedded data buffers to the IPA. No other\n \t * buffers need to be passed.\n@@ -1078,6 +1094,7 @@ void PipelineHandlerRPi::freeBuffers(Camera *camera)\n \tstd::vector<unsigned int> ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end());\n \tdata->ipa_->unmapBuffers(ipaBuffers);\n \tdata->ipaBuffers_.clear();\n+\tdata->mappedEmbeddedBuffers_.clear();\n \n \tfor (auto const stream : data->streams_)\n \t\tstream->releaseBuffers();\n@@ -1310,14 +1327,16 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n \t\t * metadata buffer.\n \t\t */\n \t\tif (!sensorMetadata_) {\n-\t\t\tconst FrameBuffer &fb = buffer->planes();\n-\t\t\tuint32_t *mem = static_cast<uint32_t *>(::mmap(nullptr, fb.planes()[0].length,\n-\t\t\t\t\t\t\t\t       PROT_READ | PROT_WRITE,\n-\t\t\t\t\t\t\t\t       MAP_SHARED,\n-\t\t\t\t\t\t\t\t       fb.planes()[0].fd.fd(), 0));\n-\t\t\tmem[0] = ctrl[V4L2_CID_EXPOSURE];\n-\t\t\tmem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n-\t\t\tmunmap(mem, fb.planes()[0].length);\n+\t\t\tunsigned int bufferId = unicam_[Unicam::Embedded].getBufferId(buffer);\n+\t\t\tauto it = mappedEmbeddedBuffers_.find(bufferId);\n+\t\t\tif (it != mappedEmbeddedBuffers_.end()) {\n+\t\t\t\tuint32_t *mem = reinterpret_cast<uint32_t *>(it->second.maps()[0].data());\n+\t\t\t\tmem[0] = ctrl[V4L2_CID_EXPOSURE];\n+\t\t\t\tmem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n+\t\t\t} else {\n+\t\t\t\tLOG(RPI, Warning) << \"Failed to find embedded buffer \"\n+\t\t\t\t\t\t  << bufferId;\n+\t\t\t}\n \t\t}\n \t}\n \n",
    "prefixes": [
        "libcamera-devel",
        "1/2"
    ]
}