diff options
Diffstat (limited to 'encoder.h')
-rw-r--r-- | encoder.h | 56 |
1 files changed, 13 insertions, 43 deletions
@@ -1,57 +1,27 @@ #ifndef ENCODER_H #define ENCODER_H -#include <boost/iostreams/concepts.hpp> -#include <boost/iostreams/operations.hpp> +#include "decoder.h" + #include <boost/shared_ptr.hpp> -#include <boost/function.hpp> -#include <iostream> #include <string> -class EncoderBase { - friend class EncoderFilter; - - protected: - typedef boost::function<std::size_t (char*, std::size_t)> ReadFunc; +class Encoder { + public: + typedef boost::shared_ptr<Encoder> p; - virtual size_t encode(ReadFunc read, uint8_t *output, size_t output_size) = 0; + //! Virtual destructor. + virtual ~Encoder() {} - public: - typedef boost::shared_ptr<EncoderBase> 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<class T> - 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<EncoderFilter> p; - EncoderFilter(EncoderBase::p encoder_); + //! Construct and return requested encoder. + static p get(const std::string& name, RawAudioSource::p source); - template<typename Source> - std::streamsize read(Source& src, char *s, std::streamsize n) { - return encoder->encode(ReadFunc<Source>(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 |