{"id":9175,"url":"https://patchwork.libcamera.org/api/1.1/patches/9175/?format=json","web_url":"https://patchwork.libcamera.org/patch/9175/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200804095850.275499-11-naush@raspberrypi.com>","date":"2020-08-04T09:58:48","name":"[libcamera-devel,v6,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/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9175/mbox/","series":[{"id":1187,"url":"https://patchwork.libcamera.org/api/1.1/series/1187/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1187","date":"2020-08-04T09:58:38","name":"Zero-copy RAW stream work","version":6,"mbox":"https://patchwork.libcamera.org/series/1187/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9175/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9175/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 621E4BD87B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  4 Aug 2020 09:59:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3235E60555;\n\tTue,  4 Aug 2020 11:59:08 +0200 (CEST)","from mail-wr1-x431.google.com (mail-wr1-x431.google.com\n\t[IPv6:2a00:1450:4864:20::431])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E9446049B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  4 Aug 2020 11:59:07 +0200 (CEST)","by mail-wr1-x431.google.com with SMTP id a5so26836760wrm.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 04 Aug 2020 02:59:07 -0700 (PDT)","from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\t32sm34047234wrh.18.2020.08.04.02.59.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 04 Aug 2020 02:59: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=\"GAvIDGRw\"; 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=lt8mUVcYxjuDMyoiYlgrDc1BgLMPQm+IF3xYVvJO6nE=;\n\tb=GAvIDGRwH3HW+ReFTq6lpAp9r7mnOueCbMwygc+C+LAw0ojD7ss4Xjx23uOoy5vFJ9\n\t2ryCQ/SVCFcMTwv4MN7Gs4eo0YJUXkrvyXOptXQqXYctjV3EXx6Ner96/VzQHk0ZQhqz\n\tg62l4zleBB5Ormy1NXr42sUpoQjzSFFmeYPHKDbcbpS1OQJO026GegjghOtpCtbqkcUD\n\t8Z/ho0pFtVVudhzTES1wW7zjeJaDvjpY4RBxWeBTY9fEAHk87LcKhYfwdNhC4t0Zftwq\n\tqjyk1Yis2FnhVpJO2paxKT1PBYsHka8x25LwimoIoqXO/6R3g+x8VVTiLzkb9GMlGsNW\n\tluvg==","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=lt8mUVcYxjuDMyoiYlgrDc1BgLMPQm+IF3xYVvJO6nE=;\n\tb=SCJLM4ssQDPKwMXmpa9fNAN/3NJsHwHIqWdcjzr30EB3PIX2k/6ZD0IcYQcUhS+Ey4\n\tfyAYI5qYuBCAzEpPQOz8bjc6f5acuI76NTO4GojzhVypwOOoZayj7ZyrVFm+FN4+cCdr\n\tmQukrmf+dquN/4O9t+gqvi4jNA3jY+rxvnhLOaR+5cbS3n+LRQmolRVBGtEuD7A2e/X5\n\tOQvuZ00CxpRgQB87W+1pF+yrFbQ7V6B7/NbtYiQbxXqFxhpQXFXAP2+BnuaISFjfZ8LF\n\tXYin/RDtCs6kp7Q/aLt1bGpY7P6etDHUsj/dQro9dPkwWY5UdMZrp8RkHOfEpVoe6fMv\n\tE6Sg==","X-Gm-Message-State":"AOAM532hzkDe+7l7HCwcZ7O7yKRf49ilPwLUa8NXX91ae8wt9oH8Irdy\n\tnsiaHXGTm69rBe2Tg+ul2gMARPn2rLg0Hg==","X-Google-Smtp-Source":"ABdhPJx71tB9tTTJPiLXhEahmipwzYZ31Rkx8knKqf/dbHwMDmMcBkZAZY3tzHFMquhho5fRBeMZDQ==","X-Received":"by 2002:adf:e992:: with SMTP id\n\th18mr17933568wrm.383.1596535146432; \n\tTue, 04 Aug 2020 02:59:06 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  4 Aug 2020 10:58:48 +0100","Message-Id":"<20200804095850.275499-11-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20200804095850.275499-1-naush@raspberrypi.com>","References":"<20200804095850.275499-1-naush@raspberrypi.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v6 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 250bbf32..8cfa87be 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -881,7 +881,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@@ -908,18 +907,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@@ -1124,7 +1119,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@@ -1175,7 +1170,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@@ -1192,7 +1187,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@@ -1429,8 +1424,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","v6","10/12"]}