{"id":9656,"url":"https://patchwork.libcamera.org/api/1.1/patches/9656/?format=json","web_url":"https://patchwork.libcamera.org/patch/9656/","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":"<20200918094233.5273-12-naush@raspberrypi.com>","date":"2020-09-18T09:42:32","name":"[libcamera-devel,v8,11/12] pipeline: raspberrypi: Use an unordered_set to store IPA buffer ids","commit_ref":"dd0df6d73965bc8566ad97d0e005545a71b7b409","pull_url":null,"state":"accepted","archived":false,"hash":"23a73768a77a2a1c3a9b926f3fbc011b2c4d5e89","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/9656/mbox/","series":[{"id":1295,"url":"https://patchwork.libcamera.org/api/1.1/series/1295/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1295","date":"2020-09-18T09:42:21","name":"Zero-copy RAW stream work","version":8,"mbox":"https://patchwork.libcamera.org/series/1295/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9656/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9656/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 3AB88C3B5B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 18 Sep 2020 09:44:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 092E762FC4;\n\tFri, 18 Sep 2020 11:44:09 +0200 (CEST)","from mail-wr1-x441.google.com (mail-wr1-x441.google.com\n\t[IPv6:2a00:1450:4864:20::441])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 10FBB62FAD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Sep 2020 11:44:07 +0200 (CEST)","by mail-wr1-x441.google.com with SMTP id t10so4961873wrv.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Sep 2020 02:44:07 -0700 (PDT)","from naushir-VirtualBox.pitowers.org\n\t([2a00:1098:3142:14:a00:27ff:fe4d:f6a2])\n\tby smtp.gmail.com with ESMTPSA id\n\tn2sm4792472wma.29.2020.09.18.02.44.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 18 Sep 2020 02:44: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=\"MI43aiZL\"; 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=VeqvmYrPOcZHFidx2F0bdpH4CTa6e7IqqNLmBrr4td4=;\n\tb=MI43aiZL93zDzh+/ViAjdRerpI+1DL/L8hHpGbSNt7rrPccMv2A6f43JNbyIw9mBbz\n\tuKBTYNp7XT6iy64PGw7RBaU6O8PS1VsslzEo7tSD/9hHDuIi05FWbL/YeZeYfCyFXhLL\n\t8xg25QLlY0TGRyGKbAMOnETFpa7kPQYu8XloOP9HevXzvnTqmLw7S9vtqYIP2LGNZqgo\n\tAcl7iHLVkvyYouoi/i5JUx0urWR9RrXa3zPJ80dVfW1OwJvnEqtxUJ5aiUykuz1owivo\n\t5mjXxI8j5NRExU3Q2FTwiIG/+cHhEIjIpeGxkSnhbyMPTSyQPtNJHsbxli+VsdwOUjWY\n\tt00g==","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=VeqvmYrPOcZHFidx2F0bdpH4CTa6e7IqqNLmBrr4td4=;\n\tb=Z4PrSTVcto3IL6S+Ol2AMQqJJhoUSwk+E7JCoYAIIFAKgPmGZDiBL55/sEJRnffTgL\n\tOb2JfS2SEdHD4vbNSRIlntVWUK5kJw234K0SRHnZXgcDsKaHuGPnz3gTkmm30qqEsuO4\n\teBBfm6vGv3ZWaIJ26zuuAbUvgRtGcNmkt1K1aPH8xdhcYqD2dehYGqrx6Ji7pNnv7jNN\n\tGMt6ReWXuud3A8/lUWd+ZGJQWr9ujyhCkTDpVUqNA3r7XxK2TKGysNHkUN3RGJxLTMrM\n\tiIqV2p6G5wttnTuoewOln8TKp/YvzkhxTboTfSbOYw2psGdJB+PKFlaMuX9pZv1S8uE6\n\toGtQ==","X-Gm-Message-State":"AOAM532o2+LcfvcXbZ/XyMkCfgyslHIvPoYD2QlydkcF03oA174UkTMp\n\tTNNzUYscL7ckUJgfNrV0YCibWFwM/PSxBg==","X-Google-Smtp-Source":"ABdhPJwETLDlad2lov/ngClBjEcrSBvF5UMHYy51vR1Imp5SGah7ihGxn0RjaQ/yr/plzrAw3/+mEQ==","X-Received":"by 2002:a5d:50cd:: with SMTP id\n\tf13mr32695803wrt.211.1600422246215; \n\tFri, 18 Sep 2020 02:44:06 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 18 Sep 2020 10:42:32 +0100","Message-Id":"<20200918094233.5273-12-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20200918094233.5273-1-naush@raspberrypi.com>","References":"<20200918094233.5273-1-naush@raspberrypi.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v8 11/12] pipeline: raspberrypi: Use an\n\tunordered_set to store IPA buffer ids","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=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"By using a set container, we can easily insert/remove buffer ids that have\nbeen mmaped by the IPA. This will be required to track buffers allocated\nexternally and passed to the pipeline handler through a Request.\n\nMove the IPA buffer mapping code into a function to remove duplicated\ncode.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 48 +++++++++++--------\n 1 file changed, 28 insertions(+), 20 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 51544233..4e12c7d6 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -10,6 +10,7 @@\n #include <mutex>\n #include <queue>\n #include <sys/mman.h>\n+#include <unordered_set>\n \n #include <libcamera/camera.h>\n #include <libcamera/control_ids.h>\n@@ -158,8 +159,8 @@ public:\n \tRPi::RPiDevice<Isp, 4> isp_;\n \t/* The vector below is just for convenience when iterating over all streams. */\n \tstd::vector<RPi::RPiStream *> streams_;\n-\t/* Buffers passed to the IPA. */\n-\tstd::vector<IPABuffer> ipaBuffers_;\n+\t/* Stores the ids of the buffers mapped in the IPA. */\n+\tstd::unordered_set<unsigned int> ipaBuffers_;\n \n \t/* DMAHEAP allocation helper. */\n \tRPi::DmaHeap dmaHeap_;\n@@ -230,6 +231,7 @@ private:\n \tint queueAllBuffers(Camera *camera);\n \tint prepareBuffers(Camera *camera);\n \tvoid freeBuffers(Camera *camera);\n+\tvoid mapBuffers(Camera *camera, const RPi::BufferMap &buffers, unsigned int mask);\n \n \tMediaDevice *unicam_;\n \tMediaDevice *isp_;\n@@ -910,36 +912,42 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n \t}\n \n \t/*\n-\t * Link the FrameBuffers with the index of their position in the vector\n-\t * stored in the RPi stream object.\n+\t * Pass the stats and embedded data buffers to the IPA. No other\n+\t * buffers need to be passed.\n+\t */\n+\tmapBuffers(camera, data->isp_[Isp::Stats].getBuffers(), RPiIpaMask::STATS);\n+\tmapBuffers(camera, data->unicam_[Unicam::Embedded].getBuffers(), RPiIpaMask::EMBEDDED_DATA);\n+\n+\treturn 0;\n+}\n+\n+void PipelineHandlerRPi::mapBuffers(Camera *camera, const RPi::BufferMap &buffers, unsigned int mask)\n+{\n+\tRPiCameraData *data = cameraData(camera);\n+\tstd::vector<IPABuffer> ipaBuffers;\n+\t/*\n+\t * Link the FrameBuffers with the id (key value) in the map stored in\n+\t * the RPi stream object - along with an identifier mask.\n \t *\n \t * This will allow us to identify buffers passed between the pipeline\n \t * handler and the IPA.\n \t */\n-\tfor (auto const &b : data->isp_[Isp::Stats].getBuffers()) {\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-\tfor (auto const &b : data->unicam_[Unicam::Embedded].getBuffers()) {\n-\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::EMBEDDED_DATA | b.first,\n-\t\t\t\t\t      .planes = b.second->planes() });\n+\tfor (auto const &it : buffers) {\n+\t\tipaBuffers.push_back({ .id = mask | it.first,\n+\t\t\t\t       .planes = it.second->planes() });\n+\t\tdata->ipaBuffers_.insert(mask | it.first);\n \t}\n \n-\tdata->ipa_->mapBuffers(data->ipaBuffers_);\n-\n-\treturn 0;\n+\tdata->ipa_->mapBuffers(ipaBuffers);\n }\n \n void PipelineHandlerRPi::freeBuffers(Camera *camera)\n {\n \tRPiCameraData *data = cameraData(camera);\n \n-\tstd::vector<unsigned int> ids;\n-\tfor (IPABuffer &ipabuf : data->ipaBuffers_)\n-\t\tids.push_back(ipabuf.id);\n-\n-\tdata->ipa_->unmapBuffers(ids);\n+\t/* Copy the buffer ids from the unordered_set to a vector to pass to the IPA. */\n+\tstd::vector<unsigned int> ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end());\n+\tdata->ipa_->unmapBuffers(ipaBuffers);\n \tdata->ipaBuffers_.clear();\n \n \tfor (auto const stream : data->streams_)\n","prefixes":["libcamera-devel","v8","11/12"]}