Patch Detail
Show a patch.
GET /api/patches/9526/?format=api
{ "id": 9526, "url": "https://patchwork.libcamera.org/api/patches/9526/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9526/", "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": "<20200908074913.109244-11-naush@raspberrypi.com>", "date": "2020-09-08T07:49:10", "name": "[libcamera-devel,v7,10/12] pipeline: raspberrypi: Use an unordered_map for the stream buffer list", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "541fea3d235a3d83474fd7d5a09994a1d79f732e", "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/9526/mbox/", "series": [ { "id": 1271, "url": "https://patchwork.libcamera.org/api/series/1271/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1271", "date": "2020-09-08T07:49:00", "name": "Zero-copy RAW stream work", "version": 7, "mbox": "https://patchwork.libcamera.org/series/1271/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9526/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9526/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 BEA59BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 8 Sep 2020 07:49:31 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8AF4462C2F;\n\tTue, 8 Sep 2020 09:49:31 +0200 (CEST)", "from mail-wr1-x429.google.com (mail-wr1-x429.google.com\n\t[IPv6:2a00:1450:4864:20::429])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EDD9462BAA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 8 Sep 2020 09:49:29 +0200 (CEST)", "by mail-wr1-x429.google.com with SMTP id z4so18025562wrr.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 08 Sep 2020 00:49:29 -0700 (PDT)", "from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tq15sm32534502wrr.8.2020.09.08.00.49.28\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 08 Sep 2020 00:49:28 -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=\"UZh1fpPP\"; 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=MR4GBDeEwsdkEea4GUgguWUuMoirZnEcLbA3FTMTiIg=;\n\tb=UZh1fpPPIj7NPrzFXHye7bekiPQsAj0XVd9w49PuuGCURXda6AHGjzJ/Uxx7tLdHpZ\n\tC+NkmrnJUGFs1uC2q4/C4JfeqJdk8aOiN/QFaha45yzDIyyE1745kVceecHgAZxgj36S\n\tHtqgfpNVgoZWGAItPvfrsGgxMpYBI46jnfEByCrWoWuySbL7R+PaOIhziqLMj6jt4mx8\n\tEu5mq+aNN23faKDG4UvPDAd+pAOeDGn5axsyyUpVC9sDw4Es5ZcqVQZ5ZtFIpPgkOo1B\n\tA+rTu4p9ZAk2bvc3ptX8RrASkL/1L6nZ3vnnTOZD7n7oBh6pqwj5k1EsqupybcYxfYyW\n\tVjyg==", "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=MR4GBDeEwsdkEea4GUgguWUuMoirZnEcLbA3FTMTiIg=;\n\tb=seVF6+awmL2C2JlkqfvaBzphnCjLhmpgFIljgwUjPPvZXay3OZdUiCXx+rDN5l9vX8\n\tbBOqmSWc0k4WzN5k+r32S2KtLuO9XFu8WxDNb7u1jnz7UOn6JFDvbmiEnUlReBkMlhK8\n\tYISM5yslXY5eqFxDfNKUpgLioWVQu1U9BoSRGdW9OaRp9ap2REpXKT2WjJUkEIFEBgBc\n\tRrMyZUD0cbDYUO1V+kH+zZu+qIZJ3LKSaPPDRFNv3CDq7BhO1VMlm2ACLsNFZejDFrtB\n\tqGJaVOcqOdUUv2W2zLRa/FdkXjB+0AN0odPeiO0rPYNCvB5I2rJdabcPxBvSA7EhJuD7\n\tuFLQ==", "X-Gm-Message-State": "AOAM532EMoJXxGNncl/QD0cEGfg/Pe5cXfvXjFwaLBGXyJk79qCqkK1C\n\tuvDJ4nrkhLpjISgjBF72tJiO4gW1fofsSw==", "X-Google-Smtp-Source": "ABdhPJyRyGRprEoHdhJ45RxLjIRC4WLvr6opPkT8+Cv3yPQqREF1t6x0qqXMDSFp60ZPG3V0JFUjng==", "X-Received": "by 2002:a5d:4c88:: with SMTP id\n\tz8mr25302827wrs.218.1599551369311; \n\tTue, 08 Sep 2020 00:49:29 -0700 (PDT)", "From": "Naushir Patuck <naush@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 8 Sep 2020 08:49:10 +0100", "Message-Id": "<20200908074913.109244-11-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20200908074913.109244-1-naush@raspberrypi.com>", "References": "<20200908074913.109244-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v7 10/12] pipeline: raspberrypi: Use an\n\tunordered_map for the stream buffer list", "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": "By using a map container, we can easily insert/remove buffers from the\nbuffer list. This will be required to track buffers allocated externally\nand passed to the pipeline handler through a Request.\n\nReplace the buffer index tracking with an id generated internally by the\nstream object.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp | 23 ++++++---------\n .../pipeline/raspberrypi/rpi_stream.cpp | 28 ++++++++++---------\n .../pipeline/raspberrypi/rpi_stream.h | 14 +++++++---\n 3 files changed, 34 insertions(+), 31 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 341ee6ce..6aa13034 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -890,7 +890,6 @@ int PipelineHandlerRPi::queueAllBuffers(Camera *camera)\n int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n {\n \tRPiCameraData *data = cameraData(camera);\n-\tunsigned int index;\n \tint ret;\n \n \t/*\n@@ -917,18 +916,14 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n \t * This will allow us to identify buffers passed between the pipeline\n \t * handler and the IPA.\n \t */\n-\tindex = 0;\n \tfor (auto const &b : data->isp_[Isp::Stats].getBuffers()) {\n-\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::STATS | index,\n-\t\t\t\t\t .planes = b->planes() });\n-\t\tindex++;\n+\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::STATS | b.first,\n+\t\t\t\t\t .planes = b.second->planes() });\n \t}\n \n-\tindex = 0;\n \tfor (auto const &b : data->unicam_[Unicam::Embedded].getBuffers()) {\n-\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::EMBEDDED_DATA | index,\n-\t\t\t\t\t .planes = b->planes() });\n-\t\tindex++;\n+\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::EMBEDDED_DATA | b.first,\n+\t\t\t\t\t .planes = b.second->planes() });\n \t}\n \n \tdata->ipa_->mapBuffers(data->ipaBuffers_);\n@@ -1127,7 +1122,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n \t\treturn;\n \n \tfor (RPi::RPiStream &s : unicam_) {\n-\t\tindex = s.getBufferIndex(buffer);\n+\t\tindex = s.getBufferId(buffer);\n \t\tif (index != -1) {\n \t\t\tstream = &s;\n \t\t\tbreak;\n@@ -1178,7 +1173,7 @@ void RPiCameraData::ispInputDequeue(FrameBuffer *buffer)\n \t\treturn;\n \n \tLOG(RPI, Debug) << \"Stream ISP Input buffer complete\"\n-\t\t\t<< \", buffer id \" << unicam_[Unicam::Image].getBufferIndex(buffer)\n+\t\t\t<< \", buffer id \" << unicam_[Unicam::Image].getBufferId(buffer)\n \t\t\t<< \", timestamp: \" << buffer->metadata().timestamp;\n \n \t/* The ISP input buffer gets re-queued into Unicam. */\n@@ -1195,7 +1190,7 @@ void RPiCameraData::ispOutputDequeue(FrameBuffer *buffer)\n \t\treturn;\n \n \tfor (RPi::RPiStream &s : isp_) {\n-\t\tindex = s.getBufferIndex(buffer);\n+\t\tindex = s.getBufferId(buffer);\n \t\tif (index != -1) {\n \t\t\tstream = &s;\n \t\t\tbreak;\n@@ -1432,8 +1427,8 @@ void RPiCameraData::tryRunPipeline()\n \t/* Set our state to say the pipeline is active. */\n \tstate_ = State::Busy;\n \n-\tunsigned int bayerIndex = unicam_[Unicam::Image].getBufferIndex(bayerBuffer);\n-\tunsigned int embeddedIndex = unicam_[Unicam::Embedded].getBufferIndex(embeddedBuffer);\n+\tunsigned int bayerIndex = unicam_[Unicam::Image].getBufferId(bayerBuffer);\n+\tunsigned int embeddedIndex = unicam_[Unicam::Embedded].getBufferId(embeddedBuffer);\n \n \tLOG(RPI, Debug) << \"Signalling RPI_IPA_EVENT_SIGNAL_ISP_PREPARE:\"\n \t\t\t<< \" Bayer buffer id: \" << bayerIndex\ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\nindex 80170d64..879e25ba 100644\n--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n@@ -44,26 +44,28 @@ bool RPiStream::isExternal() const\n \n void RPiStream::setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n {\n-\tstd::transform(buffers->begin(), buffers->end(), std::back_inserter(bufferList_),\n-\t\t [](std::unique_ptr<FrameBuffer> &b) { return b.get(); });\n+\tfor (auto const &buffer : *buffers)\n+\t\tbufferMap_.emplace(id_++, buffer.get());\n }\n \n-const std::vector<FrameBuffer *> &RPiStream::getBuffers() const\n+const BufferMap &RPiStream::getBuffers() const\n {\n-\treturn bufferList_;\n+\treturn bufferMap_;\n }\n \n-int RPiStream::getBufferIndex(FrameBuffer *buffer) const\n+int RPiStream::getBufferId(FrameBuffer *buffer) const\n {\n \tif (importOnly_)\n \t\treturn -1;\n \n-\t/* Find the buffer in the list, and return the index position. */\n-\tauto it = std::find(bufferList_.begin(), bufferList_.end(), buffer);\n-\tif (it != bufferList_.end())\n-\t\treturn std::distance(bufferList_.begin(), it);\n+\t/* Find the buffer in the map, and return the buffer id. */\n+\tauto it = std::find_if(bufferMap_.begin(), bufferMap_.end(),\n+\t\t\t [&buffer](auto const &p) { return p.second == buffer; });\n \n-\treturn -1;\n+\tif (it == bufferMap_.end())\n+\t\treturn -1;\n+\n+\treturn it->first;\n }\n \n int RPiStream::prepareBuffers(unsigned int count)\n@@ -86,7 +88,7 @@ int RPiStream::prepareBuffers(unsigned int count)\n \t\t}\n \n \t\t/* We must import all internal/external exported buffers. */\n-\t\tcount = bufferList_.size();\n+\t\tcount = bufferMap_.size();\n \t}\n \n \treturn dev_->importBuffers(count);\n@@ -196,12 +198,12 @@ void RPiStream::clearBuffers()\n \tavailableBuffers_ = std::queue<FrameBuffer *>{};\n \trequestBuffers_ = std::queue<FrameBuffer *>{};\n \tinternalBuffers_.clear();\n-\tbufferList_.clear();\n+\tbufferMap_.clear();\n }\n \n int RPiStream::queueToDevice(FrameBuffer *buffer)\n {\n-\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << getBufferIndex(buffer)\n+\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << getBufferId(buffer)\n \t\t\t << \" for \" << name_;\n \n \tint ret = dev_->queueBuffer(buffer);\ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\nindex 959e9147..ed517c22 100644\n--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n@@ -9,6 +9,7 @@\n \n #include <queue>\n #include <string>\n+#include <unordered_map>\n #include <vector>\n \n #include <libcamera/stream.h>\n@@ -19,6 +20,8 @@ namespace libcamera {\n \n namespace RPi {\n \n+using BufferMap = std::unordered_map<unsigned int, FrameBuffer *>;\n+\n /*\n * Device stream abstraction for either an internal or external stream.\n * Used for both Unicam and the ISP.\n@@ -32,7 +35,7 @@ public:\n \n \tRPiStream(const char *name, MediaEntity *dev, bool importOnly = false)\n \t\t: external_(false), importOnly_(importOnly), name_(name),\n-\t\t dev_(std::make_unique<V4L2VideoDevice>(dev))\n+\t\t dev_(std::make_unique<V4L2VideoDevice>(dev)), id_(0)\n \t{\n \t}\n \n@@ -45,8 +48,8 @@ public:\n \tbool isExternal() const;\n \n \tvoid setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n-\tconst std::vector<FrameBuffer *> &getBuffers() const;\n-\tint getBufferIndex(FrameBuffer *buffer) const;\n+\tconst BufferMap &getBuffers() const;\n+\tint getBufferId(FrameBuffer *buffer) const;\n \n \tint prepareBuffers(unsigned int count);\n \tint queueBuffer(FrameBuffer *buffer);\n@@ -74,8 +77,11 @@ private:\n \t/* The actual device stream. */\n \tstd::unique_ptr<V4L2VideoDevice> dev_;\n \n+\t/* Tracks a unique id key for the bufferMap_ */\n+\tunsigned int id_;\n+\n \t/* All frame buffers associated with this device stream. */\n-\tstd::vector<FrameBuffer *> bufferList_;\n+\tBufferMap bufferMap_;\n \n \t/*\n \t * List of frame buffers that we can use if none have been provided by\n", "prefixes": [ "libcamera-devel", "v7", "10/12" ] }