summaryrefslogtreecommitdiff
path: root/src/audio/audio_decoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/audio_decoder.cpp')
-rw-r--r--src/audio/audio_decoder.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp
index 86394a37..78b0d3f5 100644
--- a/src/audio/audio_decoder.cpp
+++ b/src/audio/audio_decoder.cpp
@@ -119,6 +119,8 @@ void Decoder::Main() {
}
auto Decoder::BeginDecoding(std::shared_ptr<codecs::IStream> stream) -> bool {
+ // Ensure any previous codec is freed before creating a new one.
+ codec_.reset();
codec_.reset(codecs::CreateCodecForType(stream->type()).value_or(nullptr));
if (!codec_) {
ESP_LOGE(kTag, "no codec found");
@@ -164,6 +166,10 @@ auto Decoder::ContinueDecoding() -> bool {
timer_->AddSamples(res->samples_written);
}
+ if (res->is_stream_finished) {
+ codec_.reset();
+ }
+
return res->is_stream_finished;
}