summaryrefslogtreecommitdiff
path: root/src/libcamera/include
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-02-29 01:42:01 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-06 18:10:44 +0200
commit7f2da874cdacf2870c7a55cd1bdf34a01b01787d (patch)
treeee497d48be18cfee4a9cf9d4d9c6d4a8d7cfb67f /src/libcamera/include
parent8a1f0321dc031a34e5fd19bfeefd8e95f9a6b683 (diff)
libcamera: byte_stream_buffer: Add zero-copy read() variant
Add a read() function to ByteStreamBuffer that returns a pointer to the data instead of copying it. Overflow check is still handled by the class, but the caller must check the returned pointer explicitly. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/libcamera/include')
-rw-r--r--src/libcamera/include/byte_stream_buffer.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libcamera/include/byte_stream_buffer.h b/src/libcamera/include/byte_stream_buffer.h
index 17cb0146..b3aaa8b9 100644
--- a/src/libcamera/include/byte_stream_buffer.h
+++ b/src/libcamera/include/byte_stream_buffer.h
@@ -9,6 +9,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <type_traits>
#include <libcamera/span.h>
@@ -44,6 +45,13 @@ public:
}
template<typename T>
+ const std::remove_reference_t<T> *read(size_t count = 1)
+ {
+ using return_type = const std::remove_reference_t<T> *;
+ return reinterpret_cast<return_type>(read(sizeof(T), count));
+ }
+
+ template<typename T>
int write(const T *t)
{
return write(reinterpret_cast<const uint8_t *>(t), sizeof(*t));
@@ -63,6 +71,7 @@ private:
void setOverflow();
int read(uint8_t *data, size_t size);
+ const uint8_t *read(size_t size, size_t count);
int write(const uint8_t *data, size_t size);
ByteStreamBuffer *parent_;