summaryrefslogtreecommitdiff
path: root/src/audio/include/audio_element.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-22 17:05:02 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-22 17:05:02 +1100
commit9176ef187227ffb56c249c5f321cd1bf50d4cfcc (patch)
treea846c8fc4e5788e97d6fca43c2807c4bf0ae0214 /src/audio/include/audio_element.hpp
parent9f8cfaa7a8abd885785830e03d7c417e856b8a22 (diff)
downloadtangara-fw-9176ef187227ffb56c249c5f321cd1bf50d4cfcc.tar.gz
Add cbor wrapper, and chunk streaming util
Diffstat (limited to 'src/audio/include/audio_element.hpp')
-rw-r--r--src/audio/include/audio_element.hpp72
1 files changed, 12 insertions, 60 deletions
diff --git a/src/audio/include/audio_element.hpp b/src/audio/include/audio_element.hpp
index 03fefd70..0be58f48 100644
--- a/src/audio/include/audio_element.hpp
+++ b/src/audio/include/audio_element.hpp
@@ -1,6 +1,10 @@
#pragma once
+#include <stdint.h>
#include <cstdint>
+#include "freertos/portmacro.h"
+#include "types.hpp"
+#include "result.hpp"
namespace audio {
@@ -10,71 +14,19 @@ class IAudioElement {
public:
virtual ~IAudioElement();
- enum CommandType {
- /*
- * Sets the sequence number of the most recent byte stream. Any commands
- * received that have a lower sequence number than this will be discarded.
- */
- SEQUENCE_NUMBER,
- /*
- * Instructs this element to read a specific number of bytes from its
- * input buffer.
- */
- READ_FRAME,
- /*
- * Represents an element-specific command. This handling of this is
- * delegated to element implementations.
- */
- ELEMENT,
- /* Instructs this element to shut down. */
- QUIT,
- };
-
- struct Command {
- CommandType type;
- uint8_t sequence_number;
- // TODO: tag data's type
- union {
- void* data;
- std::size_t frame_size;
- };
- };
+ virtual auto IdleTimeout() -> TickType_t { return portMAX_DELAY; }
- /*
- * Returns a queue that should be used for all communication with this
- * element.
- */
- virtual auto InputCommandQueue() -> QueueHandle_t = 0;
+ virtual auto InputBuffer() -> MessageBufferHandle_t* = 0;
- /*
- * Returns a buffer that will be used to stream input bytes to this element.
- * This may be NULL, if this element represents a source, e.g. a FATFS
- * reader.
- */
- virtual auto InputBuffer() -> StreamBufferHandle_t = 0;
+ virtual auto OutputBuffer() -> MessageBufferHandle_t* = 0;
- enum ProcessResult {
- OK,
- OUTPUT_FULL,
- ERROR,
+ enum StreamError {
+ BAD_FORMAT
};
- /*
- * Called when an element-specific command has been received.
- */
- virtual auto ProcessElementCommand(void* command) -> ProcessResult = 0;
-
- virtual auto SkipElementCommand(void* command) -> void = 0;
-
- /*
- * Called with the result of a read bytes command.
- */
- virtual auto ProcessData(uint8_t* data, uint16_t length) -> ProcessResult = 0;
-
- /*
- * Called periodically when there are no pending commands.
- */
- virtual auto ProcessIdle() -> ProcessResult = 0;
+ virtual auto ProcessStreamInfo(StreamInfo &info) -> cpp::result<void, StreamError> = 0;
+ virtual auto ProcessChunk(uint8_t* data, std::size_t length) -> cpp::result<void, StreamError> = 0;
+ virtual auto ProcessIdle() -> cpp::result<void, StreamError> = 0;
};
} // namespace audio