From patchwork Sat Feb 29 16:42:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2940 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 6B2F86279C for ; Sat, 29 Feb 2020 17:43:30 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0100EA28; Sat, 29 Feb 2020 17:43:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582994610; bh=zSHTjgu+vDt7JU2m5H9mOXFBD8jOA4e7olWkvvLRQQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PrKDDiOr86GLcgnjl+PD+cSwauwMG0nVNlpkH/UpKeXv1Y6DY4TtO08wCGrGV5knw WWyuTraDOMZhLr5mI2S4jMmh+gz2Uhcz3UEkzqbt9TDDRGFXZS0h3+31zN6/B7qWny jLWpPfXPcqXzYgaKxTAmI8bq86H5EYZjp7lEtc1M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:46 +0200 Message-Id: <20200229164254.23604-24-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> References: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 23/31] libcamera: byte_stream_buffer: Add Span<> support 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: Sat, 29 Feb 2020 16:43:36 -0000 From: Jacopo Mondi Add support to read and write a Span<> from and to 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(+) diff --git a/src/libcamera/byte_stream_buffer.cpp b/src/libcamera/byte_stream_buffer.cpp index cd1d8a36d464..40380bf0434a 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 b5274c62b85e..17cb0146061e 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;