decoder/audiofile: merge audiofile_get_duration() into audiofile_scan_stream()
This commit is contained in:
@@ -237,32 +237,22 @@ audiofile_stream_decode(DecoderClient &client, InputStream &is)
|
|||||||
} while (cmd == DecoderCommand::NONE);
|
} while (cmd == DecoderCommand::NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
static bool
|
||||||
static SignedSongTime
|
audiofile_scan_stream(InputStream &is, TagHandler &handler) noexcept
|
||||||
audiofile_get_duration(InputStream &is) noexcept
|
|
||||||
{
|
{
|
||||||
if (!is.IsSeekable() || !is.KnownSize())
|
if (!is.IsSeekable() || !is.KnownSize())
|
||||||
return SignedSongTime::Negative();
|
return false;
|
||||||
|
|
||||||
AudioFileInputStream afis{nullptr, is};
|
AudioFileInputStream afis{nullptr, is};
|
||||||
AFvirtualfile *vf = setup_virtual_fops(afis);
|
AFvirtualfile *vf = setup_virtual_fops(afis);
|
||||||
AFfilehandle fh = afOpenVirtualFile(vf, "r", nullptr);
|
AFfilehandle fh = afOpenVirtualFile(vf, "r", nullptr);
|
||||||
if (fh == AF_NULL_FILEHANDLE)
|
if (fh == AF_NULL_FILEHANDLE)
|
||||||
return SignedSongTime::Negative();
|
|
||||||
|
|
||||||
const auto duration = audiofile_get_duration(fh);
|
|
||||||
afCloseFile(fh);
|
|
||||||
return duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
audiofile_scan_stream(InputStream &is, TagHandler &handler) noexcept
|
|
||||||
{
|
|
||||||
const auto duration = audiofile_get_duration(is);
|
|
||||||
if (duration.IsNegative())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
handler.OnDuration(SongTime(duration));
|
AtScopeExit(fh) { afCloseFile(fh); };
|
||||||
|
|
||||||
|
handler.OnDuration(audiofile_get_duration(fh));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user