aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/AudiofileDecoderPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-07-09 18:46:58 +0200
committerMax Kellermann <max@duempel.org>2014-07-09 18:57:50 +0200
commitbc6472bb9ea12fb2226570eb2dc49058b4d8bd6c (patch)
treeeb385c466a0d08126606fa0c66699fb70e107651 /src/decoder/AudiofileDecoderPlugin.cxx
parentd4bd947bf550a208007b777eb1425f7fd75ce9b0 (diff)
downloadmpd-bc6472bb9ea12fb2226570eb2dc49058b4d8bd6c.tar.gz
mpd-bc6472bb9ea12fb2226570eb2dc49058b4d8bd6c.tar.xz
mpd-bc6472bb9ea12fb2226570eb2dc49058b4d8bd6c.zip
decoder/audiofile: use decoder_read()
.. instead of InputStream::LockRead(). The former is cancellable.
Diffstat (limited to 'src/decoder/AudiofileDecoderPlugin.cxx')
-rw-r--r--src/decoder/AudiofileDecoderPlugin.cxx39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx
index 92223f214..7c76deb7d 100644
--- a/src/decoder/AudiofileDecoderPlugin.cxx
+++ b/src/decoder/AudiofileDecoderPlugin.cxx
@@ -38,6 +38,15 @@
static constexpr Domain audiofile_domain("audiofile");
+struct AudioFileInputStream {
+ Decoder *const decoder;
+ InputStream &is;
+
+ size_t Read(void *buffer, size_t size) {
+ return decoder_read(decoder, is, buffer, size);
+ }
+};
+
static int audiofile_get_duration(const char *file)
{
int total_time;
@@ -55,29 +64,26 @@ static int audiofile_get_duration(const char *file)
static ssize_t
audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
{
- InputStream &is = *(InputStream *)vfile->closure;
-
- Error error;
- size_t nbytes = is.LockRead(data, length, error);
- if (nbytes == 0 && error.IsDefined()) {
- LogError(error);
- return -1;
- }
+ AudioFileInputStream &afis = *(AudioFileInputStream *)vfile->closure;
- return nbytes;
+ return afis.Read(data, length);
}
static AFfileoffset
audiofile_file_length(AFvirtualfile *vfile)
{
- InputStream &is = *(InputStream *)vfile->closure;
+ AudioFileInputStream &afis = *(AudioFileInputStream *)vfile->closure;
+ InputStream &is = afis.is;
+
return is.GetSize();
}
static AFfileoffset
audiofile_file_tell(AFvirtualfile *vfile)
{
- InputStream &is = *(InputStream *)vfile->closure;
+ AudioFileInputStream &afis = *(AudioFileInputStream *)vfile->closure;
+ InputStream &is = afis.is;
+
return is.GetOffset();
}
@@ -92,7 +98,9 @@ audiofile_file_destroy(AFvirtualfile *vfile)
static AFfileoffset
audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset offset, int is_relative)
{
- InputStream &is = *(InputStream *)vfile->closure;
+ AudioFileInputStream &afis = *(AudioFileInputStream *)vfile->closure;
+ InputStream &is = afis.is;
+
int whence = (is_relative ? SEEK_CUR : SEEK_SET);
Error error;
@@ -104,10 +112,10 @@ audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset offset, int is_relative)
}
static AFvirtualfile *
-setup_virtual_fops(InputStream &stream)
+setup_virtual_fops(AudioFileInputStream &afis)
{
AFvirtualfile *vf = new AFvirtualfile();
- vf->closure = &stream;
+ vf->closure = &afis;
vf->write = nullptr;
vf->read = audiofile_file_read;
vf->length = audiofile_file_length;
@@ -174,7 +182,8 @@ audiofile_stream_decode(Decoder &decoder, InputStream &is)
return;
}
- vf = setup_virtual_fops(is);
+ AudioFileInputStream afis{&decoder, is};
+ vf = setup_virtual_fops(afis);
af_fp = afOpenVirtualFile(vf, "r", nullptr);
if (af_fp == AF_NULL_FILEHANDLE) {