aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/plugins/AudiofileDecoderPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-07-09 20:02:07 +0200
committerMax Kellermann <max@duempel.org>2014-07-09 20:02:07 +0200
commit913064d6cc0dcfddb4eee0dcddacc5c82fa31448 (patch)
tree9ca3e14da0d2c355a65170ad994d47c1ac60c17a /src/decoder/plugins/AudiofileDecoderPlugin.cxx
parentfb45b8a5c94070d30e9a8ef33b04cb44c113515b (diff)
parent09384df32cc6bef40bc3630de1c928d2eb424909 (diff)
downloadmpd-913064d6cc0dcfddb4eee0dcddacc5c82fa31448.tar.gz
mpd-913064d6cc0dcfddb4eee0dcddacc5c82fa31448.tar.xz
mpd-913064d6cc0dcfddb4eee0dcddacc5c82fa31448.zip
Merge branch 'v0.18.x'
Diffstat (limited to '')
-rw-r--r--src/decoder/plugins/AudiofileDecoderPlugin.cxx44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/decoder/plugins/AudiofileDecoderPlugin.cxx b/src/decoder/plugins/AudiofileDecoderPlugin.cxx
index a3f0ee380..994a5a109 100644
--- a/src/decoder/plugins/AudiofileDecoderPlugin.cxx
+++ b/src/decoder/plugins/AudiofileDecoderPlugin.cxx
@@ -32,12 +32,27 @@
#include <af_vfs.h>
#include <assert.h>
+#include <stdio.h>
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
#define CHUNK_SIZE 1020
static constexpr Domain audiofile_domain("audiofile");
+struct AudioFileInputStream {
+ Decoder *const decoder;
+ InputStream &is;
+
+ size_t Read(void *buffer, size_t size) {
+ /* libaudiofile does not like partial reads at all,
+ and wil abort playback; therefore always force full
+ reads */
+ return decoder_read_full(decoder, is, buffer, size)
+ ? size
+ : 0;
+ }
+};
+
gcc_pure
static int
audiofile_get_duration(Path path_fs)
@@ -57,29 +72,26 @@ audiofile_get_duration(Path path_fs)
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();
}
@@ -95,7 +107,8 @@ 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;
InputStream::offset_type offset = _offset;
if (is_relative)
@@ -110,10 +123,10 @@ audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset _offset,
}
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;
@@ -180,7 +193,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) {