From bb91724b941e6366711515a544b09385fbb6fc3d Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 16 Oct 2023 16:15:48 +1100 Subject: Codec memory tweaks - Ensure mad and ogg structs are allocated internally - Free old codec before making a new one --- src/audio/audio_decoder.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/audio/audio_decoder.cpp') 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 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; } -- cgit v1.2.3