From bc6472bb9ea12fb2226570eb2dc49058b4d8bd6c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 9 Jul 2014 18:46:58 +0200 Subject: decoder/audiofile: use decoder_read() .. instead of InputStream::LockRead(). The former is cancellable. --- NEWS | 2 ++ src/decoder/AudiofileDecoderPlugin.cxx | 39 +++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index add093393..19e3b2219 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ ver 0.18.12 (not yet released) * database - proxy: fix build failure with libmpdclient 2.2 - proxy: fix add/search and other commands with libmpdclient < 2.9 +* decoder + - audiofile: improve responsiveness ver 0.18.11 (2014/05/12) * decoder 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) { -- cgit v1.2.3