From patchwork Thu Jul 4 22:53:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1628 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 11BD76156B for ; Fri, 5 Jul 2019 00:52:32 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 9C95F1C0008; Thu, 4 Jul 2019 22:52:31 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Jul 2019 00:53:32 +0200 Message-Id: <20190704225334.26170-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190704225334.26170-1-jacopo@jmondi.org> References: <20190704225334.26170-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/9] libcamera: request: Support buffer mapping X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jul 2019 22:52:32 -0000 Use the Stream class buffer mapping operation to save the association in the request at Request::findBuffer() time and reverse it with a new operation Request::unmapBuffer() used by the pipeline handler base class at buffer completion time, to return to the applications the Buffer they originally provided with the Request without involving the pipeline handlers in the process. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- include/libcamera/request.h | 4 ++- src/libcamera/pipeline_handler.cpp | 6 ++-- src/libcamera/request.cpp | 45 ++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/include/libcamera/request.h b/include/libcamera/request.h index 70f6d7fa7eeb..3353f037945e 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -36,7 +36,8 @@ public: ControlList &controls() { return controls_; } const std::map &buffers() const { return buffers_; } int setBuffers(const std::map &streamMap); - Buffer *findBuffer(Stream *stream) const; + Buffer *findBuffer(Stream *stream); + Buffer *unmapBuffer(Buffer *streamBuffer); Status status() const { return status_; } @@ -55,6 +56,7 @@ private: ControlList controls_; std::map buffers_; std::unordered_set pending_; + std::map bufferMap_; Status status_; }; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 67b215483847..a47411ecf345 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -402,8 +402,10 @@ int PipelineHandler::queueRequest(Camera *camera, Request *request) bool PipelineHandler::completeBuffer(Camera *camera, Request *request, Buffer *buffer) { - camera->bufferCompleted.emit(request, buffer); - return request->completeBuffer(buffer); + Buffer *requestBuffer = request->unmapBuffer(buffer); + + camera->bufferCompleted.emit(request, requestBuffer); + return request->completeBuffer(requestBuffer); } /** diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 9ff0abbf119c..0e07d39f8941 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -105,17 +105,58 @@ int Request::setBuffers(const std::map &streamMap) */ /** - * \brief Return the buffer associated with a stream + * \brief Retrieve the stream buffer associated with a stream * \param[in] stream The stream the buffer is associated to + * + * Depending on the configured memory type, the buffers originally provided + * by the application might get mapped to streams internal buffers. + * + * \sa Stream::mapBuffer() + * * \return The buffer associated with the stream, or nullptr if the stream is * not part of this request */ -Buffer *Request::findBuffer(Stream *stream) const +Buffer *Request::findBuffer(Stream *stream) { auto it = buffers_.find(stream); if (it == buffers_.end()) return nullptr; + /* + * Streams with internal memory mode do not need to perform any mapping + * between the application provided buffers (part of the request) + * and the one actually used by the Stream. + * + * Streams using externally allocated buffers need to create a mapping + * between the application provided buffers and the one used by pipeline + * handlers. + */ + Buffer *requestBuffer = it->second; + Buffer *mappedBuffer = stream->memoryType() == InternalMemory ? + it->second : stream->mapBuffer(it->second); + bufferMap_[mappedBuffer] = requestBuffer; + + return mappedBuffer; +} + +/** + * \brief Retrieve the application buffer associated with \a streamBuffer + * \param streamBuffer The stream buffer returned from Request::findBuffer() + * + * This operation is used by the PipelineHandler base class to retrieve the + * buffer the application originally associated with the stream in the request. + * Depending on the configured memory type, application provided buffers might + * be mapped to streams internal buffers at Request::findBuffer() time. + * + * \sa Stream::mapBuffer() + * + * \return The application buffer provided to Request::findBuffer() + */ +Buffer *Request::unmapBuffer(Buffer *streamBuffer) +{ + auto it = bufferMap_.find(streamBuffer); + ASSERT(it != bufferMap_.end()); + return it->second; }