#include "rotord.h" /* ultimately- audio analysis request will spawn a task - there will be another call that will check progress audio analysis will be saved - to a file? into a db? for now - dump analysis into the http request architecture - running rendering process main vamp library segmenter, beat detector http://127.0.0.1:9000/vamp/qm-vamp-plugins/qm-segmenter/01.wav Running plugin: "qm-segmenter"... Using block size = 26460, step size = 8820 Plugin accepts 1 -> 1 channel(s) Sound file has 2 (will mix/augment if necessary) Output is: "segmentation" Done ./rotord: symbol lookup error: /usr/local/lib/vamp/qm-vamp-plugins.so: undefined symbol: clapack_dgetrf http://www.codeproject.com/Articles/252827/Learning-Poco-A-simple-HTTP-server next: load a movie and retreive frames save a movie how do we deal with frames in libavcodec - can we request a frame by number how do we deal with resolution */ RotorRequestHandler::RotorRequestHandler(const std::string& format): _format(format){ } void RotorRequestHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) { Timestamp now; std::string dt(DateTimeFormatter::format(now, _format)); response.setChunkedTransferEncoding(true); response.setContentType("text/html"); std::ostream& ostr = response.send(); ostr << "RotorServer powered by " "POCO C++ Libraries"; ostr << ""; ostr << "

"; ostr << dt; ostr << "

"; } AudioAnalyserHandler::AudioAnalyserHandler(const vampHost::Settings& _settings): settings(_settings){ } void AudioAnalyserHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) { response.setChunkedTransferEncoding(true); response.setContentType("text/html"); //string audioData=vampHost::runPlugin(); std::ostream& ostr = response.send(); ostr << "RotorServer powered by " "POCO C++ Libraries"; ostr << ""; ostr << "

"; vampHost::runPlugin("",settings.soname,settings.filtername, "",0, settings.inputFile, ostr,true); ostr << "

"; } RenderContextHandler::RenderContextHandler(const std::string _content,const HTTPServerResponse::HTTPStatus _status){ content=_content; status=_status; } void RenderContextHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) { response.setChunkedTransferEncoding(true); response.setContentType("text/html"); response.setStatus(status); std::ostream& ostr = response.send(); ostr << ""; ostr << content; } HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& request){ Application& app = Application::instance(); Poco::URI theuri=Poco::URI(request.getURI()); std::vector command; theuri.getPathSegments(command); app.logger().information(request.clientAddress().toString()+" "+request.getMethod()); string content=""; HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_OK; /* if (segments.size() == 0) { return new RotorRequestHandler(_format); } else if (segments[0]=="vamp"&&segments.size()>3) { // vamp/plugin/filter/filename // how do deal with error condition? //Settings(string _so="",string _filter="",string _id="",string _input=""); return new AudioAnalyserHandler(vampHost::Settings(segments[1],segments[2],segments[3])); //string audioData=runPlugin(string myname, string soname, string id, // string output, int outputNo, string wavname, // string outfilename, bool useFrames); return 0; } else if (segments[0]=="new") { // create a new render context return 0; } else { return 0; } */ //at this point we are within app //making a new contexthandler? //how will this have access to the thread that it refers to //how will messages be passed //we need to do testing etc here and //what does the handler do? //it gets passed the response- gets to set response code if (command.size()) { if (command[0]=="new") { string sID=idGen.create().toString(); printf("Rotor: starting thread\n"); manager.start(new Rotor::Render_context(sID)); content=""+sID+"\n"; } else if (command[0]=="list") { std::list < Poco::AutoPtr < Poco::Task > >::iterator it; it=manager.taskList().begin(); for (it=manager.taskList().begin();it !=manager.taskList().end();++it) { content+=""+(*it)->name()+"\n"; } } else { std::unordered_map::iterator iter = context.find(command[0]); if (iter!=context.end()) { //successfully located context if (command.size()==1) { //just invoking sID if (request.getMethod()=="DELETE") { } } else { } } else { status=HTTPResponse::HTTP_NOT_FOUND; content="Rotor: render context not found\n"; } } } else { content="Rotor: empty request"; } return new RenderContextHandler(content, status); } RotorServer::RotorServer(): _helpRequested(false) { } RotorServer::~RotorServer() { } void RotorServer::initialize(Application& self){ loadConfiguration(); ServerApplication::initialize(self); } void RotorServer::uninitialize(){ ServerApplication::uninitialize(); } void RotorServer::defineOptions(OptionSet& options) { ServerApplication::defineOptions(options); options.addOption( Option("help", "h", "display argument help information") .required(false) .repeatable(false) .callback(OptionCallback(this, &RotorServer::handleHelp) ) ); } void RotorServer::handleHelp(const std::string& name, const std::string& value){ HelpFormatter helpFormatter(options()); helpFormatter.setCommand(commandName()); helpFormatter.setUsage("OPTIONS"); helpFormatter.setHeader( "Rotor"); helpFormatter.format(std::cout); stopOptionsProcessing(); _helpRequested = true; } int RotorServer::main(const std::vector& args){ if (!_helpRequested) { unsigned short port = (unsigned short) config().getInt("port", 9980); std::string format(config().getString("format", DateTimeFormat::SORTABLE_FORMAT)); ServerSocket svs(port); HTTPServer srv(new RotorRequestHandlerFactory(),svs, new HTTPServerParams); srv.start(); waitForTerminationRequest(); srv.stop(); } return Application::EXIT_OK; }