From patchwork Thu Jul 4 22:53:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1623 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 10ECA60C2C for ; Fri, 5 Jul 2019 00:52:28 +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 9ED701C0002; Thu, 4 Jul 2019 22:52:27 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Jul 2019 00:53:27 +0200 Message-Id: <20190704225334.26170-3-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 2/9] 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: Thu, 04 Jul 2019 22:52:28 -0000 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 --- include/libcamera/stream.h | 8 ++++++++ src/libcamera/camera.cpp | 1 + src/libcamera/stream.cpp | 30 ++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h index fa7d6ba4987c..796f1aff2602 100644 --- a/include/libcamera/stream.h +++ b/include/libcamera/stream.h @@ -34,6 +34,11 @@ private: std::map> formats_; }; +enum MemoryType { + InternalMemory, + ExternalMemory, +}; + struct StreamConfiguration { StreamConfiguration(); StreamConfiguration(const StreamFormats &formats); @@ -41,6 +46,7 @@ struct StreamConfiguration { unsigned int pixelFormat; Size size; + MemoryType memoryType; unsigned int bufferCount; Stream *stream() const { return stream_; } @@ -77,6 +83,7 @@ public: std::vector &buffers() { return bufferPool_.buffers(); } unsigned int bufferCount() const { return bufferPool_.count(); } const StreamConfiguration &configuration() const { return configuration_; } + MemoryType memoryType() const { return memoryType_; } protected: friend class Camera; @@ -86,6 +93,7 @@ protected: BufferPool bufferPool_; StreamConfiguration configuration_; + MemoryType memoryType_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 088a39623e36..5f756d41744a 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -683,6 +683,7 @@ int Camera::configure(CameraConfiguration *config) * Allocate buffer objects in the pool. * Memory will be allocated and assigned later. */ + stream->memoryType_ = cfg.memoryType; stream->createBuffers(cfg.bufferCount); } diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index 35197be09c26..97e0f429c9fb 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -263,6 +263,16 @@ 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 to the library and export that + * to applications. + * \var MemoryType::ExternalMemory + * The Stream uses buffers whose memory is allocated outside from the library. + */ + /** * \struct StreamConfiguration * \brief Configuration parameters for a stream @@ -276,7 +286,7 @@ SizeRange StreamFormats::range(unsigned int pixelformat) const * handlers provied StreamFormats. */ StreamConfiguration::StreamConfiguration() - : stream_(nullptr) + : memoryType(InternalMemory), stream_(nullptr) { } @@ -284,7 +294,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 +311,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 @@ -436,6 +451,12 @@ Stream::Stream() * \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 @@ -476,4 +497,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 */