diff options
author | Max Kellermann <max@duempel.org> | 2014-07-11 21:17:43 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-07-11 21:18:44 +0200 |
commit | ecb67a1ed16e93f5fe552b28631e517060115648 (patch) | |
tree | a6914d9cca059efdecb26bd957e76aebf06ed748 /src/decoder | |
parent | 0ef843f138c3eef1119e393287ca484bf32f8738 (diff) | |
download | mpd-ecb67a1ed16e93f5fe552b28631e517060115648.tar.gz mpd-ecb67a1ed16e93f5fe552b28631e517060115648.tar.xz mpd-ecb67a1ed16e93f5fe552b28631e517060115648.zip |
decoder/sndfile: use decoder_read_full()
Replaces the loop in sndfile_vio_read(), eliminating duplicate and
fragile code.
Diffstat (limited to 'src/decoder')
-rw-r--r-- | src/decoder/SndfileDecoderPlugin.cxx | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx index 5b2913c13..bcdf6d7ca 100644 --- a/src/decoder/SndfileDecoderPlugin.cxx +++ b/src/decoder/SndfileDecoderPlugin.cxx @@ -36,7 +36,11 @@ struct SndfileInputStream { InputStream &is; size_t Read(void *buffer, size_t size) { - return decoder_read(decoder, is, buffer, size); + /* libsndfile chokes on partial reads; therefore + always force full reads */ + return decoder_read_full(decoder, is, buffer, size) + ? size + : 0; } }; @@ -69,21 +73,7 @@ sndfile_vio_read(void *ptr, sf_count_t count, void *user_data) { SndfileInputStream &sis = *(SndfileInputStream *)user_data; - sf_count_t total_bytes = 0; - - /* this loop is necessary because libsndfile chokes on partial - reads */ - - do { - size_t nbytes = sis.Read((char *)ptr + total_bytes, - count - total_bytes); - if (nbytes == 0) - return -1; - - total_bytes += nbytes; - } while (total_bytes < count); - - return total_bytes; + return sis.Read(ptr, count); } static sf_count_t |