From 8e6038f799b50986871325f28b4f807312502681 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 10 Apr 2013 18:33:57 +0100 Subject: making render path --- rotord/rotor.cpp | 127 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 52 deletions(-) (limited to 'rotord/rotor.cpp') 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 processors; - processors.push_back(audio_thumb); - vector 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 processors; + processors.push_back(audio_thumb); + vector 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& 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="Starting audio analysis: "+command[3]+"\n"; - } - else { - response.status=HTTPResponse::HTTP_NOT_FOUND; - response.description="File "+command[3]+" not found\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="Starting audio analysis: "+command[3]+"\n"; + } + else { + response.status=HTTPResponse::HTTP_NOT_FOUND; + response.description="File "+command[3]+" not found\n"; + } - } - else { - response.status=HTTPResponse::HTTP_BAD_REQUEST; - response.description="Rotor: session busy\n"; - } - } + } + else { + response.status=HTTPResponse::HTTP_BAD_REQUEST; + response.description="Rotor: session busy\n"; + } + } } if (command[0]=="GET") { if (state==ANALYSING_AUDIO) { @@ -209,20 +216,20 @@ Command_response Render_context::session_command(const std::vector& 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="DUMMY RESPONSE Starting video analysis: "+command[3]+"\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="DUMMY RESPONSE Starting video analysis: "+command[3]+"\n"; + } else { - response.status=HTTPResponse::HTTP_NOT_FOUND; - response.description="File "+command[3]+" not found\n"; - } + response.status=HTTPResponse::HTTP_NOT_FOUND; + response.description="File "+command[3]+" not found\n"; + } } else { - response.status=HTTPResponse::HTTP_BAD_REQUEST; - response.description="Rotor: session busy\n"; + response.status=HTTPResponse::HTTP_BAD_REQUEST; + response.description="Rotor: session busy\n"; } } } @@ -241,10 +248,22 @@ Command_response Render_context::session_command(const std::vector& response.description+="25.2\n"; } if (command[0]=="PUT") { - //DUMMY RESPONSE - //SHOULD CHECK REQUIREMENTS - response.status=HTTPResponse::HTTP_OK; - response.description="DUMMY RESPONSE Rotor: starting render\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="Starting render: "+command[3]+"\n"; + } + else { + response.status=HTTPResponse::HTTP_BAD_REQUEST; + response.description="Rotor: session busy\n"; + } + } + else { + response.status=HTTPResponse::HTTP_BAD_REQUEST; + response.description="Rotor: no output file specified\n"; + } } if (command[0]=="DELETE") { //DUMMY RESPONSE @@ -371,9 +390,9 @@ bool Render_context::load_audio(const string &filename,vectorprocess_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<