Show a patch.

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

{
    "id": 1008,
    "url": "https://patchwork.libcamera.org/api/patches/1008/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1008/",
    "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": "<20190416134210.21097-8-jacopo@jmondi.org>",
    "date": "2019-04-16T13:42:10",
    "name": "[libcamera-devel,v6,7/7] libcamera: buffer: Store Request reference in Buffer",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "7ce57386330a7f81707c3d7393095860509e6dc5",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1008/mbox/",
    "series": [
        {
            "id": 252,
            "url": "https://patchwork.libcamera.org/api/series/252/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=252",
            "date": "2019-04-16T13:42:03",
            "name": "libcamera: Framework changes to prepare for multiple streams support",
            "version": 6,
            "mbox": "https://patchwork.libcamera.org/series/252/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1008/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1008/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 45DDA60DC9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Apr 2019 15:41:30 +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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id B9512FF808;\n\tTue, 16 Apr 2019 13:41:29 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 16 Apr 2019 15:42:10 +0200",
        "Message-Id": "<20190416134210.21097-8-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190416134210.21097-1-jacopo@jmondi.org>",
        "References": "<20190416134210.21097-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v6 7/7] libcamera: buffer: Store Request\n\treference in Buffer",
        "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": "Tue, 16 Apr 2019 13:41:31 -0000"
    },
    "content": "Add to the Buffer class methods to set and retrieve a reference to the\nRequest instance this buffer is part of.\n\nAs Buffers might outlive the Request they are associated with, the\nreference is only temporary valid during the buffer completion interval\n(since when the buffer gets queued to Camera for processing, until it\ngets marked as completed).\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/buffer.h           |  6 +++++\n src/libcamera/buffer.cpp             | 34 +++++++++++++++++++++++++++-\n src/libcamera/pipeline/ipu3/ipu3.cpp |  2 +-\n src/libcamera/request.cpp            |  4 ++++\n 4 files changed, 44 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\nindex 0c844d126a27..8f9b42e39339 100644\n--- a/include/libcamera/buffer.h\n+++ b/include/libcamera/buffer.h\n@@ -13,6 +13,7 @@\n namespace libcamera {\n \n class BufferPool;\n+class Request;\n \n class Plane final\n {\n@@ -52,14 +53,18 @@ public:\n \tunsigned int sequence() const { return sequence_; }\n \tStatus status() const { return status_; }\n \tstd::vector<Plane> &planes() { return planes_; }\n+\tRequest *request() const { return request_; }\n \n private:\n \tfriend class BufferPool;\n \tfriend class PipelineHandler;\n+\tfriend class Request;\n \tfriend class V4L2Device;\n \n \tvoid cancel();\n \n+\tvoid setRequest(Request *request) { request_ = request; }\n+\n \tunsigned int index_;\n \tunsigned int bytesused_;\n \tuint64_t timestamp_;\n@@ -67,6 +72,7 @@ private:\n \tStatus status_;\n \n \tstd::vector<Plane> planes_;\n+\tRequest *request_;\n };\n \n class BufferPool final\ndiff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\nindex e2d1cf04411e..550091c998a6 100644\n--- a/src/libcamera/buffer.cpp\n+++ b/src/libcamera/buffer.cpp\n@@ -196,7 +196,7 @@ void *Plane::mem()\n  */\n \n Buffer::Buffer()\n-\t: index_(-1)\n+\t: index_(-1), request_(nullptr)\n {\n }\n \n@@ -248,6 +248,25 @@ Buffer::Buffer()\n  * \\return The buffer status\n  */\n \n+/**\n+ * \\fn Buffer::request()\n+ * \\brief Retrieve the request this buffer belongs to\n+ *\n+ * The intended callers of this method are buffer completion handlers that\n+ * needs to associated a buffer to the request it has been queued to.\n+ *\n+ * Buffers are associated to requests at Request::prepare() time and said\n+ * association is valid until the buffer does not complete at\n+ * Request::completeBuffer() time. Before and after the buffer completion\n+ * interval (the time between when the request is queued to the Camera, and\n+ * the buffer is marked as 'complete' by pipeline handlers) the reference to\n+ * the request is set to nullptr.\n+ *\n+ * \\return The Request the Buffer belongs to, or nullptr if the buffer is\n+ * either completed or not associated with a request\n+ * \\sa Buffer::setRequest()\n+ */\n+\n /**\n  * \\brief Mark a buffer as cancel by setting its status to BufferCancelled\n  */\n@@ -259,6 +278,19 @@ void Buffer::cancel()\n \tstatus_ = BufferCancelled;\n }\n \n+/**\n+ * \\fn Buffer::setRequest()\n+ * \\brief Set the request this buffer belongs to\n+ *\n+ * Buffers are associated to Streams in a Request, which is then sent to the\n+ * Camera for processing. This method stores in the Buffer a pointer to the\n+ * Request this Buffer is part of, for later retrieval through the\n+ * Buffer::request() method.\n+ *\n+ * The intended callers are the Request::prepare() and Request::completeBuffer()\n+ * methods.\n+ */\n+\n /**\n  * \\class BufferPool\n  * \\brief A pool of buffers\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex f96e8763bce9..6f5747fb1505 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -633,7 +633,7 @@ void PipelineHandlerIPU3::IPU3CameraData::imguInputBufferReady(Buffer *buffer)\n  */\n void PipelineHandlerIPU3::IPU3CameraData::imguOutputBufferReady(Buffer *buffer)\n {\n-\tRequest *request = queuedRequests_.front();\n+\tRequest *request = buffer->request();\n \n \tpipe_->completeBuffer(camera_, request, buffer);\n \tpipe_->completeRequest(camera_, request);\ndiff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\nindex 1946845b91f4..9ae62f632308 100644\n--- a/src/libcamera/request.cpp\n+++ b/src/libcamera/request.cpp\n@@ -144,6 +144,8 @@ int Request::prepare()\n \n \tfor (auto const &pair : bufferMap_) {\n \t\tBuffer *buffer = pair.second;\n+\n+\t\tbuffer->setRequest(this);\n \t\tpending_.insert(buffer);\n \t}\n \n@@ -180,6 +182,8 @@ bool Request::completeBuffer(Buffer *buffer)\n \tint ret = pending_.erase(buffer);\n \tASSERT(ret == 1);\n \n+\tbuffer->setRequest(nullptr);\n+\n \treturn !hasPendingBuffers();\n }\n \n",
    "prefixes": [
        "libcamera-devel",
        "v6",
        "7/7"
    ]
}