From patchwork Sat Jul 13 17:23:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1692 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B3A436175B for ; Sat, 13 Jul 2019 19:24:43 +0200 (CEST) Received: from pendragon.ideasonboard.com (softbank126209254147.bbtec.net [126.209.254.147]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6FA482B2 for ; Sat, 13 Jul 2019 19:24:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1563038683; bh=5VAj2gisFfQhEnJnqo7buZXlLkxoi+kGfK+QtD0il9k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZZfbRSfwgs0+RCbPFi7efdaaHbZFpkNoynOna5rStK/F0YrOzv8fB1WBZtKnn8UzC bRUhaCL7XWUrpazwN3wlq78ie48kHimOGR5inu7OVEw0Im1AhQYs7GdXffojV/qO+b S7p/MCts38u/fFp1siGriCRMYtVxnLdFlUpdZe9g= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 13 Jul 2019 20:23:46 +0300 Message-Id: <20190713172351.25452-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190713172351.25452-1-laurent.pinchart@ideasonboard.com> References: <20190713172351.25452-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 11/16] libcamera: stream: Add Stream memory type 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: Sat, 13 Jul 2019 17:24:44 -0000 From: Jacopo Mondi Define the memory type a Stream uses and allow application to set it through the associated StreamConfiguration. A Stream can use either internal or external memory allocation methods, depending on where the data produced by the stream is actually saved. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Signed-off-by: Laurent Pinchart --- include/libcamera/stream.h | 10 +++++++++- src/libcamera/camera.cpp | 2 +- src/libcamera/stream.cpp | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h index bc14fb60480e..08eb8cc7d5c7 100644 --- a/include/libcamera/stream.h +++ b/include/libcamera/stream.h @@ -35,6 +35,11 @@ private: std::map> formats_; }; +enum MemoryType { + InternalMemory, + ExternalMemory, +}; + struct StreamConfiguration { StreamConfiguration(); StreamConfiguration(const StreamFormats &formats); @@ -42,6 +47,7 @@ struct StreamConfiguration { unsigned int pixelFormat; Size size; + MemoryType memoryType; unsigned int bufferCount; Stream *stream() const { return stream_; } @@ -73,15 +79,17 @@ public: BufferPool &bufferPool() { return bufferPool_; } std::vector &buffers() { return bufferPool_.buffers(); } const StreamConfiguration &configuration() const { return configuration_; } + MemoryType memoryType() const { return memoryType_; } protected: friend class Camera; - void createBuffers(unsigned int count); + void createBuffers(MemoryType memory, unsigned int count); void destroyBuffers(); BufferPool bufferPool_; StreamConfiguration configuration_; + MemoryType memoryType_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 61d3e821f48f..af69607b19e6 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -683,7 +683,7 @@ int Camera::configure(CameraConfiguration *config) * Allocate buffer objects in the pool. * Memory will be allocated and assigned later. */ - stream->createBuffers(cfg.bufferCount); + stream->createBuffers(cfg.memoryType, cfg.bufferCount); } state_ = CameraConfigured; diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index 884fbfebd52c..94aa4810f6b9 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -263,6 +263,17 @@ SizeRange StreamFormats::range(unsigned int pixelformat) const return range; } +/** + * \enum MemoryType + * \brief Define the memory type used by a Stream + * \var MemoryType::InternalMemory + * The Stream uses memory allocated internally by the library and exported to + * applications. + * \var MemoryType::ExternalMemory + * The Stream uses memory allocated externally by application and imported in + * the library. + */ + /** * \struct StreamConfiguration * \brief Configuration parameters for a stream @@ -276,7 +287,7 @@ SizeRange StreamFormats::range(unsigned int pixelformat) const * handlers provied StreamFormats. */ StreamConfiguration::StreamConfiguration() - : stream_(nullptr) + : memoryType(InternalMemory), stream_(nullptr) { } @@ -284,7 +295,7 @@ StreamConfiguration::StreamConfiguration() * \brief Construct a configuration with stream formats */ StreamConfiguration::StreamConfiguration(const StreamFormats &formats) - : stream_(nullptr), formats_(formats) + : memoryType(InternalMemory), stream_(nullptr), formats_(formats) { } @@ -301,6 +312,11 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats) * format described in V4L2 using the V4L2_PIX_FMT_* definitions. */ +/** + * \var StreamConfiguration::memoryType + * \brief The memory type the stream shall use + */ + /** * \var StreamConfiguration::bufferCount * \brief Requested number of buffers to allocate for the stream @@ -454,18 +470,26 @@ std::unique_ptr Stream::createBuffer(unsigned int index) * \return The active configuration of the stream */ +/** + * \fn Stream::memoryType() + * \brief Retrieve the stream memory type + * \return The memory type used by the stream + */ + /** * \brief Create buffers for the stream * \param count The number of buffers to create + * \param memory The stream memory type * * Create \a count empty buffers in the Stream's buffer pool. */ -void Stream::createBuffers(unsigned int count) +void Stream::createBuffers(MemoryType memory, unsigned int count) { destroyBuffers(); if (count == 0) return; + memoryType_ = memory; bufferPool_.createBuffers(count); } @@ -497,4 +521,9 @@ void Stream::destroyBuffers() * next call to Camera::configure() regardless of if it includes the stream. */ +/** + * \var Stream::memoryType_ + * \brief The stream memory type + */ + } /* namespace libcamera */