diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 21:08:58 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 21:08:58 +0100 |
commit | 83deeeafe2e81b42ff485e4582d4c1ac00872f50 (patch) | |
tree | 324d2e8bf8ae5cf01a1c56b3496f0ecf29749928 /music.cpp | |
parent | 9bcf29e9ce11bbc6a421b39eded8f4eb7d94a912 (diff) |
Added a simple interface to transcoding by specifying the 'decoder' and 'encoder' query arguments.
Diffstat (limited to 'music.cpp')
-rw-r--r-- | music.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -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()); + } } } |