From patchwork Tue Sep 8 07:49:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 9527 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 29077BDB1E for ; Tue, 8 Sep 2020 07:49:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E50D262C31; Tue, 8 Sep 2020 09:49:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="J3qecZdC"; dkim-atps=neutral Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0751D62C27 for ; Tue, 8 Sep 2020 09:49:31 +0200 (CEST) Received: by mail-wr1-x444.google.com with SMTP id c18so17983310wrm.9 for ; Tue, 08 Sep 2020 00:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DXlCmLR+6xccYNyuaOP6y9KyOurPOW50qeSaoIlpP0U=; b=J3qecZdCdqzu4aTjuSiWiujdiDxwvaMFQ0RL1U0jlH4M+isLA0FXAdQ3TLF3nZLpp3 THNsv9D2T8OfiMZUFY1iMqs85jfbm6GLsE+Pyi8xskj/djVdcKyCE9P9vbFkIpIB+KMG JbGoVnnfjvN4sjFOB/Cg0m0Vzq9E0fjMT2o+JN9fT039PvC1IPQmA1yxS07+cchiOdae AJybdGpIBChYJwDGRg06bht0x2rHEvF673skikXT7kHcN95IU5uov2fU9gn+S+9a+UE2 R2F8vWruGpvq9Dhao6s5NKqugUHnjuQvH74NDwNycweSSXMb00wc/0iq91ER8eRfuasX noXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DXlCmLR+6xccYNyuaOP6y9KyOurPOW50qeSaoIlpP0U=; b=t9kUTa9d9a8hTQsGsSel+P2BU7sNdxWoMGFkIVfc76NbL8pWFebWAk72HJK/SiJeWq nYeZJiO13yEziojOzHz5rbR1PrHMGW2fomptrNccRms5RsKzTj4wshqYPb+d2GCMAA4B MsQ1zrBltfjCum7l46/hgTZIb3IGm9UaHy0IUOK6cMoGn7FNRPNegC+NH8RG3gWnJ0Nw nEyiCp+z6kDNLUS8ukyX0AiLR9v69iJiQyETVmXe/Jo5WoI+o48iGwmWr/gcseoyDKD/ na3Q0vALuWhWvPlB6vVClBcZQmYrer8854VU+eo7OGhFSQnQnPPZgrsPBR1t9xoq8bue 84ZA== X-Gm-Message-State: AOAM532G/57jSVCTFSXmiwPzhKBbTvZ3DnlhOjaXJ+xzFRmhVD1D2Ju7 DEuFGUcGNR4Bl+AhFnk01wVcqy1JeJZmeA== X-Google-Smtp-Source: ABdhPJxK6sXfE5f4/mo4nxcSvi1JHTSv/LqPIgmo2VzgzpjW5vILEfiuJWeLupxpW3fXonsKkRmCsg== X-Received: by 2002:adf:81c6:: with SMTP id 64mr24475854wra.176.1599551370455; Tue, 08 Sep 2020 00:49:30 -0700 (PDT) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id q15sm32534502wrr.8.2020.09.08.00.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 00:49:29 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Sep 2020 08:49:11 +0100 Message-Id: <20200908074913.109244-12-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 11/12] pipeline: raspberrypi: Use an unordered_set to store IPA buffer ids X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" By using a set container, we can easily insert/remove buffer ids that have been mmaped by the IPA. This will be required to track buffers allocated externally and passed to the pipeline handler through a Request. Move the IPA buffer mapping code into a function to remove duplicated code. Signed-off-by: Naushir Patuck Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- .../pipeline/raspberrypi/raspberrypi.cpp | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 6aa13034..5621f182 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -158,8 +159,8 @@ public: RPi::RPiDevice isp_; /* The vector below is just for convenience when iterating over all streams. */ std::vector streams_; - /* Buffers passed to the IPA. */ - std::vector ipaBuffers_; + /* Stores the ids of the buffers mapped in the IPA. */ + std::unordered_set ipaBuffers_; /* DMAHEAP allocation helper. */ RPi::DmaHeap dmaHeap_; @@ -230,6 +231,7 @@ private: int queueAllBuffers(Camera *camera); int prepareBuffers(Camera *camera); void freeBuffers(Camera *camera); + void mapBuffers(Camera *camera, const RPi::BufferMap &buffers, unsigned int mask); MediaDevice *unicam_; MediaDevice *isp_; @@ -910,36 +912,42 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera) } /* - * Link the FrameBuffers with the index of their position in the vector - * stored in the RPi stream object. + * Pass the stats and embedded data buffers to the IPA. No other + * buffers need to be passed. + */ + mapBuffers(camera, data->isp_[Isp::Stats].getBuffers(), RPiIpaMask::STATS); + mapBuffers(camera, data->unicam_[Unicam::Embedded].getBuffers(), RPiIpaMask::EMBEDDED_DATA); + + return 0; +} + +void PipelineHandlerRPi::mapBuffers(Camera *camera, const RPi::BufferMap &buffers, unsigned int mask) +{ + RPiCameraData *data = cameraData(camera); + std::vector ipaBuffers; + /* + * Link the FrameBuffers with the id (key value) in the map stored in + * the RPi stream object - along with an identifer mask. * * This will allow us to identify buffers passed between the pipeline * handler and the IPA. */ - for (auto const &b : data->isp_[Isp::Stats].getBuffers()) { - data->ipaBuffers_.push_back({ .id = RPiIpaMask::STATS | b.first, - .planes = b.second->planes() }); - } - - for (auto const &b : data->unicam_[Unicam::Embedded].getBuffers()) { - data->ipaBuffers_.push_back({ .id = RPiIpaMask::EMBEDDED_DATA | b.first, - .planes = b.second->planes() }); + for (auto const &it : buffers) { + ipaBuffers.push_back({ .id = mask | it.first, + .planes = it.second->planes() }); + data->ipaBuffers_.insert(mask | it.first); } - data->ipa_->mapBuffers(data->ipaBuffers_); - - return 0; + data->ipa_->mapBuffers(ipaBuffers); } void PipelineHandlerRPi::freeBuffers(Camera *camera) { RPiCameraData *data = cameraData(camera); - std::vector ids; - for (IPABuffer &ipabuf : data->ipaBuffers_) - ids.push_back(ipabuf.id); - - data->ipa_->unmapBuffers(ids); + /* Copy the buffer ids from the unordered_set to a vector to pass to the IPA. */ + std::vector ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end()); + data->ipa_->unmapBuffers(ipaBuffers); data->ipaBuffers_.clear(); for (auto const stream : data->streams_)