summaryrefslogtreecommitdiff
path: root/NT/src/rendercontext.cpp
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2014-01-29 23:58:55 +0000
committerComment <tim@gray.(none)>2014-01-29 23:58:55 +0000
commit89961817f408e921de2c1be6197e2b1ee0f5df98 (patch)
tree983f41082fbe2877d9eed913d07784f157d5ced4 /NT/src/rendercontext.cpp
parent90a237397507bda5a8194b9a7c9982454cc79718 (diff)
NT audio framework
Diffstat (limited to 'NT/src/rendercontext.cpp')
-rw-r--r--NT/src/rendercontext.cpp171
1 files changed, 81 insertions, 90 deletions
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"<<endl;
+ state=IDLE;
+ renders[cmd.uid].status=FAILED;
+ }
+ }
+ if(cmd.task==LOAD_GRAPH) {
+ state=LOADING_GRAPH;
+ if (graph_filename!="") {
+ if (!graph.loadFile(graph_filename,media_dir)){
+ cerr<<"Rotor: failed to load graph from "<<graph_filename<<endl;
+ }
+ }
+ else if (graph_body!="") {
+ if (!graph.load(graph_body,media_dir)) {
+ cerr<<"Rotor: failed to load graph from body request"<<endl;
+ }
+ }
+ if (graph.loaded){
+ if (graph.audio_loaded) {
+ add_queue(Session_task(cmd.uid,ANALYSE_AUDIO));
+ cerr<<"Rotor: starting audio analysis for graph"<<endl;
+ }
+ }
+ state=IDLE;
+ }
+ sleep(100);
+ }
+}
+void Render_context::add_queue(Session_task item) {
+ mutex.lock();
+ work_queue.push_back(item);
+ mutex.unlock();
+}
string Render_context::text_render(string node_id){
Logger& logger = Logger::get(id);
Node* p;
@@ -44,23 +102,18 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H
Logger& logger = Logger::get(id);
status=HTTPResponse::HTTP_BAD_REQUEST; //error by default
- if (command.commands[1]=="resolution") {
+ if (command.commands[1]=="profile") {
if (command.method=="PUT") {
if (command.body!="") {
if (state!=RENDERING) {
- Poco::StringTokenizer t1(command.body,",");
- if (t1.count()>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;