From d37b788ea81e4b282e3f24aa5cad31d85229cc30 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/DecoderAPI.cxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/DecoderAPI.cxx') diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx index b31066e17..a3f2fc3e0 100644 --- a/src/DecoderAPI.cxx +++ b/src/DecoderAPI.cxx @@ -306,6 +306,24 @@ decoder_read(Decoder *decoder, return nbytes; } +bool +decoder_read_full(Decoder *decoder, InputStream &is, + void *_buffer, size_t size) +{ + uint8_t *buffer = (uint8_t *)_buffer; + + while (size > 0) { + size_t nbytes = decoder_read(decoder, is, buffer, size); + if (nbytes == 0) + return false; + + buffer += nbytes; + size -= nbytes; + } + + return true; +} + bool decoder_skip(Decoder *decoder, InputStream &is, size_t size) { -- cgit v1.2.3