diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-10-16 16:15:48 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-10-16 16:15:48 +1100 |
| commit | bb91724b941e6366711515a544b09385fbb6fc3d (patch) | |
| tree | 3e22163db7fda806ba1903a9a5eaff8987f0b640 /src/audio/audio_decoder.cpp | |
| parent | 7523772886ca37cf05d0ad5b24f6d520e314242e (diff) | |
| download | tangara-fw-bb91724b941e6366711515a544b09385fbb6fc3d.tar.gz | |
Codec memory tweaks
- Ensure mad and ogg structs are allocated internally
- Free old codec before making a new one
Diffstat (limited to 'src/audio/audio_decoder.cpp')
| -rw-r--r-- | src/audio/audio_decoder.cpp | 6 |
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; } |
