aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-10-19 13:12:04 +0200
committerMax Kellermann <max@duempel.org>2015-10-19 13:12:36 +0200
commit62bfb1a2731ba6c7ee27009316109ef03a60d950 (patch)
tree197342b118e6c1c78ebe595328a3f9464b04ecd3
parent38e86af75c02cf75e8dc372ef71cc8c3010d0313 (diff)
downloadmpd-62bfb1a2731ba6c7ee27009316109ef03a60d950.tar.gz
mpd-62bfb1a2731ba6c7ee27009316109ef03a60d950.tar.xz
mpd-62bfb1a2731ba6c7ee27009316109ef03a60d950.zip
decoder/mad: reduce memory usage while scanning tags
Allocate the frame pointers only when actually decoding the file.
-rw-r--r--NEWS1
-rw-r--r--src/decoder/plugins/MadDecoderPlugin.cxx14
2 files changed, 12 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 145361c35..231ac8bd9 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ ver 0.20 (not yet released)
* decoder
- ffmpeg: support ReplayGain and MixRamp
- ffmpeg: support stream tags
+ - mad: reduce memory usage while scanning tags
- mpcdec: read the bit rate
* playlist
- cue: don't skip pregap
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,