decoder/thread: open InputStream in decoder_run_file() in any case

decoder_load_replay_gain() will create the InputStream anyway, so
we're not saving any overhead by opening the InputStream on demand
only.
This commit is contained in:
Max Kellermann 2016-02-23 11:07:02 +01:00
parent 1b58bd64ff
commit a1e680fec7

View File

@ -279,18 +279,6 @@ decoder_run_stream(Decoder &decoder, const char *uri)
decoder_run_stream_fallback(decoder, *input_stream)); decoder_run_stream_fallback(decoder, *input_stream));
} }
/**
* Attempt to load replay gain data, and pass it to
* decoder_replay_gain().
*/
static void
decoder_load_replay_gain(Decoder &decoder, Path path_fs)
{
ReplayGainInfo info;
if (replay_gain_ape_read(path_fs, info))
decoder_replay_gain(decoder, &info);
}
/** /**
* Decode a file with the given decoder plugin. * Decode a file with the given decoder plugin.
* *
@ -298,6 +286,7 @@ decoder_load_replay_gain(Decoder &decoder, Path path_fs)
*/ */
static bool static bool
TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix, TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix,
InputStream &input_stream,
const DecoderPlugin &plugin) const DecoderPlugin &plugin)
{ {
if (!plugin.SupportsSuffix(suffix)) if (!plugin.SupportsSuffix(suffix))
@ -309,15 +298,8 @@ TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix,
const ScopeLock protect(dc.mutex); const ScopeLock protect(dc.mutex);
return decoder_file_decode(plugin, decoder, path_fs); return decoder_file_decode(plugin, decoder, path_fs);
} else if (plugin.stream_decode != nullptr) { } else if (plugin.stream_decode != nullptr) {
auto input_stream = decoder_input_stream_open(dc, path_fs,
decoder.error);
if (input_stream == nullptr)
/* returning true to stop the search for
another decoder plugin */
return true;
const ScopeLock protect(dc.mutex); const ScopeLock protect(dc.mutex);
return decoder_stream_decode(plugin, decoder, *input_stream); return decoder_stream_decode(plugin, decoder, input_stream);
} else } else
return false; return false;
} }
@ -334,13 +316,20 @@ decoder_run_file(Decoder &decoder, const char *uri_utf8, Path path_fs)
if (suffix == nullptr) if (suffix == nullptr)
return false; return false;
decoder_load_replay_gain(decoder, path_fs); auto input_stream = decoder_input_stream_open(decoder.dc, path_fs,
decoder.error);
if (input_stream == nullptr)
return false;
return decoder_plugins_try([&decoder, path_fs, LoadReplayGain(decoder, *input_stream);
suffix](const DecoderPlugin &plugin){
auto &is = *input_stream;
return decoder_plugins_try([&decoder, path_fs, suffix,
&is](const DecoderPlugin &plugin){
return TryDecoderFile(decoder, return TryDecoderFile(decoder,
path_fs, path_fs,
suffix, suffix,
is,
plugin); plugin);
}); });
} }