decoder/mad: reduce memory usage while scanning tags

Allocate the frame pointers only when actually decoding the file.
This commit is contained in:
Max Kellermann 2015-10-19 13:12:04 +02:00
parent 38e86af75c
commit 62bfb1a273
2 changed files with 12 additions and 3 deletions

1
NEWS
View File

@ -14,6 +14,7 @@ ver 0.20 (not yet released)
* decoder * decoder
- ffmpeg: support ReplayGain and MixRamp - ffmpeg: support ReplayGain and MixRamp
- ffmpeg: support stream tags - ffmpeg: support stream tags
- mad: reduce memory usage while scanning tags
- mpcdec: read the bit rate - mpcdec: read the bit rate
* playlist * playlist
- cue: don't skip pregap - cue: don't skip pregap

View File

@ -167,6 +167,15 @@ struct MadDecoder {
bool DecodeFirstFrame(Tag **tag); 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 gcc_pure
long TimeToFrame(SongTime t) const; long TimeToFrame(SongTime t) const;
@ -819,9 +828,6 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
return false; return false;
} }
frame_offsets = new long[max_frames];
times = new mad_timer_t[max_frames];
return true; return true;
} }
@ -1049,6 +1055,8 @@ mp3_decode(Decoder &decoder, InputStream &input_stream)
return; return;
} }
data.AllocateBuffers();
Error error; Error error;
AudioFormat audio_format; AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, if (!audio_format_init_checked(audio_format,