diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-06 05:29:39 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-06 05:29:47 +0100 |
commit | 6f2fefdd9ff5f8561b3538efb5eb0765a9b4a141 (patch) | |
tree | de37cd2d500a777344b611321ac45bce66ad5c26 /decoder.h | |
parent | ffd8b5976af7e80425c7cf043528212528877b16 (diff) |
Replaced iostream-based decoder-encoder chain with direct chain.
Diffstat (limited to 'decoder.h')
-rw-r--r-- | decoder.h | 58 |
1 files changed, 17 insertions, 41 deletions
@@ -1,56 +1,32 @@ #ifndef DECODER_H #define DECODER_H -#include <boost/iostreams/concepts.hpp> -#include <boost/iostreams/operations.hpp> #include <boost/shared_ptr.hpp> -#include <boost/function.hpp> #include <string> -class DecoderBase { - friend class DecoderFilter; - - protected: - typedef boost::function<std::size_t (char*, std::size_t)> ReadFunc; - - virtual size_t decode(ReadFunc read, uint8_t *output, size_t output_size) = 0; - +//! Interface for classes outputting raw audio. +class RawAudioSource { public: - typedef boost::shared_ptr<DecoderBase> p; - virtual ~DecoderBase() {} -}; - -//! Input filter to hold a decoder in a filter chain. -class DecoderFilter : public boost::iostreams::multichar_input_filter { - private: - DecoderBase::p decoder; + typedef boost::shared_ptr<RawAudioSource> p; - //! 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<DecoderFilter> p; - DecoderFilter(DecoderBase::p decoder_); + //! Virtual destructor. + virtual ~RawAudioSource() {} - template<typename Source> - std::streamsize read(Source& src, char *s, std::streamsize n) { - return decoder->decode(ReadFunc<Source>(src), (uint8_t*)s, n); - } + //! Read into provided buffer. + virtual std::size_t read(char* buf, std::size_t buf_size) = 0; }; -namespace decoder { - void init(); - DecoderFilter::p get_decoder(const std::string& name); +//! Decoder base class. +class Decoder : public RawAudioSource { + public: + typedef boost::shared_ptr<Decoder> p; + + //! Initialize decoders. + static void init(); + + //! Construct and return requested decoder. + static p get(const std::string& name, const std::string& filename); }; #endif |