From 0172f17b512a631b63ce1edc5baaf5ea0f666621 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Fri, 19 Jan 2018 21:23:17 -0800 Subject: [PATCH] MP3 test in Valgrind Run a host MP3 test using valgrind, shows no errors. --- src/AudioFileSourceSTDIO.cpp | 1 + src/AudioGeneratorMP3.cpp | 2 ++ src/AudioOutputSTDIO.h | 2 +- src/libmad/frame.c | 5 +++++ tests/host/Makefile | 5 ++++- tests/host/mp3.cpp | 4 ++++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/AudioFileSourceSTDIO.cpp b/src/AudioFileSourceSTDIO.cpp index 8d58e35..8e6013a 100644 --- a/src/AudioFileSourceSTDIO.cpp +++ b/src/AudioFileSourceSTDIO.cpp @@ -59,6 +59,7 @@ bool AudioFileSourceSTDIO::seek(int32_t pos, int dir) bool AudioFileSourceSTDIO::close() { fclose(f); + f = NULL; return true; } diff --git a/src/AudioGeneratorMP3.cpp b/src/AudioGeneratorMP3.cpp index e8c3e11..e272109 100644 --- a/src/AudioGeneratorMP3.cpp +++ b/src/AudioGeneratorMP3.cpp @@ -203,6 +203,8 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output) Serial.printf_P(PSTR("MP3 source file not open\n")); return false; // Error } + output->SetBitsPerSample(16); + output->SetChannels(2); if (!output->begin()) return false; // Where we are in generating one frame's data, set to invalid so we will run loop on first getsample() diff --git a/src/AudioOutputSTDIO.h b/src/AudioOutputSTDIO.h index 452a06e..f5a1028 100644 --- a/src/AudioOutputSTDIO.h +++ b/src/AudioOutputSTDIO.h @@ -30,7 +30,7 @@ class AudioOutputSTDIO : public AudioOutput { public: - AudioOutputSTDIO() { filename = NULL; }; + AudioOutputSTDIO() { filename = NULL; f = NULL; }; ~AudioOutputSTDIO() { free(filename); }; virtual bool begin() override; virtual bool ConsumeSample(int16_t sample[2]) override; diff --git a/src/libmad/frame.c b/src/libmad/frame.c index 831783b..92e7e8e 100644 --- a/src/libmad/frame.c +++ b/src/libmad/frame.c @@ -451,6 +451,11 @@ int mad_frame_decode(struct mad_frame *frame, struct mad_stream *stream) frame->header.flags &= ~MAD_FLAG_INCOMPLETE; + // EFP3 - On non-MP3 frames, abort instead of crash..we removed MP-II/MP-I decoders + if (!decoder_table[frame->header.layer - 1]) { + goto fail; + } + if (decoder_table[frame->header.layer - 1](stream, frame) == -1) { if (!MAD_RECOVERABLE(stream->error)) stream->next_frame = stream->this_frame; diff --git a/tests/host/Makefile b/tests/host/Makefile index f8bf588..1af8ade 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -31,12 +31,15 @@ libflac=../../src/libflac/md5.c ../../src/libflac/window.c ../../src/libflac/mem CCOPTS=-g -Wall -m32 -include Arduino.h CPPOPTS=-g -Wall -std=c++11 -m32 -include Arduino.h -mp3: mp3.cpp $(audiolib) +mp3: FORCE rm -f *.o gcc $(CCOPTS) -c $(libmad) -I ../../src/ -I. g++ $(CPPOPTS) -o mp3 mp3.cpp Serial.cpp *.o ../../src/AudioFileSourceSTDIO.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioFileSourceID3.cpp ../../src/AudioGeneratorMP3.cpp -I ../../src/ -I. rm -f *.o + valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./mp3 clean: rm -f mp3 *.o + +FORCE: diff --git a/tests/host/mp3.cpp b/tests/host/mp3.cpp index 42f6314..f022abc 100644 --- a/tests/host/mp3.cpp +++ b/tests/host/mp3.cpp @@ -15,4 +15,8 @@ int main(int argc, char **argv) mp3->begin(in, out); while (mp3->loop()) { /*noop*/ } mp3->stop(); + + delete mp3; + delete out; + delete in; }