summaryrefslogtreecommitdiff
path: root/rotord
diff options
context:
space:
mode:
Diffstat (limited to 'rotord')
-rw-r--r--rotord/rendercontext.cpp286
-rwxr-xr-xrotord/rotor.cpp5
-rwxr-xr-xrotord/rotord.cpp5
-rwxr-xr-xrotord/rotord.h4
4 files changed, 34 insertions, 266 deletions
diff --git a/rotord/rendercontext.cpp b/rotord/rendercontext.cpp
index 935ec08..c1ddf53 100644
--- a/rotord/rendercontext.cpp
+++ b/rotord/rendercontext.cpp
@@ -51,7 +51,7 @@ void Render_context::add_queue(int item) {
void Render_context::session_command(const std::vector<std::string>& command,xmlIO& XML,HTTPResponse::HTTPStatus& status){
status=HTTPResponse::HTTP_BAD_REQUEST; //error by default
if (command[2]=="resolution") {
- if (command[0]=="PUT") {
+ if (command[0]=="PUT") {
if (command.size()>2) {
if (state==IDLE) {
Poco::StringTokenizer t1(command[3],",");
@@ -68,7 +68,7 @@ void Render_context::session_command(const std::vector<std::string>& command,xml
}
}
else {
- XML.addValue("error","session busy");
+ XML.addValue("error","session busy");
}
}
}
@@ -92,14 +92,14 @@ void Render_context::session_command(const std::vector<std::string>& command,xml
}
else {
- XML.addValue("error","session busy");
+ XML.addValue("error","Session busy");
}
}
}
if (command[0]=="GET") {
if (state==ANALYSING_AUDIO) {
status=HTTPResponse::HTTP_OK;
- XML.addValue("status","analysing audio");
+ XML.addValue("status","Analysing audio");
char c[20];
sprintf(c,"%02f",progress);
XML.addValue("progress",string(c));
@@ -109,18 +109,22 @@ void Render_context::session_command(const std::vector<std::string>& command,xml
//can the data only be read once?
//for now
status=HTTPResponse::HTTP_OK;
- XML.addValue("status","audio ready");
+ XML.addValue("status","Audio ready");
XML.addValue("audio",audio_thumb->print());
}
else {
- XML.addValue("error","no audio loaded");
+ XML.addValue("error","No audio loaded");
}
}
if (command[0]=="DELETE") {
- //for now
- audio_filename="";
- XML.addValue("status","audio deleted");
- status=HTTPResponse::HTTP_OK;
+ if (state==IDLE) {
+ audio_filename="";
+ XML.addValue("status","Audio deleted");
+ status=HTTPResponse::HTTP_OK;
+ }
+ else {
+ XML.addValue("error","Session busy");
+ }
}
}
if (command[2]=="graph") {
@@ -236,9 +240,14 @@ void Render_context::session_command(const std::vector<std::string>& command,xml
}
if (command[2]=="render") {
if (command[0]=="GET") {
- status=HTTPResponse::HTTP_OK;
- XML.addValue("status","Rendering video");
- XML.addValue("progress",ofToString(progress));
+ if(state==RENDERING){
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","Rendering video");
+ XML.addValue("progress",ofToString(progress));
+ }
+ else {
+ XML.addValue("error","Not rendering");
+ }
}
if (command[0]=="PUT") {
if (command.size()>2) {
@@ -267,258 +276,11 @@ void Render_context::session_command(const std::vector<std::string>& command,xml
}
}
}
-Command_response Render_context::session_command(const std::vector<std::string>& command){
- //method,id,command1,{command2,}{body}
- //here we allow the controlling server to communicate with running tasks
- string ems="";
- for (auto i:command) ems=ems+i+":";
-
- cerr<<"Rotor: session command with "<<command.size()<<" arguments- "<<ems<<endl;
-
- Command_response response;
- response.status=HTTPResponse::HTTP_BAD_REQUEST;
- if (command[2]=="resolution") {
- if (command[0]=="PUT") {
- if (command.size()>2) {
- if (state==IDLE) {
- Poco::StringTokenizer t1(command[3],",");
- if (t1.count()>1){
- int w=ofToInt(t1[0]);
- int h=ofToInt(t1[1]);
- if (graph.set_resolution(w,h)){
- response.description="<status context='"+command[1]+"'>Rotor: resolution set to "+t1[0]+"x"+t1[1]+"</status>\n";
- response.status=HTTPResponse::HTTP_OK;
- }
- else {
- response.status=HTTPResponse::HTTP_BAD_REQUEST;
- response.description="<status context='"+command[1]+"'>Rotor: invalid resolution request: "+t1[0]+"x"+t1[1]+"</status>\n";
- }
- }
- }
- else {
- response.status=HTTPResponse::HTTP_BAD_REQUEST;
- response.description="<status context='"+command[1]+"'>Rotor: session busy</status>\n";
- }
- }
- }
- }
- if (command[2]=="audio") {
- if (command[0]=="PUT") { //get audio file location and initiate analysis
- if (command.size()>2) {
- if (state==IDLE) {
- audio_filename=media_dir+command[3]; //for now, store session variables in memory //check file exists
- Poco::File f=Poco::File(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(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";
- }
- }
- }
- if (command[0]=="GET") {
- if (state==ANALYSING_AUDIO) {
- response.status=HTTPResponse::HTTP_OK;
- response.description="<status context='"+command[1]+"'>Rotor: analysing audio</status>\n";
- char c[20];
- sprintf(c,"%02f",progress);
- response.description+="<progress>"+string(c)+"</progress>\n";
- }
- else if (audio_loaded) {
- //not sure about this-- should this state be retained?
- //can the data only be read once?
- //for now
- response.status=HTTPResponse::HTTP_OK;
- response.description="<status context='"+command[1]+"'>Rotor: audio ready</status>\n";
- response.description+="<audio>\n";
- response.description+=audio_thumb->print();
- response.description+="</audio>";
- }
- else {
- response.status=HTTPResponse::HTTP_BAD_REQUEST;
- response.description="<status context='"+command[1]+"'>Rotor: no audio loaded</status>\n";
- }
- }
- if (command[0]=="DELETE") {
- //for now
- audio_filename="";
- response.description="<status>1</status>\n";
- response.status=HTTPResponse::HTTP_OK;
- }
- }
- if (command[2]=="graph") {
- if (command[0]=="GET") {
- if (graph.loaded) {
- response.status=HTTPResponse::HTTP_OK;
- response.description=graph.toString();
- }
- else {
- response.description="<status>Rotor: graph not loaded</status>\n";
- }
- }
- if (command[0]=="PUT") { //get new graph from file
- if (command.size()>2) {
- //should interrupt whatever is happening?
- //before begining to load from xml
- if (state==IDLE) { //eventually not like this
- string graph_filename=graph_dir+command[3];
- Poco::File f=Poco::File(graph_filename);
- if (f.exists()) {
- if (graph.load(graph_filename)) {
- response.status=HTTPResponse::HTTP_OK;
- //response.description="<status context='"+command[1]+"'>Rotor: loaded graph "+command[3]+"</status>\n";
- response.description=graph.toString();
- //the graph could actually contain an xml object and we could just print it here?
- //or could our nodes even be subclassed from xml nodes?
- //the graph or the audio could load first- have to analyse the audio with vamp after the graph is loaded
- //for now the graph must load 1st
- }
- else {
- response.status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; //~/sources/poco-1.4.6-all/Net/include/Poco/Net/HTTPResponse.h
- response.description="<status context='"+command[1]+"'>Rotor: could not load graph "+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[0]=="DELETE") {
- //for now
- graph=Graph();
- response.description="<status>1</status>\n";
- response.status=HTTPResponse::HTTP_OK;
- }
- }
- if (command[2]=="signal") {
- if (command[0]=="GET") { //generate xml from 1st signal output
- if (state==IDLE) {
- //direct call for testing
- float framerate=25.0f;
- if (command.size()>2) {
- framerate=ofToFloat(command[3]);
- }
- string signal_xml;
- if (graph.signal_render(signal_xml,framerate)){
- response.status=HTTPResponse::HTTP_OK;
- response.description=signal_xml;
- }
- else {
- response.status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR;
- response.description="<status context='"+command[1]+"'>Rotor: could not render output signal</status>\n";
- }
- }
- else {
- response.status=HTTPResponse::HTTP_NOT_FOUND;
- response.description="<status context='"+command[1]+"'>Signal output not found</status>\n";
- }
- }
- else {
- response.status=HTTPResponse::HTTP_SERVICE_UNAVAILABLE;
- response.description="<status context='"+command[1]+"'>Rotor: context busy</status>\n";
- }
- }
- if (command[2]=="video") {
- if (command[0]=="GET") {
- //DUMMY RESPONSE
- response.status=HTTPResponse::HTTP_OK;
- response.description="<status context='"+command[1]+"'>DUMMY RESPONSE Rotor: analysing video</status>\n";
- response.description+="<progress>45.2</progress>\n";
- }
- if (command[0]=="PUT") { //get vide file location and initiate analysis
- if (command.size()>4) { //there should be a filename + a destination node
- if (state==IDLE) {
- string video_filename=media_dir+command[4];
- //check file exists
- Poco::File f=Poco::File(video_filename);
- if (f.exists()) {
- if (load_video(command[3],video_filename)) {
- //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]+"'>Rotor: succesfully loaded "+command[4]+" into video node "+command[3]+"</status>\n";
- }
- else {
- response.status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR;
- response.description="<status context='"+command[1]+"'>Rotor: could not load "+command[4]+" into video node "+command[3]+"</status>\n";
- }
- }
- else {
- response.status=HTTPResponse::HTTP_NOT_FOUND;
- response.description="<status context='"+command[1]+"'>File '"+command[4]+"' 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: bad request</status>\n";
- }
- }
- if (command[0]=="DELETE") {
- //DUMMY RESPONSE
- response.description="<status context='"+command[1]+"''>DUMMY RESPONSE 1</status>\n";
- response.status=HTTPResponse::HTTP_OK;
- }
-
- }
- if (command[2]=="render") {
- if (command[0]=="GET") {
- //DUMMY RESPONSE
- response.status=HTTPResponse::HTTP_OK;
- response.description="<status context='"+command[1]+"'>Rotor: rendering video</status>\n";
- response.description+="<progress>"+ofToString(progress)+"</progress>\n";
- }
- if (command[0]=="PUT") {
- if (command.size()>2) {
- if (state==IDLE) {
- output_filename=output_dir+command[3];
- if (command.size()>3) {
-// output_framerate=ofToFloat(command[4]);
- }
- 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
- //SHOULD CHECK REQUIREMENTS
- response.status=HTTPResponse::HTTP_OK;
- response.description="<status context='"+command[1]+"'>DUMMY RESPONSE Rotor: cancelling render</status>\n";
- }
- }
- return response;
-}
-
bool Render_context::load_audio(const string &filename,vector<Base_audio_processor*> processors){
-
+
cerr<<"Rotor: starting audio analysis"<<endl;
-
+
libav::audioloader loader;
loader.setup(filename);
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp
index 3166de8..da711e5 100755
--- a/rotord/rotor.cpp
+++ b/rotord/rotor.cpp
@@ -391,9 +391,10 @@ Image* Video_loader::output(const Frame_spec &frame){
// int nothing=0;
//}
- if (!player.fetchFrame(frame.w,frame.h,wanted)) {
+ if (!player.fetchFrame(frame.w,frame.h,wanted)) { //seek fail
cerr<<"Rotor: frame returned false"<<endl;
- return nullptr;
+ if (image.w>0) return &image; //just return the previous frame if possible
+ else return nullptr;
};
image.setup_fromRGB(frame.w,frame.h,player.pFrameRGB->data[0]);
return &image;
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp
index 6832318..5283798 100755
--- a/rotord/rotord.cpp
+++ b/rotord/rotord.cpp
@@ -45,6 +45,7 @@ caching the whole thing isn't a goer
*/
+/*
RotorRequestHandler::RotorRequestHandler(const std::string& format): _format(format){
}
@@ -65,7 +66,7 @@ void RotorRequestHandler::handleRequest(HTTPServerRequest& request,HTTPServerRes
ostr << dt;
ostr << "</p></body></html>";
}
-
+*/
RenderContextHandler::RenderContextHandler(const std::string _content,const HTTPServerResponse::HTTPStatus _status){
content=_content;
@@ -88,6 +89,8 @@ void RenderContextHandler::handleRequest(HTTPServerRequest& request,HTTPServerRe
HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& request){
+
+ cerr<<"starting http response block"<<endl;
Logger& logger = Logger::get("Rotor");
Poco::URI theuri=Poco::URI(request.getURI());
diff --git a/rotord/rotord.h b/rotord/rotord.h
index 5b0e6ef..819cfb6 100755
--- a/rotord/rotord.h
+++ b/rotord/rotord.h
@@ -69,6 +69,7 @@ using Poco::AutoPtr;
#include "rotor.h"
+/*
class RotorRequestHandler: public HTTPRequestHandler
{
public:
@@ -87,6 +88,8 @@ class AudioAnalyserHandler: public HTTPRequestHandler
private:
vampHost::Settings settings;
};
+*/
+
class RenderContextHandler: public HTTPRequestHandler
{
@@ -98,7 +101,6 @@ class RenderContextHandler: public HTTPRequestHandler
HTTPServerResponse::HTTPStatus status;
};
-
class RotorRequestHandlerFactory: public HTTPRequestHandlerFactory
{
public: