Patch Detail
Show a patch.
GET /api/1.1/patches/8758/?format=api
{ "id": 8758, "url": "https://patchwork.libcamera.org/api/1.1/patches/8758/?format=api", "web_url": "https://patchwork.libcamera.org/patch/8758/", "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": "<20200713084727.232422-9-naush@raspberrypi.com>", "date": "2020-07-13T08:47:27", "name": "[libcamera-devel,8/9] libcamera: pipeline: raspberrypi: Add more robust stream buffer logic", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "0c22a8609d86b78625fd360da794399cb9c5bace", "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/8758/mbox/", "series": [ { "id": 1100, "url": "https://patchwork.libcamera.org/api/1.1/series/1100/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1100", "date": "2020-07-13T08:47:18", "name": "Zero-copy RAW stream work", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1100/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/8758/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/8758/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 55B09BD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Jul 2020 08:48:09 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1F7C4605BD;\n\tMon, 13 Jul 2020 10:48:09 +0200 (CEST)", "from mail-wr1-x434.google.com (mail-wr1-x434.google.com\n\t[IPv6:2a00:1450:4864:20::434])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E9EB605C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jul 2020 10:48:06 +0200 (CEST)", "by mail-wr1-x434.google.com with SMTP id b6so15028196wrs.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jul 2020 01:48:06 -0700 (PDT)", "from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tg14sm23203357wrm.93.2020.07.13.01.48.04\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 13 Jul 2020 01:48:05 -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=\"pLt+a5it\"; 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=uWihPdm75vu/VFOlLQkZP5/xs711ROqPH6Z4lRafXUc=;\n\tb=pLt+a5itpEHAGzasMGkA/eOE5GADK/ppi/0oRIFDPWWvtlTD8NQqN9p6MioyDKyuuF\n\tm1AvXANsjvGwAHCexke32q1uf9MEmLnbezDWAaMj2LqXOIv5tpIR7ZcMLJDDduKLWGNr\n\tq5G/zwYIpoxdXKuhwpURTnrR4ofcKV9K+tiglpVo6bTjz5S6MbDA96ITtvsLMzGjB9jW\n\t/U/5aHzY0hcucSn867NY24hEc25p43Ds+RIqMe7MotrcFTKWPPzzBMQLrCSQhRbGIEoo\n\tM9CgMCKDjNqvyx3Z/DX4lVJVcOYT2cPumRAcGnQzIMwXLtVi9uWhH9mbpPQxnQc+NHA3\n\tuiHw==", "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=uWihPdm75vu/VFOlLQkZP5/xs711ROqPH6Z4lRafXUc=;\n\tb=KX4nZArJAuAv73AgiAY7b9nZNbvocaPwk1hhIcV2jiUE5ymEA1WCMNBv6znaHizy7G\n\tRSzSqKCAo3Llb9+0bKSoLbW+dUOKoSZjFxxmF3qEK9TOT6NnJl8SqNG6jxs7J3qRG8aS\n\thU3rMxrnfU1TRe/264WUpl7ottaPZtlEw8Q5adeVL7+nsVTx1Ifar0G5z5ravuRlZCuP\n\t9OzfFgF3X6aNgqzWiHFS8kGSaauvIHyA4+hvDE7WiNMz+6+M8CN7fLMXJObLkYPNwv/2\n\tL7yNLfHoYhs3Ve8dA6cEx3XqQLxlxgo+1ce7TDigqq01i3+IBinmYMg8E3knK4qeSlYz\n\thNDA==", "X-Gm-Message-State": "AOAM532+wcLE1N3G6dcZc+aXHPye32miU7JBIO4rSJKlp+aJjjupdqGp\n\tKFBTk24HXekYQa3A3JPxg21XOPFcnUE=", "X-Google-Smtp-Source": "ABdhPJzuELv2LVcXxczijUpD4dfjnpFTa3Vb+73Lw7KMr2raHl3v0qVKkkV4Wqw+3tX/M+PTcj/JKA==", "X-Received": "by 2002:a5d:420b:: with SMTP id\n\tn11mr78307170wrq.91.1594630085632; \n\tMon, 13 Jul 2020 01:48:05 -0700 (PDT)", "From": "Naushir Patuck <naush@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 13 Jul 2020 09:47:27 +0100", "Message-Id": "<20200713084727.232422-9-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20200713084727.232422-1-naush@raspberrypi.com>", "References": "<20200713084727.232422-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH 8/9] libcamera: pipeline: raspberrypi: Add\n\tmore 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/raspberrypi.cpp | 4 +-\n .../pipeline/raspberrypi/rpi_stream.h | 81 ++++++++++++++++---\n 2 files changed, 73 insertions(+), 12 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex e1a74d89..2c5af05b 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -732,7 +732,9 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request)\n \tfor (auto stream : data->streams_) {\n \t\tif (stream->isExternal()) {\n \t\t\tFrameBuffer *buffer = request->findBuffer(stream);\n-\t\t\tstream->queueBuffer(data->dropFrameCount_ ? nullptr : buffer);\n+\t\t\tint ret = stream->queueBuffer(data->dropFrameCount_ ? nullptr : buffer);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n \t\t}\n \t}\n \ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\nindex a6f573fa..3309edfb 100644\n--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n@@ -139,28 +139,77 @@ public:\n \t\t\tif (availableBuffers_.empty()) {\n \t\t\t\tLOG(RPISTREAM, Warning) << \"No buffers available for \"\n \t\t\t\t\t\t\t<< name_;\n-\t\t\t\treturn -EINVAL;\n+\t\t\t\t/*\n+\t\t\t\t * Note that we need to requeue an internal buffer as soon\n+\t\t\t\t * as one becomes available.\n+\t\t\t\t */\n+\t\t\t\trequeueBuffers_.push(nullptr);\n+\t\t\t\treturn -ENOMEM;\n \t\t\t}\n \n \t\t\tbuffer = availableBuffers_.front();\n \t\t\tavailableBuffers_.pop();\n \t\t}\n \n-\t\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << buffer->cookie()\n-\t\t\t\t << \" for \" << name_;\n-\n-\t\tint ret = dev_->queueBuffer(buffer);\n-\t\tif (ret) {\n-\t\t\tLOG(RPISTREAM, Error) << \"Failed to queue buffer for \"\n-\t\t\t\t\t << name_;\n+\t\tif (requeueBuffers_.empty()) {\n+\t\t\t/*\n+\t\t\t* No earlier requests are pending to be queued, so we can\n+\t\t\t* go ahead and queue the buffer into the device.\n+\t\t\t*/\n+\t\t\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << buffer->cookie()\n+\t\t\t\t\t << \" for \" << name_;\n+\n+\t\t\tint ret = dev_->queueBuffer(buffer);\n+\t\t\tif (ret)\n+\t\t\t\tLOG(RPISTREAM, Error) << \"Failed to queue buffer for \"\n+\t\t\t\t\t\t << name_;\n+\t\t\treturn ret;\n+\t\t} else {\n+\t\t\t/*\n+\t\t\t * There are earlier buffers to be queued, so this buffer\n+\t\t\t * must go on the waiting list.\n+\t\t\t */\n+\t\t\trequeueBuffers_.push(buffer);\n+\t\t\treturn 0;\n \t\t}\n-\n-\t\treturn ret;\n \t}\n \n \tvoid returnBuffer(FrameBuffer *buffer)\n \t{\n+\t\t/* Push this buffer back into the queue to be used again. */\n \t\tavailableBuffers_.push(buffer);\n+\n+\t\t/*\n+\t\t * Do we have any buffers that are waiting to be queued?\n+\t\t * If so, do it now as availableBuffers_ will not be empty.\n+\t\t */\n+\t\twhile (!requeueBuffers_.empty()) {\n+\t\t\tFrameBuffer *buffer = requeueBuffers_.front();\n+\t\t\trequeueBuffers_.pop();\n+\n+\t\t\tif (!buffer && !availableBuffers_.empty()) {\n+\t\t\t\t/*\n+\t\t\t\t * We want to queue an internal buffer, and at\n+\t\t\t\t * least one is available.\n+\t\t\t\t */\n+\t\t\t\tbuffer = availableBuffers_.front();\n+\t\t\t\tavailableBuffers_.pop();\n+\t\t\t} else if (!buffer && !availableBuffers_.empty()) {\n+\t\t\t\t/*\n+\t\t\t\t * We want to queue an internal buffer, but none\n+\t\t\t\t * are available.\n+\t\t\t\t */\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << buffer->cookie()\n+\t\t\t\t\t << \" for \" << name_ << \" from returnBuffer\";\n+\n+\t\t\tint ret = dev_->queueBuffer(buffer);\n+\t\t\tif (ret)\n+\t\t\t\tLOG(RPISTREAM, Error) << \"Failed to queue buffer for \"\n+\t\t\t\t\t\t << name_ << \" from returnBuffer\";\n+\t\t}\n \t}\n \n \tbool findFrameBuffer(FrameBuffer *buffer) const\n@@ -178,6 +227,7 @@ private:\n \tvoid clearBuffers()\n \t{\n \t\tavailableBuffers_ = std::queue<FrameBuffer *>{};\n+\t\trequeueBuffers_ = std::queue<FrameBuffer *>{};\n \t\tinternalBuffers_.clear();\n \t\tbufferList_.clear();\n \t}\n@@ -193,7 +243,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@@ -201,6 +251,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", "8/9" ] }