decoder/audiofile: implement scan_stream() instead of scan_file()

This commit is contained in:
Max Kellermann 2014-07-10 09:23:56 +02:00
parent 1d214b4aed
commit 107321e385
2 changed files with 24 additions and 23 deletions

1
NEWS
View File

@ -30,6 +30,7 @@ ver 0.19 (not yet released)
- volume: improved software volume dithering - volume: improved software volume dithering
* decoder: * decoder:
- vorbis, flac, opus: honor DESCRIPTION= tag in Xiph-based files as a comment to the song - vorbis, flac, opus: honor DESCRIPTION= tag in Xiph-based files as a comment to the song
- audiofile: support scanning remote files
* encoder: * encoder:
- shine: new encoder plugin - shine: new encoder plugin
* threads: * threads:

View File

@ -63,19 +63,6 @@ audiofile_get_duration(AFfilehandle fh)
return frame_count / rate; return frame_count / rate;
} }
gcc_pure
static int
audiofile_get_duration(Path path_fs)
{
AFfilehandle af_fp = afOpenFile(path_fs.c_str(), "r", nullptr);
if (af_fp == AF_NULL_FILEHANDLE) {
return -1;
}
int total_time = int(audiofile_get_duration(af_fp));
afCloseFile(af_fp);
return total_time;
}
static ssize_t static ssize_t
audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length) audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
{ {
@ -250,18 +237,31 @@ audiofile_stream_decode(Decoder &decoder, InputStream &is)
afCloseFile(af_fp); afCloseFile(af_fp);
} }
static bool gcc_pure
audiofile_scan_file(Path path_fs, static int
const struct tag_handler *handler, void *handler_ctx) audiofile_get_duration(InputStream &is)
{ {
int total_time = audiofile_get_duration(path_fs); if (!is.IsSeekable())
return -1;
if (total_time < 0) { AudioFileInputStream afis{nullptr, is};
FormatWarning(audiofile_domain, AFvirtualfile *vf = setup_virtual_fops(afis);
"Failed to get total song time from: %s", AFfilehandle fh = afOpenVirtualFile(vf, "r", nullptr);
path_fs.c_str()); if (fh == AF_NULL_FILEHANDLE)
return -1;
int duration = int(audiofile_get_duration(fh));
afCloseFile(fh);
return duration;
}
static bool
audiofile_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
int total_time = audiofile_get_duration(is);
if (total_time < 0)
return false; return false;
}
tag_handler_invoke_duration(handler, handler_ctx, total_time); tag_handler_invoke_duration(handler, handler_ctx, total_time);
return true; return true;
@ -283,8 +283,8 @@ const struct DecoderPlugin audiofile_decoder_plugin = {
nullptr, nullptr,
audiofile_stream_decode, audiofile_stream_decode,
nullptr, nullptr,
audiofile_scan_file,
nullptr, nullptr,
audiofile_scan_stream,
nullptr, nullptr,
audiofile_suffixes, audiofile_suffixes,
audiofile_mime_types, audiofile_mime_types,