Show a patch.

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

{
    "id": 8831,
    "url": "https://patchwork.libcamera.org/api/patches/8831/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/8831/",
    "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": "<20200715140703.566298-9-naush@raspberrypi.com>",
    "date": "2020-07-15T14:07:01",
    "name": "[libcamera-devel,v2,08/10] libcamera: pipeline: raspberrypi: Add more robust stream buffer logic",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "936fb7f5a87d7d1e3c53d1d3769db49d823c879d",
    "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/8831/mbox/",
    "series": [
        {
            "id": 1111,
            "url": "https://patchwork.libcamera.org/api/series/1111/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1111",
            "date": "2020-07-15T14:06:53",
            "name": "Zero-copy RAW stream work",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/1111/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/8831/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/8831/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 C1B1ABD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 15 Jul 2020 14:07:25 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8B02D60BEA;\n\tWed, 15 Jul 2020 16:07:25 +0200 (CEST)",
            "from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com\n\t[IPv6:2a00:1450:4864:20::42a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 21FED60BEA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Jul 2020 16:07:24 +0200 (CEST)",
            "by mail-wr1-x42a.google.com with SMTP id z15so2841996wrl.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Jul 2020 07:07:24 -0700 (PDT)",
            "from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tl67sm4195339wml.13.2020.07.15.07.07.21\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 15 Jul 2020 07:07:22 -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=\"UHcIoGol\"; 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:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=/KXVsZT/hUhQq4nWWSzSgN5H5zYfjcF3lv06viQPH5Y=;\n\tb=UHcIoGolBPRR6kx+byyOBq1IoaXSUeMIRE8CaX6s8tz6Ip0dNzisTgnPSYkcoomTPG\n\tutGZRAXwFyQj3sAZbXcZaQA3yV1aJ3pd408j6cWMKa4yyn09E4ZaxOUjfQIRc0w7jdR6\n\tUlUQrOn8zXaTiFv+/xLp8BPIxajoF41hmkHzJfYYS62lGErLwgDDI+G8MiquJw/irJ9q\n\t8lX4lerhPyGLk17kVTsfrG3pbSOjy04jHiw1Bo1OwmB9Hhij/GI1KnPPtlqGoFS9xTij\n\tATpy0Xl0WMnmazGaYGsDaY7sIEQYBQcpCfZR+MisPoFPSndWv4KUEk01igXagkFUGhsF\n\tCQwg==",
        "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:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=/KXVsZT/hUhQq4nWWSzSgN5H5zYfjcF3lv06viQPH5Y=;\n\tb=ahJPkauvgei37xP44A4PQHH/0IbeGibs/MMowtcJweL4L5VWqiv4X7EHnq0EPTASMu\n\tfylBhFPM9rT4Q2SggRmAfLnMhBQ3rlpasEAikwWr1AmmtxaNMN8z5M0YpoLcSqIWmi3B\n\trykkYr1/Qd02ZuL9HpWtnZQq69qbedWozrErX/sKJmg+8fclLlgQRUC3HqTADFKCO4Wx\n\tMan7In6ADPM8auH92O5/gsI4bQAkueq9loTmRDYCaGUgLz94usMcuth2JkWdJfR1//f3\n\tdmCqJ9SxkDAvS1iuuNrhEgtcYP7H0JT/Mx1q1Bf2qqOwIZFsESzI7z7REuC6RKw8nFdl\n\t+SJQ==",
        "X-Gm-Message-State": "AOAM531GesEdd14qhF3k4S3bDOdL7ICwCdYj/WBNAkHyl81OJByQzrW3\n\ty2J1DsJe4alIcIMix6fL0shJ2ZpnNuo=",
        "X-Google-Smtp-Source": "ABdhPJx1msNgp4C44vzmcxuiOv+wszDMEml5Bjv6z+zd6jSvVOQ3Wl4KrjMFE3Wa4DUk+skUUvYSSw==",
        "X-Received": "by 2002:a5d:540d:: with SMTP id\n\tg13mr10854440wrv.380.1594822043319; \n\tWed, 15 Jul 2020 07:07:23 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 15 Jul 2020 15:07:01 +0100",
        "Message-Id": "<20200715140703.566298-9-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20200715140703.566298-1-naush@raspberrypi.com>",
        "References": "<20200715140703.566298-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v2 08/10] libcamera: pipeline:\n\traspberrypi: Add more robust stream buffer logic",
        "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": "Add further queueing into the RPiStream object to ensure that we always\nfollow the buffer ordering (be it internal or external) given by\nincoming Requests.\n\nThis is essential, otherwise we risk dropping frames that are meant to\nbe part of a Request, and can cause the pipeline to stall indefinitely.\nThis also prevents any possibility of mismatched frame buffers going\nthrough the pipeline and out to the application.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/rpi_stream.cpp       | 69 ++++++++++++++++---\n .../pipeline/raspberrypi/rpi_stream.h         | 12 +++-\n 2 files changed, 70 insertions(+), 11 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\nindex 73111b95..d9eea3ed 100644\n--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n@@ -116,28 +116,64 @@ int RPiStream::queueBuffer(FrameBuffer *buffer)\n \t\tif (availableBuffers_.empty()) {\n \t\t\tLOG(RPISTREAM, Warning) << \"No buffers available for \"\n \t\t\t\t\t\t<< name_;\n-\t\t\treturn -EINVAL;\n+\t\t\t/*\n+\t\t\t * Note that we need to requeue an internal buffer as soon\n+\t\t\t * as one becomes available.\n+\t\t\t */\n+\t\t\trequeueBuffers_.push(nullptr);\n+\t\t\treturn -ENOMEM;\n \t\t}\n \n \t\tbuffer = availableBuffers_.front();\n \t\tavailableBuffers_.pop();\n \t}\n \n-\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << buffer->cookie()\n-\t\t\t      << \" for \" << name_;\n-\n-\tint ret = dev_->queueBuffer(buffer);\n-\tif (ret) {\n-\t\tLOG(RPISTREAM, Error) << \"Failed to queue buffer for \"\n-\t\t\t\t      << name_;\n+\tif (requeueBuffers_.empty()) {\n+\t\t/*\n+\t\t * No earlier requests are pending to be queued, so we can\n+\t\t * go ahead and queue the buffer into the device.\n+\t\t */\n+\t\treturn queueToDevice(buffer);\n+\t} else {\n+\t\t/*\n+\t\t * There are earlier buffers to be queued, so this buffer\n+\t\t * must go on the waiting list.\n+\t\t */\n+\t\trequeueBuffers_.push(buffer);\n+\t\treturn 0;\n \t}\n-\n-\treturn ret;\n }\n \n void RPiStream::returnBuffer(FrameBuffer *buffer)\n {\n+\t/* Push this buffer back into the queue to be used again. */\n \tavailableBuffers_.push(buffer);\n+\n+\t/*\n+\t * Do we have any buffers that are waiting to be queued?\n+\t * If so, do it now as availableBuffers_ will not be empty.\n+\t */\n+\twhile (!requeueBuffers_.empty()) {\n+\t\tFrameBuffer *buffer = requeueBuffers_.front();\n+\t\trequeueBuffers_.pop();\n+\n+\t\tif (!buffer && !availableBuffers_.empty()) {\n+\t\t\t/*\n+\t\t\t * We want to queue an internal buffer, and at\n+\t\t\t * least one is available.\n+\t\t\t */\n+\t\t\tbuffer = availableBuffers_.front();\n+\t\t\tavailableBuffers_.pop();\n+\t\t} else if (!buffer && availableBuffers_.empty()) {\n+\t\t\t/*\n+\t\t\t * We want to queue an internal buffer, but none\n+\t\t\t * are available. Can't do anything, quit the loop.\n+\t\t\t */\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tqueueToDevice(buffer);\n+\t}\n }\n \n bool RPiStream::findFrameBuffer(FrameBuffer *buffer) const\n@@ -154,10 +190,23 @@ bool RPiStream::findFrameBuffer(FrameBuffer *buffer) const\n void RPiStream::clearBuffers()\n {\n \tavailableBuffers_ = std::queue<FrameBuffer *>{};\n+\trequeueBuffers_ = std::queue<FrameBuffer *>{};\n \tinternalBuffers_.clear();\n \tbufferList_.clear();\n }\n \n+int RPiStream::queueToDevice(FrameBuffer *buffer)\n+{\n+\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << buffer->cookie()\n+\t\t\t      << \" for \" << name_;\n+\n+\tint ret = dev_->queueBuffer(buffer);\n+\tif (ret)\n+\t\tLOG(RPISTREAM, Error) << \"Failed to queue buffer for \"\n+\t\t\t\t      << name_;\n+\treturn ret;\n+}\n+\n } /* namespace RPi */\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\nindex dc65e5d5..0e58d261 100644\n--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n@@ -51,6 +51,7 @@ public:\n \n private:\n \tvoid clearBuffers();\n+\tint queueToDevice(FrameBuffer *buffer);\n \t/*\n \t * Indicates that this stream is active externally, i.e. the buffers\n \t * might be provided by (and returned to) the application.\n@@ -62,7 +63,7 @@ private:\n \tstd::string name_;\n \t/* The actual device stream. */\n \tstd::unique_ptr<V4L2VideoDevice> dev_;\n-\t/* All framebuffers associated with this device stream. */\n+\t/* All frame buffers associated with this device stream. */\n \tstd::vector<FrameBuffer *> bufferList_;\n \t/*\n \t * List of frame buffer that we can use if none have been provided by\n@@ -70,6 +71,15 @@ private:\n \t * buffers exported internally.\n \t */\n \tstd::queue<FrameBuffer *> availableBuffers_;\n+\t/*\n+\t * List of frame buffer that are to be re-queued into the device.\n+\t * A nullptr indicates any internal buffer can be used (from availableBuffers_),\n+\t * whereas a valid pointer indicates an external buffer to be queued.\n+\t *\n+\t * Ordering buffers to be queued is important here as it must match the\n+\t * requests coming from the application.\n+\t */\n+\tstd::queue<FrameBuffer *> requeueBuffers_;\n \t/*\n \t * This is a list of buffers exported internally. Need to keep this around\n \t * as the stream needs to maintain ownership of these buffers.\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "08/10"
    ]
}