Show a patch.

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

{
    "id": 1691,
    "url": "https://patchwork.libcamera.org/api/patches/1691/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1691/",
    "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": "<20190713172351.25452-11-laurent.pinchart@ideasonboard.com>",
    "date": "2019-07-13T17:23:45",
    "name": "[libcamera-devel,v2,10/16] libcamera: stream: Shorten access to the bufferPool",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "6391f1078470e221d486ef4165e9c27a35791b17",
    "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/1691/mbox/",
    "series": [
        {
            "id": 430,
            "url": "https://patchwork.libcamera.org/api/series/430/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=430",
            "date": "2019-07-13T17:23:35",
            "name": "Add support for external buffers",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/430/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1691/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1691/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ECC5760C23\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Jul 2019 19:24:41 +0200 (CEST)",
            "from pendragon.ideasonboard.com (softbank126209254147.bbtec.net\n\t[126.209.254.147])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C3A072B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Jul 2019 19:24:40 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1563038681;\n\tbh=g8EfUqPeiObCJp19TGmeSC4qb8hFzsMqFl8ySC2N0HU=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=C79tTY0eY+mXO52NUMg6zHWsn/wU0g1xQW+QpegmSByQ7L9/VZFysLhR8LN++Ttj2\n\tFUolzWztPkbumK3jsJV7uK6xYRYPcTRJ4uZ6FverNHKnDK2V+L2PbWZmDW11DEfmRf\n\tmtJ7MziS8knPtwJtUiBLEFkT/BdvuX1XmVV8z21U=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 13 Jul 2019 20:23:45 +0300",
        "Message-Id": "<20190713172351.25452-11-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190713172351.25452-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20190713172351.25452-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 10/16] libcamera: stream: Shorten\n\taccess to the bufferPool",
        "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": "Sat, 13 Jul 2019 17:24:42 -0000"
    },
    "content": "From: Jacopo Mondi <jacopo@jmondi.org>\n\nAll interactions with the Stream's buffers currently go through the\nBufferPool. In order to shorten accessing the buffers array, and eventually\nrestrict access to the Stream's internal buffer pool, provide operations to\naccess, create and destroy buffers.\n\nIt is still possible to access the pool for pipeline handlers to\npopulate it by exporting buffers from a video device to Stream's pool.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/stream.h |  4 ++++\n src/cam/capture.cpp        |  2 +-\n src/libcamera/camera.cpp   |  4 ++--\n src/libcamera/stream.cpp   | 36 ++++++++++++++++++++++++++++++++++--\n src/qcam/main_window.cpp   |  2 +-\n 5 files changed, 42 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h\nindex f595a630eb4a..bc14fb60480e 100644\n--- a/include/libcamera/stream.h\n+++ b/include/libcamera/stream.h\n@@ -71,11 +71,15 @@ public:\n \tstd::unique_ptr<Buffer> createBuffer(unsigned int index);\n \n \tBufferPool &bufferPool() { return bufferPool_; }\n+\tstd::vector<BufferMemory> &buffers() { return bufferPool_.buffers(); }\n \tconst StreamConfiguration &configuration() const { return configuration_; }\n \n protected:\n \tfriend class Camera;\n \n+\tvoid createBuffers(unsigned int count);\n+\tvoid destroyBuffers();\n+\n \tBufferPool bufferPool_;\n \tStreamConfiguration configuration_;\n };\ndiff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\nindex 66ec1abaa5ac..5ffa4ae291da 100644\n--- a/src/cam/capture.cpp\n+++ b/src/cam/capture.cpp\n@@ -154,7 +154,7 @@ void Capture::requestComplete(Request *request, const std::map<Stream *, Buffer\n \tfor (auto it = buffers.begin(); it != buffers.end(); ++it) {\n \t\tStream *stream = it->first;\n \t\tBuffer *buffer = it->second;\n-\t\tBufferMemory *mem = &stream->bufferPool().buffers()[buffer->index()];\n+\t\tBufferMemory *mem = &stream->buffers()[buffer->index()];\n \t\tconst std::string &name = streamName_[stream];\n \n \t\tinfo << \" \" << name\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 1f307654ab01..61d3e821f48f 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -683,7 +683,7 @@ int Camera::configure(CameraConfiguration *config)\n \t\t * Allocate buffer objects in the pool.\n \t\t * Memory will be allocated and assigned later.\n \t\t */\n-\t\tstream->bufferPool().createBuffers(cfg.bufferCount);\n+\t\tstream->createBuffers(cfg.bufferCount);\n \t}\n \n \tstate_ = CameraConfigured;\n@@ -744,7 +744,7 @@ int Camera::freeBuffers()\n \t\t * All mappings must be destroyed before buffers can be freed\n \t\t * by the V4L2 device that has allocated them.\n \t\t */\n-\t\tstream->bufferPool().destroyBuffers();\n+\t\tstream->destroyBuffers();\n \t}\n \n \tstate_ = CameraConfigured;\ndiff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp\nindex 6d80646b55cd..884fbfebd52c 100644\n--- a/src/libcamera/stream.cpp\n+++ b/src/libcamera/stream.cpp\n@@ -435,19 +435,51 @@ std::unique_ptr<Buffer> Stream::createBuffer(unsigned int index)\n  * \\fn Stream::bufferPool()\n  * \\brief Retrieve the buffer pool for the stream\n  *\n- * The buffer pool handles the buffers used to capture frames at the output of\n- * the stream. It is initially created empty and shall be populated with\n+ * The buffer pool handles the memory buffers used to store frames for the\n+ * stream. It is initially created empty and shall be populated with\n  * buffers before being used.\n  *\n  * \\return A reference to the buffer pool\n  */\n \n+/**\n+ * \\fn Stream::buffers()\n+ * \\brief Retrieve the memory buffers in the Stream's buffer pool\n+ * \\return The list of stream's memory buffers\n+ */\n+\n /**\n  * \\fn Stream::configuration()\n  * \\brief Retrieve the active configuration of the stream\n  * \\return The active configuration of the stream\n  */\n \n+/**\n+ * \\brief Create buffers for the stream\n+ * \\param count The number of buffers to create\n+ *\n+ * Create \\a count empty buffers in the Stream's buffer pool.\n+ */\n+void Stream::createBuffers(unsigned int count)\n+{\n+\tdestroyBuffers();\n+\tif (count == 0)\n+\t\treturn;\n+\n+\tbufferPool_.createBuffers(count);\n+}\n+\n+/**\n+ * \\brief Destroy buffers in the stream\n+ *\n+ * If no buffers have been created or if buffers have already been destroyed no\n+ * operation is performed.\n+ */\n+void Stream::destroyBuffers()\n+{\n+\tbufferPool_.destroyBuffers();\n+}\n+\n /**\n  * \\var Stream::bufferPool_\n  * \\brief The pool of buffers associated with the stream\ndiff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 7023e1158fb6..92f888323f0b 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -235,7 +235,7 @@ void MainWindow::requestComplete(Request *request,\n \t\t  << \" fps: \" << std::fixed << std::setprecision(2) << fps\n \t\t  << std::endl;\n \n-\tBufferMemory *mem = &stream->bufferPool().buffers()[buffer->index()];\n+\tBufferMemory *mem = &stream->buffers()[buffer->index()];\n \tdisplay(buffer, mem);\n \n \trequest = camera_->createRequest();\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "10/16"
    ]
}