diff options
| author | jacqueline <me@jacqueline.id.au> | 2022-12-02 13:39:00 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2022-12-02 13:39:00 +1100 |
| commit | 222c810b07ffc635fc7908d121e97e4d65ccc5c8 (patch) | |
| tree | 91c7b5c72a11770ebf3695bf0c234597b2bc419d /src/audio/include | |
| parent | 71a4f5166f5491dc0982a18d62c63e28b3a52faa (diff) | |
| download | tangara-fw-222c810b07ffc635fc7908d121e97e4d65ccc5c8.tar.gz | |
fix build errors
Diffstat (limited to 'src/audio/include')
| -rw-r--r-- | src/audio/include/audio_decoder.hpp | 9 | ||||
| -rw-r--r-- | src/audio/include/audio_element.hpp | 27 | ||||
| -rw-r--r-- | src/audio/include/chunk.hpp | 37 | ||||
| -rw-r--r-- | src/audio/include/fatfs_audio_input.hpp | 11 | ||||
| -rw-r--r-- | src/audio/include/stream_info.hpp | 14 |
5 files changed, 62 insertions, 36 deletions
diff --git a/src/audio/include/audio_decoder.hpp b/src/audio/include/audio_decoder.hpp index 98ebdc71..a4508c3e 100644 --- a/src/audio/include/audio_decoder.hpp +++ b/src/audio/include/audio_decoder.hpp @@ -18,8 +18,13 @@ class AudioDecoder : public IAudioElement { AudioDecoder(); ~AudioDecoder(); - auto SetInputBuffer(StreamBufferHandle_t*) -> void; - auto SetOutputBuffer(StreamBufferHandle_t*) -> void; + auto SetInputBuffer(MessageBufferHandle_t*) -> void; + auto SetOutputBuffer(MessageBufferHandle_t*) -> void; + + auto ProcessStreamInfo(StreamInfo&& info) -> cpp::result<void, StreamError>; + auto ProcessChunk(uint8_t* data, std::size_t length) + -> cpp::result<size_t, StreamError>; + auto ProcessIdle() -> cpp::result<void, StreamError>; AudioDecoder(const AudioDecoder&) = delete; AudioDecoder& operator=(const AudioDecoder&) = delete; diff --git a/src/audio/include/audio_element.hpp b/src/audio/include/audio_element.hpp index 2a2f0727..13a48590 100644 --- a/src/audio/include/audio_element.hpp +++ b/src/audio/include/audio_element.hpp @@ -1,13 +1,28 @@ #pragma once #include <stdint.h> + #include <cstdint> + +#include "freertos/FreeRTOS.h" + +#include "freertos/message_buffer.h" #include "freertos/portmacro.h" #include "result.hpp" + +#include "stream_info.hpp" #include "types.hpp" namespace audio { +/* Errors that may be returned by any of the Process* methods. */ +enum StreamError { + // Indicates that this element is unable to handle the upcoming chunks. + UNSUPPORTED_STREAM, + // Indicates an error with reading or writing stream data. + IO_ERROR, +}; + /* * One indepedentent part of an audio pipeline. Each element has an input and * output message stream, and is responsible for taking data from the input @@ -46,14 +61,6 @@ class IAudioElement { /* Returns this element's output buffer. */ auto OutputBuffer() -> MessageBufferHandle_t* { return output_buffer_; } - /* Errors that may be returned by any of the Process* methods. */ - enum StreamError { - // Indicates that this element is unable to handle the upcoming chunks. - UNSUPPORTED_STREAM, - // Indicates an error with reading or writing stream data. - IO_ERROR, - }; - /* * Called when a StreamInfo message is received. Used to configure this * element in preperation for incoming chunks. @@ -78,8 +85,8 @@ class IAudioElement { virtual auto ProcessIdle() -> cpp::result<void, StreamError> = 0; protected: - StreamBufferHandle_t* input_buffer_; - StreamBufferHandle_t* output_buffer_; + MessageBufferHandle_t* input_buffer_; + MessageBufferHandle_t* output_buffer_; }; } // namespace audio diff --git a/src/audio/include/chunk.hpp b/src/audio/include/chunk.hpp index a3f943ea..365c83d0 100644 --- a/src/audio/include/chunk.hpp +++ b/src/audio/include/chunk.hpp @@ -4,8 +4,13 @@ #include <cstdint> #include <optional> #include <string> -#include "esp-idf/components/cbor/tinycbor/src/cbor.h" + +#include "freertos/FreeRTOS.h" + +#include "cbor.h" +#include "freertos/message_buffer.h" #include "freertos/portmacro.h" +#include "freertos/queue.h" #include "result.hpp" namespace audio { @@ -35,7 +40,22 @@ auto WriteChunksToStream(MessageBufferHandle_t* stream, uint8_t* working_buffer, size_t working_buffer_length, std::function<size_t(uint8_t*, size_t)> callback, - TickType_t max_wait) -> EncodeWriteResult; + TickType_t max_wait) -> ChunkWriteResult; + +enum ChunkReadResult { + CHUNK_READ_OKAY, + // Returned when the chunk was read successfully, but the consumer did not + // use all of the data. + CHUNK_LEFTOVER_DATA, + // Returned an error in parsing the cbor-encoded header. + CHUNK_DECODING_ERROR, + // Returned when max_wait expired before any data was read. + CHUNK_READ_TIMEOUT, + // Returned when a non-chunk message is received. + CHUNK_STREAM_ENDED, + // Returned when the processing callback does not return a value. + CHUNK_PROCESSING_ERROR, +}; class ChunkReader { public: @@ -46,17 +66,6 @@ class ChunkReader { auto GetLastMessage() -> std::pair<uint8_t*, size_t>; - enum ChunkReadResult { - // Returned an error in parsing the cbor-encoded header. - CHUNK_DECODING_ERROR, - // Returned when max_wait expired before any data was read. - CHUNK_READ_TIMEOUT, - // Returned when a non-chunk message is received. - CHUNK_STREAM_ENDED, - // Returned when the processing callback does not return a value. - CHUNK_PROCESSING_ERROR, - }; - /* * Reads chunks of data from the given input stream, and invokes the given * callback to process each of them in turn. @@ -71,7 +80,7 @@ class ChunkReader { */ auto ReadChunkFromStream( std::function<std::optional<size_t>(uint8_t*, size_t)> callback, - TickType_t max_wait) -> EncodeReadResult; + TickType_t max_wait) -> ChunkReadResult; private: MessageBufferHandle_t* stream_; diff --git a/src/audio/include/fatfs_audio_input.hpp b/src/audio/include/fatfs_audio_input.hpp index 0fc2729f..6fe178ab 100644 --- a/src/audio/include/fatfs_audio_input.hpp +++ b/src/audio/include/fatfs_audio_input.hpp @@ -5,8 +5,9 @@ #include <string> #include "freertos/FreeRTOS.h" + +#include "freertos/message_buffer.h" #include "freertos/queue.h" -#include "freertos/stream_buffer.h" #include "audio_element.hpp" #include "storage.hpp" @@ -18,11 +19,16 @@ class FatfsAudioInput : public IAudioElement { FatfsAudioInput(std::shared_ptr<drivers::SdStorage> storage); ~FatfsAudioInput(); - auto OutputBuffer() -> MessageBufferHandle_t; + auto ProcessStreamInfo(StreamInfo&& info) -> cpp::result<void, StreamError>; + auto ProcessChunk(uint8_t* data, std::size_t length) + -> cpp::result<size_t, StreamError>; + auto ProcessIdle() -> cpp::result<void, StreamError>; auto SendChunk(uint8_t* buffer, size_t size) -> size_t; private: + auto GetRingBufferDistance() -> size_t; + std::shared_ptr<drivers::SdStorage> storage_; uint8_t* file_buffer_; @@ -39,7 +45,6 @@ class FatfsAudioInput : public IAudioElement { uint8_t* output_buffer_memory_; StaticMessageBuffer_t output_buffer_metadata_; - MessageBufferHandle_t output_buffer_; }; } // namespace audio diff --git a/src/audio/include/stream_info.hpp b/src/audio/include/stream_info.hpp index bf5d4c60..ca28dd4e 100644 --- a/src/audio/include/stream_info.hpp +++ b/src/audio/include/stream_info.hpp @@ -3,9 +3,13 @@ #include <cstdint> #include <optional> #include <string> -#include "esp-idf/components/cbor/tinycbor/src/cbor.h" + +#include "cbor.h" #include "result.hpp" +#include "cbor_decoder.hpp" +#include "cbor_encoder.hpp" + namespace audio { class StreamInfo { @@ -18,7 +22,7 @@ class StreamInfo { static auto Create(const uint8_t* buffer, size_t length) -> cpp::result<StreamInfo, ParseError>; - StreamInfo(CborValue& map); + StreamInfo(cbor::MapDecoder*); StreamInfo() = default; StreamInfo(const StreamInfo&) = default; @@ -34,11 +38,7 @@ class StreamInfo { return sample_rate_; } - enum EncodeError { - OUT_OF_MEMORY, - }; - - auto WriteToMap(CborEncoder encoder) -> cpp::result<size_t, EncodeError>; + auto WriteToMap(cbor::Encoder& encoder) -> cpp::result<size_t, CborError>; private: std::optional<std::string> path_; |
