diff options
| -rw-r--r-- | rotord/rotor.cpp | 127 | ||||
| -rwxr-xr-x | rotord/rotor.h | 21 |
2 files changed, 96 insertions, 52 deletions
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 360b75e..f9c39b3 100644 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -19,21 +19,27 @@ void Render_context::runTask() { work_queue.pop_front(); } mutex.unlock(); - if (cmd==ANALYSE_AUDIO) { - state=ANALYSING_AUDIO; - vector<Base_audio_processor*> processors; - processors.push_back(audio_thumb); - vector<Node*> analysers=graph.find_nodes("audio_analysis"); - for (auto a: analysers) { - processors.push_back(a); - } - if (load_audio(audio_filename,processors)) { - state=AUDIO_READY; - } - else { - //an error occurred: TODO have to clean up allocated data. autoptr? - state=IDLE; - } + switch(cmd) { + case ANALYSE_AUDIO: + state=ANALYSING_AUDIO; + vector<Base_audio_processor*> processors; + processors.push_back(audio_thumb); + vector<Node*> analysers=graph.find_nodes("audio_analysis"); + for (auto a: analysers) { + processors.push_back(a); + } + if (load_audio(audio_filename,processors)) { + state=AUDIO_READY; + } + else { + //an error occurred: TODO have to clean up allocated data. autoptr? + state=IDLE; + } + break; + case RENDER: + state=RENDERING; + /// + break; } sleep(100); } @@ -75,27 +81,28 @@ Command_response Render_context::session_command(const std::vector<std::string>& response.status=HTTPResponse::HTTP_BAD_REQUEST; if (command[2]=="audio") { if (command[0]=="PUT") { //get audio file location and initiate analysis - if (command.size()>2) { - if (state==IDLE) { - //check file exists - Poco::File f=Poco::File(command[3]); - if (f.exists()) { - //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? - audio_filename=command[3]; //for now, store session variables in memory - add_queue(ANALYSE_AUDIO); - response.description="<status context='"+command[1]+"'>Starting audio analysis: "+command[3]+"</status>\n"; - } - else { - response.status=HTTPResponse::HTTP_NOT_FOUND; - response.description="<status context='"+command[1]+"'>File "+command[3]+" not found</status>\n"; - } + if (command.size()>2) { + if (state==IDLE) { + //check file exists + Poco::File f=Poco::File(command[3]); + if (f.exists()) { + //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? + audio_filename=command[3]; //for now, store session variables in memory + add_queue(ANALYSE_AUDIO); + response.status=HTTPResponse::HTTP_OK; + response.description="<status context='"+command[1]+"'>Starting audio analysis: "+command[3]+"</status>\n"; + } + else { + response.status=HTTPResponse::HTTP_NOT_FOUND; + response.description="<status context='"+command[1]+"'>File "+command[3]+" not found</status>\n"; + } - } - else { - response.status=HTTPResponse::HTTP_BAD_REQUEST; - response.description="<status context='"+command[1]+"'>Rotor: session busy</status>\n"; - } - } + } + else { + response.status=HTTPResponse::HTTP_BAD_REQUEST; + response.description="<status context='"+command[1]+"'>Rotor: session busy</status>\n"; + } + } } if (command[0]=="GET") { if (state==ANALYSING_AUDIO) { @@ -209,20 +216,20 @@ Command_response Render_context::session_command(const std::vector<std::string>& if (command.size()>2) { if (state==IDLE) { //check file exists - Poco::File f=Poco::File(command[3]); - if (f.exists()) { - //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? - //DUMMY RESPONSE - response.description="<status context='"+command[1]+"'>DUMMY RESPONSE Starting video analysis: "+command[3]+"</status>\n"; - } + Poco::File f=Poco::File(command[3]); + if (f.exists()) { + //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? + //DUMMY RESPONSE + response.description="<status context='"+command[1]+"'>DUMMY RESPONSE Starting video analysis: "+command[3]+"</status>\n"; + } else { - response.status=HTTPResponse::HTTP_NOT_FOUND; - response.description="<status context='"+command[1]+"'>File "+command[3]+" not found</status>\n"; - } + response.status=HTTPResponse::HTTP_NOT_FOUND; + response.description="<status context='"+command[1]+"'>File "+command[3]+" not found</status>\n"; + } } else { - response.status=HTTPResponse::HTTP_BAD_REQUEST; - response.description="<status context='"+command[1]+"'>Rotor: session busy</status>\n"; + response.status=HTTPResponse::HTTP_BAD_REQUEST; + response.description="<status context='"+command[1]+"'>Rotor: session busy</status>\n"; } } } @@ -241,10 +248,22 @@ Command_response Render_context::session_command(const std::vector<std::string>& response.description+="<progress>25.2</progress>\n"; } if (command[0]=="PUT") { - //DUMMY RESPONSE - //SHOULD CHECK REQUIREMENTS - response.status=HTTPResponse::HTTP_OK; - response.description="<status context='"+command[1]+"'>DUMMY RESPONSE Rotor: starting render</status>\n"; + if (command.size()>2) { + if (state==IDLE) { + output_filename=command[3]; //for now, store session variables in memory + add_queue(RENDER); + response.status=HTTPResponse::HTTP_OK; + response.description="<status context='"+command[1]+"'>Starting render: "+command[3]+"</status>\n"; + } + else { + response.status=HTTPResponse::HTTP_BAD_REQUEST; + response.description="<status context='"+command[1]+"'>Rotor: session busy</status>\n"; + } + } + else { + response.status=HTTPResponse::HTTP_BAD_REQUEST; + response.description="<status context='"+command[1]+"'>Rotor: no output file specified</status>\n"; + } } if (command[0]=="DELETE") { //DUMMY RESPONSE @@ -371,9 +390,9 @@ bool Render_context::load_audio(const string &filename,vector<Base_audio_process //now we can pass the data to the processor(s) for (auto p: processors) { - sample_processed=p->process_frame(frame->data[0],frame->nb_samples); + p->process_frame(frame->data[0],frame->nb_samples); } - + sample_processed+=frame->nb_samples; mutex.lock(); progress=((double)sample_processed)/samples; mutex.unlock(); @@ -480,6 +499,7 @@ Node_factory::Node_factory(){ add_type("divide",new Signal_divide()); add_type("==",new Is_new_integer()); add_type("signal_output",new Signal_output()); + add_type("video_output",new Video_output()); } bool Audio_thumbnailer::init(int _channels,int _bits,int _samples,int _rate) { //base_audio_processor::init(_channels,_bits,_samples); @@ -576,4 +596,7 @@ void Audio_analysis::print_features(){ for (auto i: analyser.features) { cerr<<i.second<<" "<<i.first<<endl; } +} +bool Video_output::render(const float duration, const float framerate,string &filename){ + //render out the network }
\ No newline at end of file diff --git a/rotord/rotor.h b/rotord/rotor.h index 36ef0aa..699aa8a 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -326,6 +326,15 @@ namespace Rotor { else return 0.0f; } }; + class Video_output: public Image_node { + public: + Video_output(){}; + Video_output(map<string,string> &settings) { + base_settings(settings); + }; + Video_output* clone(map<string,string> &_settings) { return new Video_output(_settings);}; + bool render(const float duration, const float framerate,string &filename); + }; //------------------------------------------------------------------- class Node_factory{ public: @@ -374,6 +383,18 @@ namespace Rotor { } else return false; } + bool video_render(const float _fr,string &filename) { + //things to manage: + //audio location is known by render context + //video_output can generate frames + //where do these come together? + if (_fr>.001) framerate=_fr; + if (find_node("video_output")) { + Video_output *video_output=dynamic_cast<Video_output*>(find_node("video_output")); + return video_output->render(duration,framerate,filename,); + } + else return false; + } int load(Poco::UUID uid); bool load(string &graph_filename); UUID save(); //save to DB, returns UUID of saved graph |
