From patchwork Mon Jan 13 16:42:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2637 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C0F36074A for ; Mon, 13 Jan 2020 17:40:40 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 92526100005; Mon, 13 Jan 2020 16:40:39 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jan 2020 17:42:43 +0100 Message-Id: <20200113164245.52535-22-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200113164245.52535-1-jacopo@jmondi.org> References: <20200113164245.52535-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 21/23] libcamera: byte_stream_buffer: Support span<> 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: , X-List-Received-Date: Mon, 13 Jan 2020 16:40:42 -0000 Add support to write and read span<> of data to the ByteStreamBuffer class. Signed-off-by: Jacopo Mondi --- src/libcamera/byte_stream_buffer.cpp | 31 ++++++++++++++++++++-- src/libcamera/include/byte_stream_buffer.h | 14 ++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/libcamera/byte_stream_buffer.cpp b/src/libcamera/byte_stream_buffer.cpp index 23d624dd0a06..9fb14508722f 100644 --- a/src/libcamera/byte_stream_buffer.cpp +++ b/src/libcamera/byte_stream_buffer.cpp @@ -225,22 +225,49 @@ int ByteStreamBuffer::skip(size_t size) /** * \fn template int ByteStreamBuffer::read(T *t) - * \brief Read \a size \a data from the managed memory buffer + * \brief Read data from the managed memory buffer into \a t * \param[out] t Pointer to the memory containing the read data * \return 0 on success, a negative error code otherwise * \retval -EACCES attempting to read from a write buffer * \retval -ENOSPC no more space is available in the managed memory buffer */ +/** + * \fn template int ByteStreamBuffer::read(Span *t) + * \brief Read a sequence of data from the managed memory buffer into span \a t + * \param[out] t Pointer to an intialized span where to read data + * + * This function reads data from managed memory and writes it to an initialized + * memory location represented by the span \a t. + * + * The provided span \a t should be initialized with a memory area large + * enough to contain the read data. This function does not perform any + * memory allocation or initialization in the span \a t. It is responsibility of + * the caller to do so. + * + * \return 0 on success, a negative error code otherwise + * \retval -EACCES attempting to read from a write buffer + * \retval -ENOSPC no more space is available in the managed memory buffer + */ + /** * \fn template int ByteStreamBuffer::write(const T *t) - * \brief Write \a data of \a size to the managed memory buffer + * \brief Write \a t to the managed memory buffer * \param[in] t The data to write to memory * \return 0 on success, a negative error code otherwise * \retval -EACCES attempting to write to a read buffer * \retval -ENOSPC no more space is available in the managed memory buffer */ +/** + * \fn template int ByteStreamBuffer::write(const Span &t) + * \brief Write a span of data \a t to the managed memory buffer + * \param[in] t The span of data to write to memory + * \return 0 on success, a negative error code otherwise + * \retval -EACCES attempting to write to a read buffer + * \retval -ENOSPC no more space is available in the managed memory buffer + */ + int ByteStreamBuffer::read(uint8_t *data, size_t size) { if (!read_) diff --git a/src/libcamera/include/byte_stream_buffer.h b/src/libcamera/include/byte_stream_buffer.h index b5274c62b85e..2d5267ac06c0 100644 --- a/src/libcamera/include/byte_stream_buffer.h +++ b/src/libcamera/include/byte_stream_buffer.h @@ -10,6 +10,8 @@ #include #include +#include + namespace libcamera { class ByteStreamBuffer @@ -34,10 +36,22 @@ public: return read(reinterpret_cast(t), sizeof(*t)); } template + int read(Span *t) + { + return read(reinterpret_cast(t->data()), + sizeof(t->data()[0]) * t->size()); + } + template int write(const T *t) { return write(reinterpret_cast(t), sizeof(*t)); } + template + int write(const Span &t) + { + return write(reinterpret_cast(t.data()), + sizeof(t.data()[0]) * t.size()); + } private: ByteStreamBuffer(const ByteStreamBuffer &other) = delete;