From e755f01e631e832e3ef529049888d62af38d2b38 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Thu, 6 Jan 2011 03:24:28 +0100 Subject: Change decoder/encoder API to provide decode/encode functions with a read callback function. --- decoders/mpg123_decoder.cpp | 8 ++++++++ decoders/mpg123_decoder.h | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'decoders') diff --git a/decoders/mpg123_decoder.cpp b/decoders/mpg123_decoder.cpp index 0c2629f..0618320 100644 --- a/decoders/mpg123_decoder.cpp +++ b/decoders/mpg123_decoder.cpp @@ -48,3 +48,11 @@ size_t DecoderMpg123::decode(const uint8_t *input, size_t input_size, uint8_t *o return output_written; } + +size_t DecoderMpg123::decode(ReadFunc read, uint8_t *output, size_t output_size) { + char src_data[0x2000]; + std::streamsize src_read = read(src_data, 0x2000); + if(src_read < 0) + src_read = 0; + return decode((const uint8_t*)src_data, src_read, (uint8_t*)output, output_size); +} diff --git a/decoders/mpg123_decoder.h b/decoders/mpg123_decoder.h index 46f9e4c..5a637af 100644 --- a/decoders/mpg123_decoder.h +++ b/decoders/mpg123_decoder.h @@ -8,11 +8,15 @@ class DecoderMpg123 : public DecoderBase { private: mpg123_handle *handle; - + + size_t decode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size); + + protected: + virtual size_t decode(ReadFunc read, uint8_t *output, size_t output_size); + public: DecoderMpg123(); ~DecoderMpg123(); - size_t decode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size); }; #endif -- cgit v1.2.3