From f16cd2b2694251252327969830de2d94b9065823 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sat, 20 Jan 2018 18:32:21 -0800 Subject: [PATCH] Only mad_*_finish after a successful mad_*_start When the input file(stream) doesn't open, you could end up calling mp3::stop() which would try and mad_finish structures that were not yet initialized. Now carry a flag when these are set, and only _finish when it's set. --- src/AudioGeneratorMP3.cpp | 16 ++++++++++------ src/AudioGeneratorMP3.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/AudioGeneratorMP3.cpp b/src/AudioGeneratorMP3.cpp index 296b582..66484d6 100644 --- a/src/AudioGeneratorMP3.cpp +++ b/src/AudioGeneratorMP3.cpp @@ -29,6 +29,7 @@ AudioGeneratorMP3::AudioGeneratorMP3() buffLen = 1500; // Max theoretical frame of 1441 + 8 guard bytes, with some fluff buff = NULL; nsCountMax = 1152/32; + madInitted = false; } AudioGeneratorMP3::~AudioGeneratorMP3() @@ -49,10 +50,13 @@ bool AudioGeneratorMP3::stop() { free(buff); buff = NULL; - - mad_synth_finish(&synth); - mad_frame_finish(&frame); - mad_stream_finish(&stream); + + if (madInitted) { + mad_synth_finish(&synth); + mad_frame_finish(&frame); + mad_stream_finish(&stream); + madInitted = false; + } running = false; output->stop(); @@ -222,8 +226,8 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output) mad_stream_init(&stream); mad_frame_init(&frame); mad_synth_init(&synth); - - mad_stream_options(&stream, 0); // TODO - add options suppoirt + mad_stream_options(&stream, 0); // TODO - add options support + madInitted = true; running = true; return true; diff --git a/src/AudioGeneratorMP3.h b/src/AudioGeneratorMP3.h index a4b2cc9..3858050 100644 --- a/src/AudioGeneratorMP3.h +++ b/src/AudioGeneratorMP3.h @@ -44,6 +44,7 @@ class AudioGeneratorMP3 : public AudioGenerator int lastChannels; // Decoding bits + bool madInitted; struct mad_stream stream; struct mad_frame frame; struct mad_synth synth;