diff options
| -rw-r--r-- | rotord/src/graph.cpp | 64 | ||||
| -rw-r--r-- | rotord/src/graph.h | 54 | ||||
| -rw-r--r-- | rotord/src/rendercontext.cpp | 64 | ||||
| -rw-r--r-- | rotord/src/rendercontext.h | 3 | ||||
| -rwxr-xr-x | rotord/src/rotor.h | 43 | ||||
| -rwxr-xr-x | rotord/src/rotord.cpp | 8 |
6 files changed, 123 insertions, 113 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp index 7ca8879..e6c0e3f 100644 --- a/rotord/src/graph.cpp +++ b/rotord/src/graph.cpp @@ -1,4 +1,4 @@ -#include "rotor.h" +#include "graph.h" using namespace Rotor; using Poco::Logger; @@ -507,4 +507,64 @@ bool Graph::parseXml(string media_path){ } loaded=true; return true; -}
\ No newline at end of file +} +bool Graph::load_audio(const string &filename,vector<Audio_processor*> processors){ + Logger& logger = Logger::get("Rotor"); + logger.information("Analysing "+filename); + + libav::audioloader loader; + loader.setup(filename); + + duration=((float)loader.formatContext->duration)/AV_TIME_BASE; + + int rate = loader.codecContext->sample_rate; + int samples = ((loader.formatContext->duration + 5000)*rate)/AV_TIME_BASE; //why 5000 more? + int channels= loader.codecContext->channels; + int bits = 16; //???why can't we read this loader.codecContext->bits_per_raw_sample; + + for (auto p: processors) { + if(!p->init(channels,bits,samples,rate) ){ + logger.error("ERROR: Audio plugin failed to initialse"); + return false; + } + } + + AVFrame* frame=loader.get_frame(); + int sample_processed=0; + + while (frame) + { + //now we can pass the data to the processor(s) + for (auto p: processors) { + p->process_frame(frame->data[0],frame->nb_samples); + } + sample_processed+=frame->nb_samples; + //mutex.lock(); + progress=((float)sample_processed)/samples; //atomic on 64 bit? + //mutex.unlock(); + + frame=loader.get_frame(); + } + + loader.close(); + + for (auto p: processors) { + p->cleanup(); + p->print_summary(); + } + + logger.information("Finished audio analysis"); + return true; +} +bool Graph::load_video(const string &nodeID,const string &filename){ + //this is a good standard example of how to find + //a node of a specific type by ID and do something + if (nodes.find(nodeID)!=nodes.end()){ + if (nodes[nodeID]->type=="video_loader") { + if (((Video_loader*)nodes[nodeID])->load(filename)) { + return true; + } + } + } + return false; +} diff --git a/rotord/src/graph.h b/rotord/src/graph.h new file mode 100644 index 0000000..1c76937 --- /dev/null +++ b/rotord/src/graph.h @@ -0,0 +1,54 @@ +#ifndef GRAPH_H +#define GRAPH_H + +#include "rotor.h" + +namespace Rotor { + class Graph{ + public: + Graph(){duration=20.0f;loaded = false;outW=640;outH=360;}; + Graph(const string& _uid,const string& _desc){ + init(_uid,_desc); + audio_loaded=false; + }; + void init(const string& _uid,const string& _desc){ + uid=_uid; + description=_desc; + duration=20.0f; + framerate=25.0f; + cancelled=false; + }; + string uid; //every version of a graph has a UUID, no particular need to actually read its data(?) + //?? is it faster than using strings?? + string description; + std::unordered_map<string,Node*> nodes; + vector<Node*> find_nodes(const string &type); //could be a way of finding a set based on capabilities? + Node* find_node(const string &type); + bool signal_render(string &signal_xml,const float framerate); + bool video_render(const string &output_filename,const float framerate,float& progress); + bool load(string data,string media_path); + bool loadFile(string &filename,string media_path); + bool parseXml(string media_path); + bool parseJson(string &data,string &media_path); + bool set_resolution(int w,int h); + bool preview(xmlIO &XML,string &node,string &format,int frame,int w,int h); + bool check_audio(string audio,string path); + bool print_features(xmlIO &XML,string &node); + bool load_audio(const string &filename,vector<Audio_processor*> processors); + bool load_video(const string &nodeID,const string &filename);//can be performance or clip + bool loaded; + float duration; + float framerate; + const string toString(); + xmlIO xml; + bool audio_loaded; + string audio_filename; + bool cancelled; + float progress; + private: + Node_factory factory; + int outW,outH; + + }; +} +#endif diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp index cebe003..1cc440a 100644 --- a/rotord/src/rendercontext.cpp +++ b/rotord/src/rendercontext.cpp @@ -23,7 +23,7 @@ void Render_context::runTask() { processors.push_back(dynamic_cast<Audio_processor*>(a.second)); } } - if (load_audio(graph.audio_filename,processors)) { + if (graph.load_audio(graph.audio_filename,processors)) { graph.audio_loaded=true; state=IDLE; } @@ -272,7 +272,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H //check file exists Poco::File f=Poco::File(video_filename); if (f.exists()) { - if (load_video(command.commands[2],video_filename)) { + if (graph.load_video(command.commands[2],video_filename)) { //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? //DUMMY RESPONSE status=HTTPResponse::HTTP_OK; @@ -439,63 +439,3 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H } } -bool Render_context::load_audio(const string &filename,vector<Audio_processor*> processors){ - Logger& logger = Logger::get("Rotor"); - logger.information("Analysing "+filename); - - libav::audioloader loader; - loader.setup(filename); - - graph.duration=((float)loader.formatContext->duration)/AV_TIME_BASE; - - int rate = loader.codecContext->sample_rate; - int samples = ((loader.formatContext->duration + 5000)*rate)/AV_TIME_BASE; //why 5000 more? - int channels= loader.codecContext->channels; - int bits = 16; //???why can't we read this loader.codecContext->bits_per_raw_sample; - - for (auto p: processors) { - if(!p->init(channels,bits,samples,rate) ){ - logger.error("ERROR: Audio plugin failed to initialse"); - return false; - } - } - - AVFrame* frame=loader.get_frame(); - int sample_processed=0; - - while (frame) - { - //now we can pass the data to the processor(s) - for (auto p: processors) { - p->process_frame(frame->data[0],frame->nb_samples); - } - sample_processed+=frame->nb_samples; - //mutex.lock(); - progress=((float)sample_processed)/samples; //atomic on 64 bit? - //mutex.unlock(); - - frame=loader.get_frame(); - } - - loader.close(); - - for (auto p: processors) { - p->cleanup(); - p->print_summary(); - } - - logger.information("Finished audio analysis"); - return true; -} -bool Render_context::load_video(const string &nodeID,const string &filename){ - //this is a good standard example of how to find - //a node of a specific type by ID and do something - if (graph.nodes.find(nodeID)!=graph.nodes.end()){ - if (graph.nodes[nodeID]->type=="video_loader") { - if (((Video_loader*)graph.nodes[nodeID])->load(filename)) { - return true; - } - } - } - return false; -} diff --git a/rotord/src/rendercontext.h b/rotord/src/rendercontext.h index 2d26ec2..bd37c53 100644 --- a/rotord/src/rendercontext.h +++ b/rotord/src/rendercontext.h @@ -5,6 +5,7 @@ #include "Poco/StringTokenizer.h" #include "rotor.h" +#include "graph.h" namespace Rotor { #define IDLE 0 @@ -69,8 +70,6 @@ namespace Rotor { void session_command(const Session_command& command,xmlIO& XML,Poco::Net::HTTPResponse::HTTPStatus& status); void cancel(); //interrupt locking process int make_preview(int nodeID, float time); //starts a frame preview - returns status code - how to retrieve? - bool load_audio(const string &filename,vector<Audio_processor*> processors); - bool load_video(const string &nodeID,const string &filename);//can be performance or clip Render_status get_render_status(const string &uid){ //cerr<<"render status requested: "<<uid<<" status: "<<renders[uid].status<<endl; diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index dea3fa0..3eb3fe6 100755 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -1111,49 +1111,6 @@ namespace Rotor { private: unordered_map<string,Node*> type_map; }; - class Graph{ - public: - Graph(){duration=20.0f;loaded = false;outW=640;outH=360;}; - Graph(const string& _uid,const string& _desc){ - init(_uid,_desc); - audio_loaded=false; - }; - void init(const string& _uid,const string& _desc){ - uid=_uid; - description=_desc; - duration=20.0f; - framerate=25.0f; - cancelled=false; - }; - string uid; //every version of a graph has a UUID, no particular need to actually read its data(?) - //?? is it faster than using strings?? - string description; - std::unordered_map<string,Node*> nodes; - vector<Node*> find_nodes(const string &type); //could be a way of finding a set based on capabilities? - Node* find_node(const string &type); - bool signal_render(string &signal_xml,const float framerate); - bool video_render(const string &output_filename,const float framerate,float& progress); - bool load(string data,string media_path); - bool loadFile(string &filename,string media_path); - bool parseXml(string media_path); - bool parseJson(string &data,string &media_path); - bool set_resolution(int w,int h); - bool preview(xmlIO &XML,string &node,string &format,int frame,int w,int h); - bool check_audio(string audio,string path); - bool print_features(xmlIO &XML,string &node); - bool loaded; - float duration; - float framerate; - const string toString(); - xmlIO xml; - bool audio_loaded; - string audio_filename; - bool cancelled; - private: - Node_factory factory; - int outW,outH; - - }; class Audio_thumbnailer: public Audio_processor { public: Audio_thumbnailer(){ diff --git a/rotord/src/rotord.cpp b/rotord/src/rotord.cpp index 57318ed..51c21ab 100755 --- a/rotord/src/rotord.cpp +++ b/rotord/src/rotord.cpp @@ -147,16 +147,16 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS XML.addAttribute("render","progress",status.progress,i); break; case RENDER_READY: - XML.addAttribute("render","status","render complete",i); + XML.addAttribute("render","status","complete",i); break; case FAILED: - XML.addAttribute("render","status","render failed",i); + XML.addAttribute("render","status","failed",i); break; case NOT_FOUND: - XML.addAttribute("render","status","error - not found",i); + XML.addAttribute("render","error","not found",i); break; case CANCELLED: - XML.addAttribute("render","status","render cancelled",i); + XML.addAttribute("render","status","cancelled",i); break; } context_found=true; |
