From 62bfb1a2731ba6c7ee27009316109ef03a60d950 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 19 Oct 2015 13:12:04 +0200 Subject: decoder/mad: reduce memory usage while scanning tags Allocate the frame pointers only when actually decoding the file. --- src/decoder/plugins/MadDecoderPlugin.cxx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/decoder/plugins/MadDecoderPlugin.cxx b/src/decoder/plugins/MadDecoderPlugin.cxx index ea2c9ac6c..9baa6fb9c 100644 --- a/src/decoder/plugins/MadDecoderPlugin.cxx +++ b/src/decoder/plugins/MadDecoderPlugin.cxx @@ -167,6 +167,15 @@ struct MadDecoder { bool DecodeFirstFrame(Tag **tag); + void AllocateBuffers() { + assert(max_frames > 0); + assert(frame_offsets == nullptr); + assert(times == nullptr); + + frame_offsets = new long[max_frames]; + times = new mad_timer_t[max_frames]; + } + gcc_pure long TimeToFrame(SongTime t) const; @@ -819,9 +828,6 @@ MadDecoder::DecodeFirstFrame(Tag **tag) return false; } - frame_offsets = new long[max_frames]; - times = new mad_timer_t[max_frames]; - return true; } @@ -1049,6 +1055,8 @@ mp3_decode(Decoder &decoder, InputStream &input_stream) return; } + data.AllocateBuffers(); + Error error; AudioFormat audio_format; if (!audio_format_init_checked(audio_format, -- cgit v1.2.3