From 89961817f408e921de2c1be6197e2b1ee0f5df98 Mon Sep 17 00:00:00 2001 From: Comment Date: Wed, 29 Jan 2014 23:58:55 +0000 Subject: NT audio framework --- NT/src/rendercontext.cpp | 171 ++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 90 deletions(-) (limited to 'NT/src/rendercontext.cpp') diff --git a/NT/src/rendercontext.cpp b/NT/src/rendercontext.cpp index 3309b16..a03723f 100644 --- a/NT/src/rendercontext.cpp +++ b/NT/src/rendercontext.cpp @@ -5,6 +5,64 @@ using namespace std; using Poco::Net::HTTPResponse; using Poco::Logger; +void Render_context::runTask() { + while (!isCancelled()) { + Session_task cmd; + mutex.lock(); + if (work_queue.size()){ + cmd=work_queue[0]; + work_queue.pop_front(); + graph.cancelled=false; + } + mutex.unlock(); + if(cmd.task==ANALYSE_AUDIO) { + state=ANALYSING_AUDIO; + graph.load_audio(cmd.body); + state=IDLE; + } + if(cmd.task==RENDER) { + state=RENDERING; + renders[cmd.uid]=Render_status(RENDERING); + if(graph.video_render(output_filename,output_framerate,start,stop)){ + state=IDLE; + if (graph.cancelled) renders[cmd.uid].status=CANCELLED; + else renders[cmd.uid].status=RENDER_READY; + } + else { + //an error occurred: TODO have to clean up allocated data. autoptr? + cerr<<"Rotor: render failed"<1){ - int w=toInt(t1[0]); - int h=toInt(t1[1]); - if (set_resolution(w,h)){ - logger.information("resolution set to "+t1[0]+"x"+t1[1]); - XML.addValue("status","resolution set to "+t1[0]+"x"+t1[1]); - status=HTTPResponse::HTTP_OK; - } - else { - logger.error("ERROR: invalid resolution request: "+t1[0]+"x"+t1[1]); - XML.addValue("error","invalid resolution request: "+t1[0]+"x"+t1[1]); - } + if (set_profile(command.body)){ + logger.information("profile set to "+command.body); + XML.addValue("status","profile set to "+command.body); + status=HTTPResponse::HTTP_OK; + } + else { + logger.error("ERROR: invalid profile request: "+command.body); + XML.addValue("error","invalid profile request: "+command.body); } } else { @@ -69,65 +122,6 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H } } } - if (command.commands[1]=="bitrate") { - if (command.method=="PUT") { - int b=toInt(command.body); - if (graph.set_bitrate(b)){ - logger.information("bitrate set to "+command.body); - XML.addValue("status","bitrate set to "+command.body); - status=HTTPResponse::HTTP_OK; - } - else { - logger.error("ERROR: Could not set bitrate set to "+command.body); - XML.addValue("error","Could not set bitrate set to "+command.body); - } - } - else { - status=HTTPResponse::HTTP_BAD_REQUEST; - logger.error("ERROR: Bad request"); - XML.addValue("error","Bad request"); - } - } - if (command.commands[1]=="fragmentation") { - if (command.method=="PUT") { - bool f=(toInt(command.body)!=0); - if (graph.set_fragmentation(f)){ - string fs=f?"on":"off"; - logger.information("MP4 fragmentation "+fs); - XML.addValue("status","MP4 fragmentation "+fs); - status=HTTPResponse::HTTP_OK; - } - else { - logger.error("ERROR: Could not set MP4 fragmentation"); - XML.addValue("error","Could not set MP4 fragmentation"); - } - } - else { - status=HTTPResponse::HTTP_BAD_REQUEST; - logger.error("ERROR: Bad request"); - XML.addValue("error","Bad request"); - } - } - if (command.commands[1]=="dash") { - if (command.method=="PUT") { - bool f=(toInt(command.body)!=0); - if (graph.set_dash(f)){ - string fs=f?"on":"off"; - logger.information("MPEG-DASH output "+fs); - XML.addValue("status","MPEG-DASH output "+fs); - status=HTTPResponse::HTTP_OK; - } - else { - logger.error("ERROR: Could not set MPEG-DASH output"); - XML.addValue("error","Could not set MPEG-DASH output"); - } - } - else { - status=HTTPResponse::HTTP_BAD_REQUEST; - logger.error("ERROR: Bad request"); - XML.addValue("error","Bad request"); - } - } if (command.commands[1]=="audio") { if (command.method=="PUT") { //get audio file location and initiate analysis if (command.body!="") { @@ -135,7 +129,6 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H graph.audio_filename=media_dir+command.body; //for now, store session variables in memory //check file exists Poco::File f=Poco::File(graph.audio_filename); if (f.exists()) { - //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? add_queue(Session_task(command.uid,ANALYSE_AUDIO)); status=HTTPResponse::HTTP_OK; logger.information("Audio analysis: "+command.body); @@ -162,6 +155,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H sprintf(c,"%02f",graph.progress); XML.addValue("progress",string(c)); } + /* else if (graph.audio_loaded) { //not sure about this-- should this state be retained? //can the data only be read once? @@ -175,6 +169,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H logger.error("ERROR: audio thumbnail requested but no audio loaded"); XML.addValue("error","No audio loaded"); } + */ } if (command.method=="DELETE") { if (state==IDLE) { @@ -216,29 +211,25 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H //before begining to load from xml if (state==IDLE) { //eventually not like this if (command.body!="") { - graph_filename=""; - graph_body=""; - if (Poco::File(graph_dir+command.body).exists()) { - graph_filename=graph_dir+command.body; - add_queue(Session_task(command.uid,LOAD_GRAPH)); + string graph_filename=graph_dir+command.body; + string graph_body=""; + if (Poco::File(graph_filename).exists()) {; + add_queue(Session_task(command.uid,LOAD_GRAPH,graph_filename)); status=HTTPResponse::HTTP_OK; logger.information("Loading graph from file: "+command.body); XML.addValue("status","Loading graph from file: "+command.body); //XML.addValue("render_id",command.uid); process ID? } else { - xmlIO xml; bool readable=true; - if (!xml.loadFromBuffer(command.body)){ - Json::Value root; // will contains the root value after parsing. - Json::Reader reader; - if ( !reader.parse( command.body, root ) ) - { - status=HTTPResponse::HTTP_BAD_REQUEST; - logger.error("ERROR: Could not load graph"); - XML.addValue("error","Could not load graph"); - readable=false; - } + Json::Value root; // will contains the root value after parsing. + Json::Reader reader; + if ( !reader.parse( command.body, root ) ) + { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Could not load graph"); + XML.addValue("error","Could not load graph"); + readable=false; } if (readable) { graph_body=command.body; -- cgit v1.2.3