diff options
author | Max Kellermann <max@duempel.org> | 2014-07-09 20:02:07 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-07-09 20:02:07 +0200 |
commit | 913064d6cc0dcfddb4eee0dcddacc5c82fa31448 (patch) | |
tree | 9ca3e14da0d2c355a65170ad994d47c1ac60c17a /src | |
parent | fb45b8a5c94070d30e9a8ef33b04cb44c113515b (diff) | |
parent | 09384df32cc6bef40bc3630de1c928d2eb424909 (diff) | |
download | mpd-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.cxx | 44 | ||||
-rw-r--r-- | src/decoder/plugins/DsdLib.cxx | 10 | ||||
-rw-r--r-- | src/decoder/plugins/DsdLib.hxx | 4 | ||||
-rw-r--r-- | src/decoder/plugins/DsdiffDecoderPlugin.cxx | 25 | ||||
-rw-r--r-- | src/decoder/plugins/DsfDecoderPlugin.cxx | 11 | ||||
-rw-r--r-- | src/decoder/plugins/OpusDecoderPlugin.cxx | 1 | ||||
-rw-r--r-- | src/playlist/plugins/PlsPlaylistPlugin.cxx | 1 |
7 files changed, 50 insertions, 46 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) { diff --git a/src/decoder/plugins/DsdLib.cxx b/src/decoder/plugins/DsdLib.cxx index c52c504e6..0f10b20e9 100644 --- a/src/decoder/plugins/DsdLib.cxx +++ b/src/decoder/plugins/DsdLib.cxx @@ -45,14 +45,6 @@ DsdId::Equals(const char *s) const return memcmp(value, s, sizeof(value)) == 0; } -bool -dsdlib_read(Decoder *decoder, InputStream &is, - void *data, size_t length) -{ - size_t nbytes = decoder_read(decoder, is, data, length); - return nbytes == length; -} - /** * Skip the #input_stream to the specified offset. */ @@ -123,7 +115,7 @@ dsdlib_tag_id3(InputStream &is, id3_byte_t *dsdid3data; dsdid3data = dsdid3; - if (!dsdlib_read(nullptr, is, dsdid3data, count)) + if (!decoder_read_full(nullptr, is, dsdid3data, count)) return; id3_tag = id3_tag_parse(dsdid3data, count); diff --git a/src/decoder/plugins/DsdLib.hxx b/src/decoder/plugins/DsdLib.hxx index 6b02f8bbc..5250922ac 100644 --- a/src/decoder/plugins/DsdLib.hxx +++ b/src/decoder/plugins/DsdLib.hxx @@ -59,10 +59,6 @@ public: }; bool -dsdlib_read(Decoder *decoder, InputStream &is, - void *data, size_t length); - -bool dsdlib_skip_to(Decoder *decoder, InputStream &is, uint64_t offset); diff --git a/src/decoder/plugins/DsdiffDecoderPlugin.cxx b/src/decoder/plugins/DsdiffDecoderPlugin.cxx index 92f7ecdaa..d6f402911 100644 --- a/src/decoder/plugins/DsdiffDecoderPlugin.cxx +++ b/src/decoder/plugins/DsdiffDecoderPlugin.cxx @@ -90,14 +90,14 @@ static bool dsdiff_read_id(Decoder *decoder, InputStream &is, DsdId *id) { - return dsdlib_read(decoder, is, id, sizeof(*id)); + return decoder_read_full(decoder, is, id, sizeof(*id)); } static bool dsdiff_read_chunk_header(Decoder *decoder, InputStream &is, DsdiffChunkHeader *header) { - return dsdlib_read(decoder, is, header, sizeof(*header)); + return decoder_read_full(decoder, is, header, sizeof(*header)); } static bool @@ -109,8 +109,7 @@ dsdiff_read_payload(Decoder *decoder, InputStream &is, if (size != (uint64_t)length) return false; - size_t nbytes = decoder_read(decoder, is, data, length); - return nbytes == length; + return decoder_read_full(decoder, is, data, length); } /** @@ -142,8 +141,8 @@ dsdiff_read_prop_snd(Decoder *decoder, InputStream &is, } else if (header.id.Equals("CHNL")) { uint16_t channels; if (header.GetSize() < sizeof(channels) || - !dsdlib_read(decoder, is, - &channels, sizeof(channels)) || + !decoder_read_full(decoder, is, + &channels, sizeof(channels)) || !dsdlib_skip_to(decoder, is, chunk_end_offset)) return false; @@ -151,8 +150,8 @@ dsdiff_read_prop_snd(Decoder *decoder, InputStream &is, } else if (header.id.Equals("CMPR")) { DsdId type; if (header.GetSize() < sizeof(type) || - !dsdlib_read(decoder, is, - &type, sizeof(type)) || + !decoder_read_full(decoder, is, + &type, sizeof(type)) || !dsdlib_skip_to(decoder, is, chunk_end_offset)) return false; @@ -205,7 +204,7 @@ dsdiff_handle_native_tag(InputStream &is, struct dsdiff_native_tag metatag; - if (!dsdlib_read(nullptr, is, &metatag, sizeof(metatag))) + if (!decoder_read_full(nullptr, is, &metatag, sizeof(metatag))) return; uint32_t length = FromBE32(metatag.size); @@ -218,7 +217,7 @@ dsdiff_handle_native_tag(InputStream &is, char *label; label = string; - if (!dsdlib_read(nullptr, is, label, (size_t)length)) + if (!decoder_read_full(nullptr, is, label, (size_t)length)) return; string[length] = '\0'; @@ -325,7 +324,7 @@ dsdiff_read_metadata(Decoder *decoder, InputStream &is, DsdiffChunkHeader *chunk_header) { DsdiffHeader header; - if (!dsdlib_read(decoder, is, &header, sizeof(header)) || + if (!decoder_read_full(decoder, is, &header, sizeof(header)) || !header.id.Equals("FRM8") || !header.format.Equals("DSD ")) return false; @@ -388,10 +387,10 @@ dsdiff_decode_chunk(Decoder &decoder, InputStream &is, now_size = now_frames * frame_size; } - size_t nbytes = decoder_read(decoder, is, buffer, now_size); - if (nbytes != now_size) + if (!decoder_read_full(&decoder, is, buffer, now_size)) return false; + const size_t nbytes = now_size; chunk_size -= nbytes; if (lsbitfirst) diff --git a/src/decoder/plugins/DsfDecoderPlugin.cxx b/src/decoder/plugins/DsfDecoderPlugin.cxx index 6fbaf6bf6..6a7267f61 100644 --- a/src/decoder/plugins/DsfDecoderPlugin.cxx +++ b/src/decoder/plugins/DsfDecoderPlugin.cxx @@ -100,7 +100,7 @@ dsf_read_metadata(Decoder *decoder, InputStream &is, DsfMetaData *metadata) { DsfHeader dsf_header; - if (!dsdlib_read(decoder, is, &dsf_header, sizeof(dsf_header)) || + if (!decoder_read_full(decoder, is, &dsf_header, sizeof(dsf_header)) || !dsf_header.id.Equals("DSD ")) return false; @@ -114,7 +114,8 @@ dsf_read_metadata(Decoder *decoder, InputStream &is, /* read the 'fmt ' chunk of the DSF file */ DsfFmtChunk dsf_fmt_chunk; - if (!dsdlib_read(decoder, is, &dsf_fmt_chunk, sizeof(dsf_fmt_chunk)) || + if (!decoder_read_full(decoder, is, + &dsf_fmt_chunk, sizeof(dsf_fmt_chunk)) || !dsf_fmt_chunk.id.Equals("fmt ")) return false; @@ -140,7 +141,7 @@ dsf_read_metadata(Decoder *decoder, InputStream &is, /* read the 'data' chunk of the DSF file */ DsfDataChunk data_chunk; - if (!dsdlib_read(decoder, is, &data_chunk, sizeof(data_chunk)) || + if (!decoder_read_full(decoder, is, &data_chunk, sizeof(data_chunk)) || !data_chunk.id.Equals("data")) return false; @@ -244,10 +245,10 @@ dsf_decode_chunk(Decoder &decoder, InputStream &is, now_size = now_frames * frame_size; } - size_t nbytes = decoder_read(&decoder, is, buffer, now_size); - if (nbytes != now_size) + if (!decoder_read_full(&decoder, is, buffer, now_size)) return false; + const size_t nbytes = now_size; chunk_size -= nbytes; if (bitreverse) diff --git a/src/decoder/plugins/OpusDecoderPlugin.cxx b/src/decoder/plugins/OpusDecoderPlugin.cxx index 27c559272..8d1f75e72 100644 --- a/src/decoder/plugins/OpusDecoderPlugin.cxx +++ b/src/decoder/plugins/OpusDecoderPlugin.cxx @@ -36,6 +36,7 @@ #include <ogg/ogg.h> #include <string.h> +#include <stdio.h> static constexpr opus_int32 opus_sample_rate = 48000; diff --git a/src/playlist/plugins/PlsPlaylistPlugin.cxx b/src/playlist/plugins/PlsPlaylistPlugin.cxx index 979f59a96..7df7d134b 100644 --- a/src/playlist/plugins/PlsPlaylistPlugin.cxx +++ b/src/playlist/plugins/PlsPlaylistPlugin.cxx @@ -31,6 +31,7 @@ #include <glib.h> #include <string> +#include <stdio.h> #include <stdio.h> |