summaryrefslogtreecommitdiff
path: root/music.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-12-28 21:08:58 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-12-28 21:08:58 +0100
commit83deeeafe2e81b42ff485e4582d4c1ac00872f50 (patch)
tree324d2e8bf8ae5cf01a1c56b3496f0ecf29749928 /music.cpp
parent9bcf29e9ce11bbc6a421b39eded8f4eb7d94a912 (diff)
Added a simple interface to transcoding by specifying the 'decoder' and 'encoder' query arguments.
Diffstat (limited to 'music.cpp')
-rw-r--r--music.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/music.cpp b/music.cpp
index b36ba7b..8321b38 100644
--- a/music.cpp
+++ b/music.cpp
@@ -1,4 +1,7 @@
#include "music.h"
+#include "decoder.h"
+#include "encoder.h"
+#include "transcode.h"
#include <boost/format.hpp>
#include <boost/algorithm/string/predicate.hpp>
@@ -8,7 +11,10 @@ namespace music {
MusicDirectory *root_directory = NULL;
-void init(const fs::path root) {
+void init(std::string root) {
+ // remove trailing slash
+ if(boost::algorithm::ends_with(root, "/"))
+ root = root.substr(0, root.size()-1);
root_directory = new MusicDirectory(root);
}
@@ -41,7 +47,7 @@ MusicListing *find(std::string path) {
}; // namespace music
-void MusicDirectory::render(HTTPResponse& res) {
+void MusicDirectory::render(HTTPRequest& req, HTTPResponse& res) {
res.add_header("content-type", "text/html");
for(MusicDirectories::iterator it = directories.begin(); it != directories.end(); it++) {
@@ -75,7 +81,7 @@ MusicDirectory::MusicDirectory(const fs::path root) {
}
}
-void MusicTrack::render(HTTPResponse& res) {
+void MusicTrack::render(HTTPRequest& req, HTTPResponse& res) {
res.add_header("content-type", "application/octet-stream");
fs::ifstream is(path, std::ios::binary | std::ios::in);
@@ -83,9 +89,18 @@ void MusicTrack::render(HTTPResponse& res) {
res.add_header("content-length", boost::str(boost::format("%d") % is.tellg()));
is.seekg(0, std::ios::beg);
- char data[0x1000];
- while(is.good()) {
- is.read(data, 0x1000);
- res.write(data, is.gcount());
+ if(req.query.find("decoder") != req.query.end() && req.query.find("encoder") != req.query.end()) {
+ DecoderBase *d = decoder::get_decoder(req.query["decoder"]);
+ EncoderBase *e = encoder::get_encoder(req.query["encoder"]);
+ Transcoder t(is, res, *d, *e);
+ t.run();
+ delete d;
+ delete e;
+ } else {
+ char data[0x1000];
+ while(is.good()) {
+ is.read(data, 0x1000);
+ res.write(data, is.gcount());
+ }
}
}