diff options
author | Max Kellermann <max@duempel.org> | 2013-12-14 12:21:23 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-14 12:40:43 +0100 |
commit | cb336ff666a8fb2958cfb35c36ffcf613b02cd70 (patch) | |
tree | 41b2468979a5b5ed163832a88754e9f5bb85ffba | |
parent | e2e5433beb02eec1ddafbcdd33ce82ceeee83e0a (diff) | |
download | mpd-cb336ff666a8fb2958cfb35c36ffcf613b02cd70.tar.gz mpd-cb336ff666a8fb2958cfb35c36ffcf613b02cd70.tar.xz mpd-cb336ff666a8fb2958cfb35c36ffcf613b02cd70.zip |
DecoderAPI: add function decoder_skip()
Move code from the "mad" plugin.
-rw-r--r-- | src/DecoderAPI.cxx | 16 | ||||
-rw-r--r-- | src/DecoderAPI.hxx | 8 | ||||
-rw-r--r-- | src/decoder/MadDecoderPlugin.cxx | 15 | ||||
-rw-r--r-- | test/FakeDecoderAPI.cxx | 16 | ||||
-rw-r--r-- | test/run_decoder.cxx | 16 |
5 files changed, 57 insertions, 14 deletions
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx index 4c6a6f918..b31066e17 100644 --- a/src/DecoderAPI.cxx +++ b/src/DecoderAPI.cxx @@ -306,6 +306,22 @@ decoder_read(Decoder *decoder, return nbytes; } +bool +decoder_skip(Decoder *decoder, InputStream &is, size_t size) +{ + while (size > 0) { + char buffer[1024]; + size_t nbytes = decoder_read(decoder, is, buffer, + std::min(sizeof(buffer), size)); + if (nbytes == 0) + return false; + + size -= nbytes; + } + + return true; +} + void decoder_timestamp(Decoder &decoder, double t) { diff --git a/src/DecoderAPI.hxx b/src/DecoderAPI.hxx index df1b5c40d..f88503fed 100644 --- a/src/DecoderAPI.hxx +++ b/src/DecoderAPI.hxx @@ -117,6 +117,14 @@ decoder_read(Decoder &decoder, InputStream &is, } /** + * Skip data on the #InputStream. + * + * @return true on success, false on error or command + */ +bool +decoder_skip(Decoder *decoder, InputStream &is, size_t size); + +/** * Sets the time stamp for the next data chunk [seconds]. The MPD * core automatically counts it up, and a decoder plugin only needs to * use this function if it thinks that adding to the time stamp based diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx index 0359840fc..c98d65f87 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 } diff --git a/test/FakeDecoderAPI.cxx b/test/FakeDecoderAPI.cxx index e2040b40d..469e37feb 100644 --- a/test/FakeDecoderAPI.cxx +++ b/test/FakeDecoderAPI.cxx @@ -65,6 +65,22 @@ decoder_read(gcc_unused Decoder *decoder, return is.LockRead(buffer, length, IgnoreError()); } +bool +decoder_skip(Decoder *decoder, InputStream &is, size_t size) +{ + while (size > 0) { + char buffer[1024]; + size_t nbytes = decoder_read(decoder, is, buffer, + std::min(sizeof(buffer), size)); + if (nbytes == 0) + return false; + + size -= nbytes; + } + + return true; +} + void decoder_timestamp(gcc_unused Decoder &decoder, gcc_unused double t) diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx index 2f7330a1d..cab68c64e 100644 --- a/test/run_decoder.cxx +++ b/test/run_decoder.cxx @@ -101,6 +101,22 @@ decoder_read(gcc_unused Decoder *decoder, return is.LockRead(buffer, length, IgnoreError()); } +bool +decoder_skip(Decoder *decoder, InputStream &is, size_t size) +{ + while (size > 0) { + char buffer[1024]; + size_t nbytes = decoder_read(decoder, is, buffer, + std::min(sizeof(buffer), size)); + if (nbytes == 0) + return false; + + size -= nbytes; + } + + return true; +} + void decoder_timestamp(gcc_unused Decoder &decoder, gcc_unused double t) |