Show a patch.

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

{
    "id": 1628,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1628/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1628/",
    "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": "<20190704225334.26170-8-jacopo@jmondi.org>",
    "date": "2019-07-04T22:53:32",
    "name": "[libcamera-devel,7/9] libcamera: request: Support buffer mapping",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "0d21e653f87c9189c594ea3910df655e3380c0c1",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1628/mbox/",
    "series": [
        {
            "id": 407,
            "url": "https://patchwork.libcamera.org/api/1.1/series/407/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=407",
            "date": "2019-07-04T22:53:25",
            "name": "Add support for external bufferes",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/407/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1628/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1628/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 11BD76156B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jul 2019 00:52:32 +0200 (CEST)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 9C95F1C0008;\n\tThu,  4 Jul 2019 22:52:31 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  5 Jul 2019 00:53:32 +0200",
        "Message-Id": "<20190704225334.26170-8-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190704225334.26170-1-jacopo@jmondi.org>",
        "References": "<20190704225334.26170-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 7/9] libcamera: request: Support buffer\n\tmapping",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.23",
        "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>",
        "X-List-Received-Date": "Thu, 04 Jul 2019 22:52:32 -0000"
    },
    "content": "Use the Stream class buffer mapping operation to save the association in\nthe request at Request::findBuffer() time and reverse it with a new\noperation Request::unmapBuffer() used by the pipeline handler base class\nat buffer completion time, to return to the applications the Buffer they\noriginally provided with the Request without involving the pipeline\nhandlers in the process.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/request.h        |  4 ++-\n src/libcamera/pipeline_handler.cpp |  6 ++--\n src/libcamera/request.cpp          | 45 ++++++++++++++++++++++++++++--\n 3 files changed, 50 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/include/libcamera/request.h b/include/libcamera/request.h\nindex 70f6d7fa7eeb..3353f037945e 100644\n--- a/include/libcamera/request.h\n+++ b/include/libcamera/request.h\n@@ -36,7 +36,8 @@ public:\n \tControlList &controls() { return controls_; }\n \tconst std::map<Stream *, Buffer *> &buffers() const { return buffers_; }\n \tint setBuffers(const std::map<Stream *, Buffer *> &streamMap);\n-\tBuffer *findBuffer(Stream *stream) const;\n+\tBuffer *findBuffer(Stream *stream);\n+\tBuffer *unmapBuffer(Buffer *streamBuffer);\n \n \tStatus status() const { return status_; }\n \n@@ -55,6 +56,7 @@ private:\n \tControlList controls_;\n \tstd::map<Stream *, Buffer *> buffers_;\n \tstd::unordered_set<Buffer *> pending_;\n+\tstd::map<Buffer *, Buffer *> bufferMap_;\n \n \tStatus status_;\n };\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 67b215483847..a47411ecf345 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -402,8 +402,10 @@ int PipelineHandler::queueRequest(Camera *camera, Request *request)\n bool PipelineHandler::completeBuffer(Camera *camera, Request *request,\n \t\t\t\t     Buffer *buffer)\n {\n-\tcamera->bufferCompleted.emit(request, buffer);\n-\treturn request->completeBuffer(buffer);\n+\tBuffer *requestBuffer = request->unmapBuffer(buffer);\n+\n+\tcamera->bufferCompleted.emit(request, requestBuffer);\n+\treturn request->completeBuffer(requestBuffer);\n }\n \n /**\ndiff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\nindex 9ff0abbf119c..0e07d39f8941 100644\n--- a/src/libcamera/request.cpp\n+++ b/src/libcamera/request.cpp\n@@ -105,17 +105,58 @@ int Request::setBuffers(const std::map<Stream *, Buffer *> &streamMap)\n  */\n \n /**\n- * \\brief Return the buffer associated with a stream\n+ * \\brief Retrieve the stream buffer associated with a stream\n  * \\param[in] stream The stream the buffer is associated to\n+ *\n+ * Depending on the configured memory type, the buffers originally provided\n+ * by the application might get mapped to streams internal buffers.\n+ *\n+ * \\sa Stream::mapBuffer()\n+ *\n  * \\return The buffer associated with the stream, or nullptr if the stream is\n  * not part of this request\n  */\n-Buffer *Request::findBuffer(Stream *stream) const\n+Buffer *Request::findBuffer(Stream *stream)\n {\n \tauto it = buffers_.find(stream);\n \tif (it == buffers_.end())\n \t\treturn nullptr;\n \n+\t/*\n+\t * Streams with internal memory mode do not need to perform any mapping\n+\t * between the application provided buffers (part of the request)\n+\t * and the one actually used by the Stream.\n+\t *\n+\t * Streams using externally allocated buffers need to create a mapping\n+\t * between the application provided buffers and the one used by pipeline\n+\t * handlers.\n+\t */\n+\tBuffer *requestBuffer = it->second;\n+\tBuffer *mappedBuffer = stream->memoryType() == InternalMemory ?\n+\t\t\t       it->second : stream->mapBuffer(it->second);\n+\tbufferMap_[mappedBuffer] = requestBuffer;\n+\n+\treturn mappedBuffer;\n+}\n+\n+/**\n+ * \\brief Retrieve the application buffer associated with \\a streamBuffer\n+ * \\param streamBuffer The stream buffer returned from Request::findBuffer()\n+ *\n+ * This operation is used by the PipelineHandler base class to retrieve the\n+ * buffer the application originally associated with the stream in the request.\n+ * Depending on the configured memory type, application provided buffers might\n+ * be mapped to streams internal buffers at Request::findBuffer() time.\n+ *\n+ * \\sa Stream::mapBuffer()\n+ *\n+ * \\return The application buffer provided to Request::findBuffer()\n+ */\n+Buffer *Request::unmapBuffer(Buffer *streamBuffer)\n+{\n+\tauto it = bufferMap_.find(streamBuffer);\n+\tASSERT(it != bufferMap_.end());\n+\n \treturn it->second;\n }\n \n",
    "prefixes": [
        "libcamera-devel",
        "7/9"
    ]
}