diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-01-26 15:02:57 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-01-26 15:02:57 +1100 |
| commit | f6dcd845fc80da4e3043146e4362258dd8e0c0a1 (patch) | |
| tree | 91410899a83fcc2dfb1eb3ab4837a11e401366fc /src/audio/include/stream_event.hpp | |
| parent | e7f926e2c376ccd4f4a4d6f4b104f3c23b0059dc (diff) | |
| download | tangara-fw-f6dcd845fc80da4e3043146e4362258dd8e0c0a1.tar.gz | |
Switch from MessageBuffer to Queue for pipeline comms
Diffstat (limited to 'src/audio/include/stream_event.hpp')
| -rw-r--r-- | src/audio/include/stream_event.hpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/audio/include/stream_event.hpp b/src/audio/include/stream_event.hpp new file mode 100644 index 00000000..4dfdab41 --- /dev/null +++ b/src/audio/include/stream_event.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include <memory> + +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" + +#include "span.hpp" +#include "stream_info.hpp" + +namespace audio { + +struct StreamEvent { + static auto CreateStreamInfo(QueueHandle_t source, + std::unique_ptr<StreamInfo> payload) + -> std::unique_ptr<StreamEvent>; + static auto CreateChunkData(QueueHandle_t source, std::size_t chunk_size) + -> std::unique_ptr<StreamEvent>; + static auto CreateChunkNotification(QueueHandle_t source) + -> std::unique_ptr<StreamEvent>; + + StreamEvent(); + ~StreamEvent(); + StreamEvent(StreamEvent&&); + + QueueHandle_t source; + + enum { + UNINITIALISED, + STREAM_INFO, + CHUNK_DATA, + CHUNK_NOTIFICATION, + } tag; + + union { + std::unique_ptr<StreamInfo> stream_info; + + // Scott Meyers says: + // `About the only situation I can conceive of when a std::unique_ptr<T[]> + // would make sense would be when you’re using a C-like API that returns a + // raw pointer to a heap array that you assume ownership of.` + // :-) + + struct { + std::unique_ptr<std::byte*> raw_bytes; + cpp::span<std::byte> bytes; + } chunk_data; + + // FIXME: It would be nice to also support a pointer to himem data here, to + // save a little ordinary heap space. + }; + + StreamEvent(const StreamEvent&) = delete; + StreamEvent& operator=(const StreamEvent&) = delete; +}; + +} // namespace audio |
