From 86e8b8c10d4af0068b06f2da1b6feaf7647e483e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 25 Nov 2016 13:26:40 +0100 Subject: [PATCH] decoder/Thread: skip the ReplayGain loader if the feature is disabled https://bugs.musicpd.org/view.php?id=4595 --- src/decoder/DecoderThread.cxx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/decoder/DecoderThread.cxx b/src/decoder/DecoderThread.cxx index 603140009..cd8eb7538 100644 --- a/src/decoder/DecoderThread.cxx +++ b/src/decoder/DecoderThread.cxx @@ -256,6 +256,23 @@ LoadReplayGain(DecoderClient &client, InputStream &is) client.SubmitReplayGain(&info); } +/** + * Call LoadReplayGain() unless ReplayGain is disabled. This saves + * the I/O overhead when the user is not interested in the feature. + */ +static void +MaybeLoadReplayGain(DecoderBridge &bridge, InputStream &is) +{ + { + const ScopeLock protect(bridge.dc.mutex); + if (bridge.dc.replay_gain_mode == ReplayGainMode::OFF) + /* ReplayGain is disabled */ + return; + } + + LoadReplayGain(bridge, is); +} + /** * Try decoding a stream. * @@ -269,7 +286,7 @@ decoder_run_stream(DecoderBridge &bridge, const char *uri) auto input_stream = decoder_input_stream_open(dc, uri); assert(input_stream); - LoadReplayGain(bridge, *input_stream); + MaybeLoadReplayGain(bridge, *input_stream); const ScopeLock protect(dc.mutex); @@ -376,7 +393,7 @@ decoder_run_file(DecoderBridge &bridge, const char *uri_utf8, Path path_fs) assert(input_stream); - LoadReplayGain(bridge, *input_stream); + MaybeLoadReplayGain(bridge, *input_stream); auto &is = *input_stream; return decoder_plugins_try([&bridge, path_fs, suffix,