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.
This commit is contained in:
Earle F. Philhower, III committed 2018-01-20 18:32:21 -08:00
1 parent a359222eae
commit f16cd2b269
2 files changed
+11 -6

No files matched your search

+10 -6
View File
@@ -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;
+1
View File
@@ -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;