Commit 9b69d22d authored by Max Kellermann's avatar Max Kellermann

DecoderThread: pass Path object around for local song files

parent 4ab4cf85
...@@ -282,15 +282,15 @@ decoder_run_stream(Decoder &decoder, const char *uri) ...@@ -282,15 +282,15 @@ decoder_run_stream(Decoder &decoder, const char *uri)
* decoder_replay_gain(). * decoder_replay_gain().
*/ */
static void static void
decoder_load_replay_gain(Decoder &decoder, const char *path_fs) decoder_load_replay_gain(Decoder &decoder, Path path_fs)
{ {
ReplayGainInfo info; ReplayGainInfo info;
if (replay_gain_ape_read(Path::FromFS(path_fs), info)) if (replay_gain_ape_read(path_fs, info))
decoder_replay_gain(decoder, &info); decoder_replay_gain(decoder, &info);
} }
static bool static bool
TryDecoderFile(Decoder &decoder, const char *path_fs, const char *suffix, TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix,
const DecoderPlugin &plugin) const DecoderPlugin &plugin)
{ {
if (!plugin.SupportsSuffix(suffix)) if (!plugin.SupportsSuffix(suffix))
...@@ -301,13 +301,13 @@ TryDecoderFile(Decoder &decoder, const char *path_fs, const char *suffix, ...@@ -301,13 +301,13 @@ TryDecoderFile(Decoder &decoder, const char *path_fs, const char *suffix,
if (plugin.file_decode != nullptr) { if (plugin.file_decode != nullptr) {
dc.Lock(); dc.Lock();
if (decoder_file_decode(plugin, decoder, path_fs)) if (decoder_file_decode(plugin, decoder, path_fs.c_str()))
return true; return true;
dc.Unlock(); dc.Unlock();
} else if (plugin.stream_decode != nullptr) { } else if (plugin.stream_decode != nullptr) {
InputStream *input_stream = InputStream *input_stream =
decoder_input_stream_open(dc, path_fs); decoder_input_stream_open(dc, path_fs.c_str());
if (input_stream == nullptr) if (input_stream == nullptr)
return false; return false;
...@@ -333,9 +333,9 @@ TryDecoderFile(Decoder &decoder, const char *path_fs, const char *suffix, ...@@ -333,9 +333,9 @@ TryDecoderFile(Decoder &decoder, const char *path_fs, const char *suffix,
* Try decoding a file. * Try decoding a file.
*/ */
static bool static bool
decoder_run_file(Decoder &decoder, const char *path_fs) decoder_run_file(Decoder &decoder, const char *uri_utf8, Path path_fs)
{ {
const char *suffix = uri_get_suffix(path_fs); const char *suffix = uri_get_suffix(uri_utf8);
if (suffix == nullptr) if (suffix == nullptr)
return false; return false;
...@@ -344,8 +344,10 @@ decoder_run_file(Decoder &decoder, const char *path_fs) ...@@ -344,8 +344,10 @@ decoder_run_file(Decoder &decoder, const char *path_fs)
decoder_load_replay_gain(decoder, path_fs); decoder_load_replay_gain(decoder, path_fs);
if (decoder_plugins_try([&decoder, path_fs, suffix](const DecoderPlugin &plugin){ if (decoder_plugins_try([&decoder, path_fs,
return TryDecoderFile(decoder, path_fs, suffix, suffix](const DecoderPlugin &plugin){
return TryDecoderFile(decoder,
path_fs, suffix,
plugin); plugin);
})) }))
return true; return true;
...@@ -356,7 +358,7 @@ decoder_run_file(Decoder &decoder, const char *path_fs) ...@@ -356,7 +358,7 @@ decoder_run_file(Decoder &decoder, const char *path_fs)
static void static void
decoder_run_song(DecoderControl &dc, decoder_run_song(DecoderControl &dc,
const DetachedSong &song, const char *uri) const DetachedSong &song, const char *uri, Path path_fs)
{ {
Decoder decoder(dc, dc.start_ms > 0, Decoder decoder(dc, dc.start_ms > 0,
new Tag(song.GetTag())); new Tag(song.GetTag()));
...@@ -366,8 +368,8 @@ decoder_run_song(DecoderControl &dc, ...@@ -366,8 +368,8 @@ decoder_run_song(DecoderControl &dc,
decoder_command_finished_locked(dc); decoder_command_finished_locked(dc);
ret = song.IsFile() ret = !path_fs.IsNull()
? decoder_run_file(decoder, uri) ? decoder_run_file(decoder, uri, path_fs)
: decoder_run_stream(decoder, uri); : decoder_run_stream(decoder, uri);
dc.Unlock(); dc.Unlock();
...@@ -409,19 +411,23 @@ decoder_run(DecoderControl &dc) ...@@ -409,19 +411,23 @@ decoder_run(DecoderControl &dc)
assert(dc.song != nullptr); assert(dc.song != nullptr);
const DetachedSong &song = *dc.song; const DetachedSong &song = *dc.song;
const std::string uri = song.IsFile() const char *const uri_utf8 = song.GetRealURI();
? map_song_fs(song).c_str()
: song.GetRealURI();
if (uri.empty()) { Path path_fs = Path::Null();
dc.state = DecoderState::ERROR; AllocatedPath path_buffer = AllocatedPath::Null();
dc.error.Set(decoder_domain, "Failed to map song"); if (song.IsFile()) {
path_buffer = map_song_fs(song);
if (path_buffer.IsNull()) {
dc.state = DecoderState::ERROR;
dc.error.Set(decoder_domain, "Failed to map song");
decoder_command_finished_locked(dc);
return;
}
decoder_command_finished_locked(dc); path_fs = path_buffer;
return;
} }
decoder_run_song(dc, song, uri.c_str()); decoder_run_song(dc, song, uri_utf8, path_fs);
} }
......
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