From 3f221e2edb3bebe3806c4a7f5490ba92ed99c101 Mon Sep 17 00:00:00 2001 From: Gustavo Zacarias Date: Tue, 8 Jul 2014 10:46:15 -0300 Subject: decoder/AudiofileDecoderPlugin: fix build failure due to missing stdio.h include Signed-off-by: Gustavo Zacarias --- src/decoder/AudiofileDecoderPlugin.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'src/decoder') diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx index ab3557e52..92223f214 100644 --- a/src/decoder/AudiofileDecoderPlugin.cxx +++ b/src/decoder/AudiofileDecoderPlugin.cxx @@ -31,6 +31,7 @@ #include #include +#include /* pick 1020 since its devisible for 8,16,24, and 32-bit audio */ #define CHUNK_SIZE 1020 -- cgit v1.2.3 From a70443af319d5aa562c44a685ef753d117643fc0 Mon Sep 17 00:00:00 2001 From: Gustavo Zacarias Date: Tue, 8 Jul 2014 10:46:16 -0300 Subject: decoder/OpusDecoderPlugin: fix build failure due to missing stdio.h include Signed-off-by: Gustavo Zacarias --- src/decoder/OpusDecoderPlugin.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'src/decoder') diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx index f3d7b342e..01ea3687a 100644 --- a/src/decoder/OpusDecoderPlugin.cxx +++ b/src/decoder/OpusDecoderPlugin.cxx @@ -40,6 +40,7 @@ #include #include +#include static constexpr opus_int32 opus_sample_rate = 48000; -- cgit v1.2.3 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. --- src/decoder/AudiofileDecoderPlugin.cxx | 39 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src/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 From bf7417981f2527348fb261f40f4de15f9b350db5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 14 Dec 2013 12:21:23 +0100 Subject: DecoderAPI: add function decoder_skip() Move code from the "mad" plugin. --- src/decoder/MadDecoderPlugin.cxx | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx index 9dd86c55f..7afc8ef8f 100644 --- a/src/decoder/MadDecoderPlugin.cxx +++ b/src/decoder/MadDecoderPlugin.cxx @@ -413,20 +413,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag) mad_stream_skip(&stream, tagsize); } else { mad_stream_skip(&stream, count); - - while (count < tagsize) { - size_t len = tagsize - count; - char ignored[1024]; - if (len > sizeof(ignored)) - len = sizeof(ignored); - - len = decoder_read(decoder, input_stream, - ignored, len); - if (len == 0) - break; - else - count += len; - } + decoder_skip(decoder, input_stream, tagsize - count); } #endif } -- cgit v1.2.3 From 0759421d119d8d3d829978ede81683ca54d65d69 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 14 Dec 2013 12:43:06 +0100 Subject: DecoderAPI: add function decoder_read_full() Move code from the "mad" plugin. --- src/decoder/MadDecoderPlugin.cxx | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx index 7afc8ef8f..6f619b34b 100644 --- a/src/decoder/MadDecoderPlugin.cxx +++ b/src/decoder/MadDecoderPlugin.cxx @@ -353,18 +353,8 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag) memcpy(allocated, stream.this_frame, count); mad_stream_skip(&(stream), count); - while (count < tagsize) { - size_t len; - - len = decoder_read(decoder, input_stream, - allocated + count, tagsize - count); - if (len == 0) - break; - else - count += len; - } - - if (count != tagsize) { + if (!decoder_read_full(decoder, input_stream, + allocated + count, tagsize - count)) { LogDebug(mad_domain, "error parsing ID3 tag"); g_free(allocated); return; -- cgit v1.2.3 From 20538516b92082067ce3477d612fb404ba8671ad Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 9 Jul 2014 19:05:20 +0200 Subject: decoder/audiofile: use decoder_read_full() Works around WAV stream playback bug, because libaudiofile does not like partial reads (Mantis 0004028). --- src/decoder/AudiofileDecoderPlugin.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/decoder') diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx index 7c76deb7d..3fb23bc20 100644 --- a/src/decoder/AudiofileDecoderPlugin.cxx +++ b/src/decoder/AudiofileDecoderPlugin.cxx @@ -43,7 +43,12 @@ struct AudioFileInputStream { InputStream &is; size_t Read(void *buffer, size_t size) { - return decoder_read(decoder, is, buffer, 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; } }; -- cgit v1.2.3 From 09384df32cc6bef40bc3630de1c928d2eb424909 Mon Sep 17 00:00:00 2001 From: Joff Date: Wed, 9 Jul 2014 19:18:36 +0200 Subject: decoder/dsd: use decoder_read_full() where appropriate Addresses Mantis ticket 0004015. [mk: use decoder_read_full() only when needed, and a few formal changes] --- src/decoder/DsdLib.cxx | 10 +--------- src/decoder/DsdLib.hxx | 4 ---- src/decoder/DsdiffDecoderPlugin.cxx | 25 ++++++++++++------------- src/decoder/DsfDecoderPlugin.cxx | 11 ++++++----- 4 files changed, 19 insertions(+), 31 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/DsdLib.cxx b/src/decoder/DsdLib.cxx index 67cc7e945..eafedda8f 100644 --- a/src/decoder/DsdLib.cxx +++ b/src/decoder/DsdLib.cxx @@ -49,14 +49,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. */ @@ -149,7 +141,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/DsdLib.hxx b/src/decoder/DsdLib.hxx index 53160cf1e..5c6127149 100644 --- a/src/decoder/DsdLib.hxx +++ b/src/decoder/DsdLib.hxx @@ -58,10 +58,6 @@ public: } }; -bool -dsdlib_read(Decoder *decoder, InputStream &is, - void *data, size_t length); - bool dsdlib_skip_to(Decoder *decoder, InputStream &is, int64_t offset); diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx index a3c0149b9..f8506851a 100644 --- a/src/decoder/DsdiffDecoderPlugin.cxx +++ b/src/decoder/DsdiffDecoderPlugin.cxx @@ -93,14 +93,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 @@ -112,8 +112,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); } /** @@ -145,8 +144,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; @@ -154,8 +153,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; @@ -208,7 +207,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); @@ -221,7 +220,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'; @@ -328,7 +327,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; @@ -391,10 +390,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/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx index 5ef94e647..ad5483c32 100644 --- a/src/decoder/DsfDecoderPlugin.cxx +++ b/src/decoder/DsfDecoderPlugin.cxx @@ -103,7 +103,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; @@ -117,7 +117,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; @@ -143,7 +144,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; @@ -247,10 +248,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) -- cgit v1.2.3