aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-07-10 09:23:56 +0200
committerMax Kellermann <max@duempel.org>2014-07-10 09:23:56 +0200
commit107321e385c95487fa3535ded98ed6d87cb66b00 (patch)
treedfbecab6b563f018d2b4b4be51c394ab8dc11253 /src
parent1d214b4aed84384e91400a9a83b3f39bc3ba24aa (diff)
downloadmpd-107321e385c95487fa3535ded98ed6d87cb66b00.tar.gz
mpd-107321e385c95487fa3535ded98ed6d87cb66b00.tar.xz
mpd-107321e385c95487fa3535ded98ed6d87cb66b00.zip
decoder/audiofile: implement scan_stream() instead of scan_file()
Diffstat (limited to 'src')
-rw-r--r--src/decoder/plugins/AudiofileDecoderPlugin.cxx46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/decoder/plugins/AudiofileDecoderPlugin.cxx b/src/decoder/plugins/AudiofileDecoderPlugin.cxx
index f0bc03ed1..08e3de134 100644
--- a/src/decoder/plugins/AudiofileDecoderPlugin.cxx
+++ b/src/decoder/plugins/AudiofileDecoderPlugin.cxx
@@ -63,19 +63,6 @@ audiofile_get_duration(AFfilehandle fh)
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
audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
{
@@ -250,18 +237,31 @@ audiofile_stream_decode(Decoder &decoder, InputStream &is)
afCloseFile(af_fp);
}
-static bool
-audiofile_scan_file(Path path_fs,
- const struct tag_handler *handler, void *handler_ctx)
+gcc_pure
+static int
+audiofile_get_duration(InputStream &is)
{
- int total_time = audiofile_get_duration(path_fs);
+ if (!is.IsSeekable())
+ return -1;
+
+ AudioFileInputStream afis{nullptr, is};
+ AFvirtualfile *vf = setup_virtual_fops(afis);
+ AFfilehandle fh = afOpenVirtualFile(vf, "r", nullptr);
+ if (fh == AF_NULL_FILEHANDLE)
+ return -1;
- if (total_time < 0) {
- FormatWarning(audiofile_domain,
- "Failed to get total song time from: %s",
- path_fs.c_str());
+ 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;
- }
tag_handler_invoke_duration(handler, handler_ctx, total_time);
return true;
@@ -283,8 +283,8 @@ const struct DecoderPlugin audiofile_decoder_plugin = {
nullptr,
audiofile_stream_decode,
nullptr,
- audiofile_scan_file,
nullptr,
+ audiofile_scan_stream,
nullptr,
audiofile_suffixes,
audiofile_mime_types,