From 83deeeafe2e81b42ff485e4582d4c1ac00872f50 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 28 Dec 2010 21:08:58 +0100 Subject: Added a simple interface to transcoding by specifying the 'decoder' and 'encoder' query arguments. --- music.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'music.cpp') 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 #include @@ -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()); + } } } -- cgit v1.2.3