From 16d5d29049c08e21f57f7928ceedf40586a2d294 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Sat, 3 Dec 2022 11:10:06 +1100 Subject: Use std::span (backported) and std::byte to make our buffers safer --- src/audio/include/fatfs_audio_input.hpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/audio/include/fatfs_audio_input.hpp') diff --git a/src/audio/include/fatfs_audio_input.hpp b/src/audio/include/fatfs_audio_input.hpp index c54b32bd..3ca79457 100644 --- a/src/audio/include/fatfs_audio_input.hpp +++ b/src/audio/include/fatfs_audio_input.hpp @@ -8,6 +8,7 @@ #include "freertos/message_buffer.h" #include "freertos/queue.h" +#include "span.hpp" #include "audio_element.hpp" #include "storage.hpp" @@ -21,28 +22,28 @@ class FatfsAudioInput : public IAudioElement { auto ProcessStreamInfo(StreamInfo& info) -> cpp::result; - auto ProcessChunk(uint8_t* data, std::size_t length) - -> cpp::result; + auto ProcessChunk(cpp::span& chunk) + -> cpp::result = 0; auto ProcessIdle() -> cpp::result; - auto SendChunk(uint8_t* buffer, size_t size) -> size_t; + auto SendChunk(cpp::span dest) -> size_t; private: auto GetRingBufferDistance() -> size_t; std::shared_ptr storage_; - uint8_t* file_buffer_; - uint8_t* file_buffer_read_pos_; - uint8_t* pending_read_pos_; - uint8_t* file_buffer_write_pos_; + std::byte* raw_file_buffer_; + cpp::span file_buffer_; + cpp::span::iterator file_buffer_read_pos_; + cpp::span::iterator pending_read_pos_; + cpp::span::iterator file_buffer_write_pos_; - uint8_t* chunk_buffer_; + std::byte* raw_chunk_buffer_; + cpp::span chunk_buffer_; FIL current_file_; - bool is_file_open_ = false; - - MessageBufferHandle_t input_buffer_; + bool is_file_open_; uint8_t* output_buffer_memory_; StaticMessageBuffer_t output_buffer_metadata_; -- cgit v1.2.3