Commit a1e680fe authored by Max Kellermann's avatar Max Kellermann

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.
parent 1b58bd64
...@@ -280,24 +280,13 @@ decoder_run_stream(Decoder &decoder, const char *uri) ...@@ -280,24 +280,13 @@ decoder_run_stream(Decoder &decoder, const char *uri)
} }
/** /**
* 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.
* *
* DecoderControl::mutex is not locked by caller. * DecoderControl::mutex is not locked by caller.
*/ */
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, ...@@ -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) ...@@ -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;
LoadReplayGain(decoder, *input_stream);
return decoder_plugins_try([&decoder, path_fs, auto &is = *input_stream;
suffix](const DecoderPlugin &plugin){ 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);
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment