From 01be69eca1fa89c047fc29f5cb0ea8ba0898dad1 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 7 Dec 2022 15:36:47 +1100 Subject: better handling of chunk buffer --- src/audio/audio_task.cpp | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'src/audio/audio_task.cpp') diff --git a/src/audio/audio_task.cpp b/src/audio/audio_task.cpp index 112f8f34..3512c96f 100644 --- a/src/audio/audio_task.cpp +++ b/src/audio/audio_task.cpp @@ -19,12 +19,8 @@ namespace audio { -static const TickType_t kCommandWaitTicks = 1; -static const TickType_t kIdleTaskDelay = 1; -static const size_t kChunkBufferSize = kMaxChunkSize * 1.5; - auto StartAudioTask(const std::string& name, - std::shared_ptr& element) -> void { + std::shared_ptr element) -> void { AudioTaskArgs* args = new AudioTaskArgs{.element = element}; xTaskCreate(&AudioTaskMain, name.c_str(), element->StackSizeBytes(), args, kTaskPriorityAudio, NULL); @@ -45,24 +41,22 @@ void AudioTaskMain(void* args) { // processing any chunks from it. Try doing this first, then fall back to // the other cases. bool has_received_message = false; - if (element->InputBuffer() != nullptr) { - ChunkReadResult chunk_res = chunk_reader.ReadChunkFromStream( - [&](cpp::span data) -> std::optional { - process_res = element->ProcessChunk(data); - if (process_res.has_value()) { - return process_res.value(); - } else { - return {}; - } - }, - element->IdleTimeout()); - - if (chunk_res == CHUNK_PROCESSING_ERROR || - chunk_res == CHUNK_DECODING_ERROR) { - break; // TODO. - } else if (chunk_res == CHUNK_STREAM_ENDED) { - has_received_message = true; - } + ChunkReadResult chunk_res = chunk_reader.ReadChunkFromStream( + [&](cpp::span data) -> std::optional { + process_res = element->ProcessChunk(data); + if (process_res.has_value()) { + return process_res.value(); + } else { + return {}; + } + }, + element->IdleTimeout()); + + if (chunk_res == CHUNK_PROCESSING_ERROR || + chunk_res == CHUNK_DECODING_ERROR) { + break; // TODO. + } else if (chunk_res == CHUNK_STREAM_ENDED) { + has_received_message = true; } if (has_received_message) { -- cgit v1.2.3