#ifndef RENDERCONTEXT_H #define RENDERCONTEXT_H /*------------------------ Render context manages a rotor graph as a web service, and renders out linear movies TJR Jan 2014 -------------------------*/ #include "Poco/Task.h" #include "Poco/StringTokenizer.h" #include "rotor.h" #include "graph.h" // // When rendering, where do duration etc come from? // // It should come from: // a) a specified duration // b) the duration of the song being worked on // c) a default duration // // graph.get_duration() namespace Rotor { #define IDLE 0 #define ANALYSING_AUDIO 1 #define AUDIO_READY 2 #define CREATING_PREVIEW 3 #define PREVIEW_READY 4 #define RENDERING 5 #define RENDER_READY 6 #define FAILED 7 #define NOT_FOUND 8 #define CANCELLED 9 #define LOADING_GRAPH 10 #define ANALYSE_AUDIO 1 #define PREVIEW 2 #define RENDER 3 #define LOAD_GRAPH_FILE 4 #define LOAD_GRAPH_STRING 5 class Session_command { public: Session_command(){body="";}; string uid,method,id,body; vector commands; }; class Session_task { public: Session_task(const string &_uid="",int _task=0):uid(_uid),task(_task) {}; string uid; int task; string message; }; class Render_status { public: Render_status():status(0),progress(0.0){}; Render_status(int _status):status(_status),progress(0.0){}; int status; double progress; }; class Render_settings { public: Render_settings(int w=640,int h=360):width(w),height(h){}; int width,height; }; class Render_context: public Poco::Task { public: Render_context(const std::string& _id,const std::string& _media_dir=""): Task(_id) { id=_id; media_dir=_media_dir; graph.init(id); //set up log AutoPtr splitterChannel(new SplitterChannel()); AutoPtr consoleChannel(new ConsoleChannel()); AutoPtr fileChannel(new FileChannel("Rotord_"+id+".log")); splitterChannel->addChannel(consoleChannel); splitterChannel->addChannel(fileChannel); AutoPtr formatter(new PatternFormatter("%d-%m-%Y %H:%M:%S %s: %t")); AutoPtr formattingChannel(new FormattingChannel(formatter, splitterChannel)); Logger& logger = Logger::create(id, formattingChannel, Message::PRIO_TRACE); //load profiles logger.information("started thread"); } ~Render_context(){ Logger& logger = Logger::get(id); cancel(); logger.information("stopped thread"); } void runTask(); void add_queue(Session_task item); bool set_profile(const std::string& _profile){ if (profiles.find(_profile)==profiles.end()) return false; profile=_profile; return true; } void session_command(const Session_command& command,xmlIO& XML,Poco::Net::HTTPResponse::HTTPStatus& status); Render_status get_render_status(const string &uid){ if (renders.find(uid)!=renders.end()){ if (renders[uid].status==RENDERING){ renders[uid].progress=graph.progress; } return renders[uid]; } return Render_status(NOT_FOUND); }; std::string text_render(std::string node_id=""); bool video_render(std::string output_filename,std::string node_id=""); Graph graph; private: bool cancelled; double progress; int state; std::string id; std::unordered_map renders; std::unordered_map profiles; std::string profile; std::string media_dir; std::deque work_queue; Poco::Mutex mutex; }; }; #endif //RENDERCONTEXT_H