From 6f2fefdd9ff5f8561b3538efb5eb0765a9b4a141 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Thu, 6 Jan 2011 05:29:39 +0100 Subject: Replaced iostream-based decoder-encoder chain with direct chain. --- encoder.h | 56 +++++++++++++------------------------------------------- 1 file changed, 13 insertions(+), 43 deletions(-) (limited to 'encoder.h') diff --git a/encoder.h b/encoder.h index d000ffc..6d7a0c1 100644 --- a/encoder.h +++ b/encoder.h @@ -1,57 +1,27 @@ #ifndef ENCODER_H #define ENCODER_H -#include -#include +#include "decoder.h" + #include -#include -#include #include -class EncoderBase { - friend class EncoderFilter; - - protected: - typedef boost::function ReadFunc; +class Encoder { + public: + typedef boost::shared_ptr p; - virtual size_t encode(ReadFunc read, uint8_t *output, size_t output_size) = 0; + //! Virtual destructor. + virtual ~Encoder() {} - public: - typedef boost::shared_ptr p; - virtual ~EncoderBase() {} -}; - -//! Input filter to hold an encoder in a filter chain. -class EncoderFilter : public boost::iostreams::multichar_input_filter { - private: - EncoderBase::p encoder; + //! Initialize encoders. + static void init(); - //! Functor binding a source to a read function. - template - struct ReadFunc { - T& s; - - ReadFunc(T& s_) : s(s_) {} - - std::size_t operator()(char* buf, std::size_t buf_size) { - return boost::iostreams::read(s, buf, buf_size); - } - }; - - public: - typedef boost::shared_ptr p; - EncoderFilter(EncoderBase::p encoder_); + //! Construct and return requested encoder. + static p get(const std::string& name, RawAudioSource::p source); - template - std::streamsize read(Source& src, char *s, std::streamsize n) { - return encoder->encode(ReadFunc(src), (uint8_t*)s, n); - }; -}; - -namespace encoder { - void init(); - EncoderFilter::p get_encoder(const std::string& name); + //! Read into provided buffer. + virtual std::size_t read(char* buf, std::size_t buf_size) = 0; }; #endif -- cgit v1.2.3