diff options
| author | jacqueline <me@jacqueline.id.au> | 2022-12-02 17:25:53 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2022-12-02 17:25:53 +1100 |
| commit | c36208016eefcdfdeff045f675f74fdb69dddb52 (patch) | |
| tree | 817bd458ca14a6dd0d200390a0b11cb2120aa33f /src/audio/fatfs_audio_input.cpp | |
| parent | 222c810b07ffc635fc7908d121e97e4d65ccc5c8 (diff) | |
| download | tangara-fw-c36208016eefcdfdeff045f675f74fdb69dddb52.tar.gz | |
better cbor handling
Diffstat (limited to 'src/audio/fatfs_audio_input.cpp')
| -rw-r--r-- | src/audio/fatfs_audio_input.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp index dee090d0..d4cbf6db 100644 --- a/src/audio/fatfs_audio_input.cpp +++ b/src/audio/fatfs_audio_input.cpp @@ -10,6 +10,9 @@ #include "audio_element.hpp" #include "chunk.hpp" +#include "stream_message.hpp" + +static const char* kTag = "SRC"; namespace audio { @@ -43,14 +46,17 @@ FatfsAudioInput::~FatfsAudioInput() { free(output_buffer_); } -auto FatfsAudioInput::ProcessStreamInfo(StreamInfo&& info) - -> cpp::result<void, StreamError> { +auto FatfsAudioInput::ProcessStreamInfo(StreamInfo& info) + -> cpp::result<void, AudioProcessingError> { if (is_file_open_) { f_close(¤t_file_); is_file_open_ = false; } - std::string path = info.Path().value_or(""); + if (!info.Path()) { + return cpp::fail(UNSUPPORTED_STREAM); + } + std::string path = info.Path().value(); FRESULT res = f_open(¤t_file_, path.c_str(), FA_READ); if (res != FR_OK) { return cpp::fail(IO_ERROR); @@ -58,15 +64,24 @@ auto FatfsAudioInput::ProcessStreamInfo(StreamInfo&& info) is_file_open_ = true; - // TODO: pass on stream info. + auto write_res = + WriteMessage(TYPE_STREAM_INFO, + std::bind(&StreamInfo::Encode, info, std::placeholders::_1), + chunk_buffer_, kMaxChunkSize); + + if (write_res.has_error()) { + return cpp::fail(IO_ERROR); + } else { + xMessageBufferSend(output_buffer_, chunk_buffer_, write_res.value(), + portMAX_DELAY); + } return {}; } auto FatfsAudioInput::ProcessChunk(uint8_t* data, std::size_t length) - -> cpp::result<size_t, StreamError> { - // TODO. - return 0; + -> cpp::result<size_t, AudioProcessingError> { + return cpp::fail(UNSUPPORTED_STREAM); } auto FatfsAudioInput::GetRingBufferDistance() -> size_t { @@ -83,7 +98,7 @@ auto FatfsAudioInput::GetRingBufferDistance() -> size_t { + (file_buffer_write_pos_ - file_buffer_); } -auto FatfsAudioInput::ProcessIdle() -> cpp::result<void, StreamError> { +auto FatfsAudioInput::ProcessIdle() -> cpp::result<void, AudioProcessingError> { // First, see if we're able to fill up the input buffer with any more of the // file's contents. if (is_file_open_) { @@ -102,7 +117,8 @@ auto FatfsAudioInput::ProcessIdle() -> cpp::result<void, StreamError> { FRESULT result = f_read(¤t_file_, file_buffer_write_pos_, read_size, &bytes_read); if (result != FR_OK) { - return cpp::fail(IO_ERROR); // TODO; + ESP_LOGE(kTag, "file I/O error %d", result); + return cpp::fail(IO_ERROR); } if (f_eof(¤t_file_)) { @@ -128,9 +144,11 @@ auto FatfsAudioInput::ProcessIdle() -> cpp::result<void, StreamError> { switch (result) { case CHUNK_WRITE_TIMEOUT: case CHUNK_OUT_OF_DATA: - return {}; // TODO. + // Both of these are fine; SendChunk keeps track of where it's up to + // internally, so we will pick back up where we left off. + return {}; default: - return {}; // TODO. + return cpp::fail(IO_ERROR); } } |
