From 8a1f0321dc031a34e5fd19bfeefd8e95f9a6b683 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Mon, 13 Jan 2020 13:40:46 +0100 Subject: libcamera: byte_stream_buffer: Add Span<> support Add support to write and read a Span<> to and from the ByteStreamBuffer class. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/byte_stream_buffer.cpp | 18 ++++++++++++++++++ src/libcamera/include/byte_stream_buffer.h | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'src') diff --git a/src/libcamera/byte_stream_buffer.cpp b/src/libcamera/byte_stream_buffer.cpp index cd1d8a36..17e710c4 100644 --- a/src/libcamera/byte_stream_buffer.cpp +++ b/src/libcamera/byte_stream_buffer.cpp @@ -232,6 +232,15 @@ int ByteStreamBuffer::skip(size_t size) * \retval -ENOSPC no more space is available in the managed memory buffer */ +/** + * \fn template int ByteStreamBuffer::read(const Span &data) + * \brief Read data from the managed memory buffer into Span \a data + * \param[out] data Span representing the destination memory + * \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 t to the managed memory buffer @@ -241,6 +250,15 @@ int ByteStreamBuffer::skip(size_t size) * \retval -ENOSPC no more space is available in the managed memory buffer */ +/** + * \fn template int ByteStreamBuffer::write(const Span &data) + * \brief Write \a data to the managed memory buffer + * \param[in] data 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 + */ + 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 b5274c62..17cb0146 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 @@ -33,12 +35,27 @@ public: { return read(reinterpret_cast(t), sizeof(*t)); } + + template + int read(const Span &data) + { + return read(reinterpret_cast(data.data()), + data.size_bytes()); + } + template int write(const T *t) { return write(reinterpret_cast(t), sizeof(*t)); } + template + int write(const Span &data) + { + return write(reinterpret_cast(data.data()), + data.size_bytes()); + } + private: ByteStreamBuffer(const ByteStreamBuffer &other) = delete; ByteStreamBuffer &operator=(const ByteStreamBuffer &other) = delete; -- cgit v1.2.1