From patchwork Fri Jul 17 08:54:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 8848 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 70071C0109 for ; Fri, 17 Jul 2020 08:54:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3352F6053A; Fri, 17 Jul 2020 10:54:28 +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="nRbqjsSx"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3DAF46054C for ; Fri, 17 Jul 2020 10:54:25 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id f139so16039115wmf.5 for ; Fri, 17 Jul 2020 01:54:25 -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=YqGfCQ7TR779z8O5CQTjcZsNXHDUsTejqHSEgFaeGIU=; b=nRbqjsSxf+Dp3HjgLjBCK7krXVWbBXF9bwXqvzDZJfOpBtunFqju2Cccknd4PLgIwe MLLlQTNTM3hmTmZBXv031DgVLhTToJcBmGrAzBrar649cydDqXSG+tGjv9uFbLVs22wE 2cOeXQJdjMyCtpg7wcyj10HE0S0uKYrxdiK2Bs43b+xe01pppejpvRgTpdJg85bnjGMP 8h18wLkOAywvgWvsq7O4n/5Se6jAXHBjo4kGFeaWZ+A05C9Sa1VL8f9mKzgQnsZFlzZP 4581NeoSb597xHm54MNinaeHvcZvPBmXZ59bKQ96Xw0rWJwVT0gpBDLjb4uDvKJ7PfAP B9qA== 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=YqGfCQ7TR779z8O5CQTjcZsNXHDUsTejqHSEgFaeGIU=; b=qI7zeCuvtZ9RiPCIzAY4FVdaTCa0TAAFYpYcZvdg35QaNWFxZqhAKO2lVcxQeikqGS cSWEKQPRASnE+cPtfdFlbI9Uq3o6iKudlIyA8KPnXeaT3W2hZNtQfFEOX9WrmvVfB3CB w3gbkqEmQ1gRsNdCpfWxj89SVoCaZNj+72ShEbmAE/jA1ZQlm8f+Hf3JwmQIPyb/QiOQ eLZxZY8Mk58HU6oz5B8R5r7vym8ziomGmGQJMWD3u/z90orjXly/6NuEGHeeoB0k3eb2 eldIc/81fBKTNXnspy0hcPAjMI27Bp0H6XMNakoQVuUFMihItKfWZgKtZG+irzBb8E+u /6Xg== X-Gm-Message-State: AOAM533LZmsZJ3boWjQXI0aKBUkcpMzK3+S+jHBxIPWzcE9HJcddKQKx aAD04lTFefkCtbHCcgtkqXmVSS3XdWQ= X-Google-Smtp-Source: ABdhPJzT3qtvlOvtMtyhBrYRq6x6jD0AE3t5OlfmW2cwb5mSezoVWIZW/EC9opQgS/OAlxl2/PYaiQ== X-Received: by 2002:a1c:7510:: with SMTP id o16mr7734154wmc.146.1594976064398; Fri, 17 Jul 2020 01:54:24 -0700 (PDT) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id 92sm14582375wrr.96.2020.07.17.01.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 01:54:23 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 17 Jul 2020 09:54:10 +0100 Message-Id: <20200717085410.732308-11-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717085410.732308-1-naush@raspberrypi.com> References: <20200717085410.732308-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 10/10] libcamera: pipeline: raspberrypi: Handle any externally allocated FrameBuffer 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" Handle the case where a FrameBuffer that has been externally allocated (i.e. not through the v4l2 video device) is passed into a Request. We must store the buffer pointer in our internal buffer list to identify when used, as well as mmap the buffer in the IPA if needed. Signed-off-by: Naushir Patuck --- .../pipeline/raspberrypi/raspberrypi.cpp | 94 +++++++++++-------- .../pipeline/raspberrypi/rpi_stream.cpp | 5 + .../pipeline/raspberrypi/rpi_stream.h | 1 + 3 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index e400c10c..99896eee 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -171,8 +171,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::vector ipaBufferIds_; /* VCSM allocation helper. */ ::RPi::Vcsm vcsm_; @@ -192,7 +192,6 @@ public: std::queue bayerQueue_; std::queue embeddedQueue_; std::deque requestQueue_; - unsigned int dropFrameCount_; private: @@ -243,6 +242,8 @@ private: int queueAllBuffers(Camera *camera); int prepareBuffers(Camera *camera); void freeBuffers(Camera *camera); + void mapBuffers(Camera *camera, const std::vector &buffers, + unsigned int startId); MediaDevice *unicam_; MediaDevice *isp_; @@ -736,20 +737,38 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) /* Push all buffers supplied in the Request to the respective streams. */ for (auto stream : data->streams_) { - if (stream->isExternal()) { - FrameBuffer *buffer = request->findBuffer(stream); + if (!stream->isExternal()) + continue; + + FrameBuffer *buffer = request->findBuffer(stream); + if (buffer && stream->getBufferIndex(buffer) == -1) { /* - * A nullptr in buffer means that we should queue an internally - * allocated buffer. - * - * The below queueBuffer() call will do nothing if there are not - * enough internal buffers allocated, but this will be handled by - * queuing the request for buffers in the RPiStream object. + * This buffer is not recognised, so it must have been allocated + * outside the v4l2 device. Store it in the stream buffer list + * so we can track it. */ - int ret = stream->queueBuffer(buffer); - if (ret) - return ret; + stream->setExternalBuffer(buffer); + + /* Also get the IPA to mmap it if needed. */ + if (stream == &data->unicam_[Unicam::Embedded]) { + mapBuffers(camera, { buffer }, + RPiIpaMask::EMBEDDED_DATA | (stream->getBuffers().size() - 1)); + } else if (stream == &data->isp_[Isp::Stats]) { + mapBuffers(camera, { buffer }, + RPiIpaMask::STATS | (stream->getBuffers().size() - 1)); + } } + /* + * A nullptr in buffer means that we should queue an internally + * allocated buffer. + * + * The below queueBuffer() call will do nothing if there are not + * enough internal buffers allocated, but this will be handled by + * queuing the request for buffers in the RPiStream object. + */ + int ret = stream->queueBuffer(buffer); + if (ret) + return ret; } /* Push the request to the back of the queue. */ @@ -888,7 +907,6 @@ int PipelineHandlerRPi::queueAllBuffers(Camera *camera) int PipelineHandlerRPi::prepareBuffers(Camera *camera) { RPiCameraData *data = cameraData(camera); - unsigned int index; int ret; /* @@ -908,42 +926,44 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera) return ret; } + /* + * 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 std::vector &buffers, + unsigned int startId) +{ + RPiCameraData *data = cameraData(camera); + std::vector ipaBuffers; + unsigned int id = startId; /* * Link the FrameBuffers with the index of their position in the vector - * stored in the RPi stream object. + * 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. */ - index = 0; - for (auto const &b : data->isp_[Isp::Stats].getBuffers()) { - data->ipaBuffers_.push_back({ .id = RPiIpaMask::STATS | index, - .planes = b->planes() }); - index++; - } - - index = 0; - for (auto const &b : data->unicam_[Unicam::Embedded].getBuffers()) { - data->ipaBuffers_.push_back({ .id = RPiIpaMask::EMBEDDED_DATA | index, - .planes = b->planes() }); - index++; + for (auto const &b : buffers) { + ipaBuffers.push_back({ .id = id, .planes = b->planes() }); + data->ipaBufferIds_.push_back(id); + id++; } - 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); - data->ipaBuffers_.clear(); + data->ipa_->unmapBuffers(data->ipaBufferIds_); + data->ipaBufferIds_.clear(); for (auto const stream : data->streams_) stream->releaseBuffers(); diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp index 61226e94..e4158e3a 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp @@ -48,6 +48,11 @@ void RPiStream::setExportedBuffers(std::vector> *bu [](std::unique_ptr &b) { return b.get(); }); } +void RPiStream::setExternalBuffer(FrameBuffer *buffer) +{ + bufferList_.push_back(buffer); +} + const std::vector &RPiStream::getBuffers() const { return bufferList_; diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h index a6fd5c8e..e2534a32 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h @@ -41,6 +41,7 @@ public: void reset(); std::string name() const; void setExportedBuffers(std::vector> *buffers); + void setExternalBuffer(FrameBuffer *buffer); const std::vector &getBuffers() const; void releaseBuffers(); int prepareBuffers(unsigned int count);