summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--decoder.cpp19
-rw-r--r--decoder.h10
-rw-r--r--decoders/mpg123_decoder.cpp2
-rw-r--r--encoder.cpp18
-rw-r--r--encoder.h10
-rw-r--r--main.cpp4
6 files changed, 61 insertions, 2 deletions
diff --git a/decoder.cpp b/decoder.cpp
new file mode 100644
index 0000000..e80c714
--- /dev/null
+++ b/decoder.cpp
@@ -0,0 +1,19 @@
+#include "decoder.h"
+#include "decoders/mpg123_decoder.h"
+
+#include <map>
+
+namespace decoder {
+ typedef boost::function<DecoderBase*()> DecoderFactory;
+ std::map<std::string, DecoderFactory> decoder_factories;
+
+void init() {
+ mpg123_init(); // initialize the mpg123 library
+ decoder_factories["mpg123"] = boost::factory<DecoderMpg123*>();
+}
+
+DecoderBase *get_decoder(const std::string& name) {
+ return decoder_factories[name]();
+}
+
+};
diff --git a/decoder.h b/decoder.h
index 7e76088..b4dcdb6 100644
--- a/decoder.h
+++ b/decoder.h
@@ -2,10 +2,20 @@
#define DECODER_H
#include <boost/cstdint.hpp>
+#include <boost/function.hpp>
+#include <boost/functional/factory.hpp>
+#include <boost/functional/value_factory.hpp>
+
+#include <string>
class DecoderBase {
public:
virtual size_t decode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size) = 0;
};
+namespace decoder {
+ void init();
+ DecoderBase *get_decoder(const std::string& name);
+};
+
#endif
diff --git a/decoders/mpg123_decoder.cpp b/decoders/mpg123_decoder.cpp
index 41aef40..0c2629f 100644
--- a/decoders/mpg123_decoder.cpp
+++ b/decoders/mpg123_decoder.cpp
@@ -6,8 +6,6 @@
#include <stdexcept>
DecoderMpg123::DecoderMpg123() {
- mpg123_init();
-
int error;
handle = mpg123_new("generic", &error);
if(error) {
diff --git a/encoder.cpp b/encoder.cpp
new file mode 100644
index 0000000..9bea59b
--- /dev/null
+++ b/encoder.cpp
@@ -0,0 +1,18 @@
+#include "encoder.h"
+#include "encoders/lame_encoder.h"
+
+#include <map>
+
+namespace encoder {
+ typedef boost::function<EncoderBase*()> EncoderFactory;
+ std::map<std::string, EncoderFactory> encoder_factories;
+
+void init() {
+ encoder_factories["lame"] = boost::factory<EncoderLame*>();
+}
+
+EncoderBase *get_encoder(const std::string& name) {
+ return encoder_factories[name]();
+}
+
+};
diff --git a/encoder.h b/encoder.h
index a9a0e5c..9949b52 100644
--- a/encoder.h
+++ b/encoder.h
@@ -2,6 +2,11 @@
#define ENCODER_H
#include <boost/cstdint.hpp>
+#include <boost/function.hpp>
+#include <boost/functional/factory.hpp>
+#include <boost/functional/value_factory.hpp>
+
+#include <string>
class EncoderBase {
public:
@@ -9,4 +14,9 @@ class EncoderBase {
virtual size_t flush(uint8_t *output, size_t output_size) = 0;
};
+namespace encoder {
+ void init();
+ EncoderBase *get_encoder(const std::string& name);
+};
+
#endif
diff --git a/main.cpp b/main.cpp
index 3827607..2c0ada7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,6 @@
#include "music.h"
+#include "decoder.h"
+#include "encoder.h"
#include "httpd.h"
#include <iostream>
@@ -9,6 +11,8 @@
int main(int argc, char **argv) {
try {
music::init(argv[1]);
+ decoder::init();
+ encoder::init();
boost::asio::io_service io_service;
HTTPServer httpd(io_service);