summaryrefslogtreecommitdiff
path: root/decoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.h')
-rw-r--r--decoder.h58
1 files changed, 17 insertions, 41 deletions
diff --git a/decoder.h b/decoder.h
index d58dcf1..a1d857f 100644
--- a/decoder.h
+++ b/decoder.h
@@ -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