summaryrefslogtreecommitdiff
path: root/rotord
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-07-01 16:04:34 +0100
committerTim Redfern <tim@herge.(none)>2013-07-01 16:04:34 +0100
commit0d867b8b615add6e1a5aaa300c5a39b87614d906 (patch)
tree27134dc08b34782a4d62da8671cfa181eecdeca9 /rotord
parent3710ee5ea32841d3f62e52834aa2a55f026c6620 (diff)
generating output xml
Diffstat (limited to 'rotord')
-rw-r--r--rotord/graph.cpp10
-rw-r--r--rotord/rendercontext.cpp28
-rwxr-xr-xrotord/rotor.cpp6
-rwxr-xr-xrotord/rotor.h8
-rwxr-xr-xrotord/rotord.cpp72
5 files changed, 74 insertions, 50 deletions
diff --git a/rotord/graph.cpp b/rotord/graph.cpp
index 7644dde..a6e1603 100644
--- a/rotord/graph.cpp
+++ b/rotord/graph.cpp
@@ -34,12 +34,20 @@ bool Graph::signal_render(string &signal_xml,const float framerate) {
bool Graph::video_render(const string &output_filename,const string &audio_filename,const float framerate,float& progress) {
if (find_node("video_output")) {
Video_output *video_output=dynamic_cast<Video_output*>(find_node("video_output"));
- return video_output->render(duration,framerate,output_filename,audio_filename,progress);
+ return video_output->render(duration,framerate,output_filename,audio_filename,progress,outW,outH);
}
cerr<<"Rotor: video output node not found"<<endl;
return false;
}
+bool Graph::set_resolution(int w,int h){
+ if (w>64&&h>48){
+ outW=w;
+ outH=h;
+ return true;
+ }
+ else return false;
+}
bool Graph::load(string &filename){
loaded=false;
printf("loading graph: %s\n",filename.c_str());
diff --git a/rotord/rendercontext.cpp b/rotord/rendercontext.cpp
index 422ef08..4be54f1 100644
--- a/rotord/rendercontext.cpp
+++ b/rotord/rendercontext.cpp
@@ -48,6 +48,9 @@ void Render_context::add_queue(int item) {
work_queue.push_back(item);
mutex.unlock();
}
+void Render_context::session_command(const std::vector<std::string>& command,xmlIO& XML,HTTPResponse::HTTPStatus& status){
+
+}
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
@@ -58,6 +61,31 @@ Command_response Render_context::session_command(const std::vector<std::string>&
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) {
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp
index fb68eed..12741f9 100755
--- a/rotord/rotor.cpp
+++ b/rotord/rotor.cpp
@@ -244,13 +244,11 @@ bool Video_output::render(const float duration, const float framerate,const stri
}
*/
-bool Video_output::render(const float duration, const float framerate,const string &output_filename,const string &audio_filename,float& progress){
+bool Video_output::render(const float duration, const float framerate,const string &output_filename,const string &audio_filename,float& progress,int outW,int outH){
//
//setup defaults
- int outW=640;
- int outH=360;
- int bitRate=4000000;
+ int bitRate=5000000;
int frameRate=25;
AVCodecID codecId=AV_CODEC_ID_H264; //MPEG4;
std::string container ="mp4";
diff --git a/rotord/rotor.h b/rotord/rotor.h
index 8720983..e2a26d9 100755
--- a/rotord/rotor.h
+++ b/rotord/rotor.h
@@ -31,6 +31,7 @@ TODO - put the boilerplate code for checking inputs into the base class, finally
#include "Poco/File.h"
#include "Poco/Base64Encoder.h"
#include "Poco/Path.h"
+#include "Poco/StringTokenizer.h"
#include <iostream>
@@ -815,7 +816,7 @@ namespace Rotor {
else return nullptr;
};
Video_output* clone(map<string,string> &_settings) { return new Video_output(_settings);};
- bool render(const float duration, const float framerate,const string &output_filename,const string &audio_filename,float& progress);
+ bool render(const float duration, const float framerate,const string &output_filename,const string &audio_filename,float& progress,int w,int h);
private:
@@ -1339,7 +1340,7 @@ namespace Rotor {
};
class Graph{
public:
- Graph(){duration=10.0f;loaded = false;};
+ Graph(){duration=10.0f;loaded = false;outW=640;outH=360;};
Graph(const string& _uid,const string& _desc){init(_uid,_desc);};
void init(const string& _uid,const string& _desc){ uid=_uid;description=_desc;duration=10.0f;};
string uid; //every version of a graph has a UUID, no particular need to actually read its data(?)
@@ -1352,6 +1353,7 @@ namespace Rotor {
bool video_render(const string &output_filename,const string &audio_filename,const float framerate,float& progress);
int load(Poco::UUID uid);
bool load(string &graph_filename);
+ bool set_resolution(int w,int h);
UUID save(); //save to DB, returns UUID of saved graph
bool loaded;
float duration;
@@ -1359,6 +1361,7 @@ namespace Rotor {
private:
Node_factory factory;
xmlIO xml;
+ int outW,outH;
};
class Audio_thumbnailer: public Base_audio_processor {
public:
@@ -1405,6 +1408,7 @@ namespace Rotor {
void runTask();
void add_queue(int item);
Command_response session_command(const std::vector<std::string>& command);
+ void session_command(const std::vector<std::string>& command,xmlIO& XML,HTTPResponse::HTTPStatus& status);
Render_status get_status();
void cancel(); //interrupt locking process
int make_preview(int nodeID, float time); //starts a frame preview - returns status code - how to retrieve?
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp
index 7b7285b..6ece98a 100755
--- a/rotord/rotord.cpp
+++ b/rotord/rotord.cpp
@@ -96,7 +96,6 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
logger.information(request.clientAddress().toString()+" "+request.getMethod());
- string content="";
HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_BAD_REQUEST; //by default
std::string body;
@@ -104,6 +103,13 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
os<<request.stream().rdbuf();
body=os.str();
+ xmlIO XML; //xml object handles the servers responses
+ XML.addTag("rotor");
+ XML.pushTag("rotor");
+
+ //can we create a tinyxml object here and pass a pointer to it to the render context?
+ //can tinyxml output to a string? is there any reason to use poco instead?
+
if (command.size()) {
if (command[0]=="new") {
if (request.getMethod()=="GET") {
@@ -114,15 +120,16 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
//seems to hang, to me
logger.information("Rotor: starting thread "+sID);
manager.start(new Rotor::Render_context(sID));
- content="<sID>"+sID+"</sID>\n";
+ //XML.addTag("sID");
+ XML.addValue("sID",sID);
status=HTTPResponse::HTTP_OK;
}
- if (request.getMethod()=="PUT") { //undocumented manual thread name
+ if (request.getMethod()=="PUT") { //unofficial manual thread name
if (body.size()) {
string sID=body;
cerr << "Rotor: starting thread "<< sID << endl;
manager.start(new Rotor::Render_context(sID));
- content="<sID>"+sID+"</sID>\n";
+ XML.addValue("sID",sID);
status=HTTPResponse::HTTP_OK;
}
}
@@ -140,34 +147,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
//this is c++11 specific but works
for (auto& task: manager.taskList()) { //c++11
- content+="<sID>"+task->name()+" </sID>\n";
+ XML.addValue("sID",task->name());
}
status=HTTPResponse::HTTP_OK;
}
}
- else if (command[0]=="styles") {
- //eventually retrieve from sql;
- //a bit of weirdness here: prefer to just get whole file to a string.
- if (request.getMethod()=="GET") {
- std::string stylesfile = "styles.xml";
- Poco::File f=Poco::File(stylesfile);
- if (f.exists()) {
- Poco::FileInputStream file(stylesfile);
- //while (!file.eof()) {
- // file >> content;
- //}
- Poco::StreamCopier::copyToString(file, content);
- status=HTTPResponse::HTTP_OK;
- }
- else {
- content="<status>Rotor: internal error: styles not found</status>\n";
- }
-
- }
- else {
- content="<status>Rotor: bad request</status>\n";
- }
- }
else if (command[0]=="exit") {
exit(0);
}
@@ -178,15 +162,15 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
//valid session command
found=true;
if (command.size()==1) {
- //just invoking sID
- if (request.getMethod()=="DELETE") {
- task->cancel();
- content="<status>1</status>\n";
- status=HTTPResponse::HTTP_OK;
- }
- else {
- content="<status>Rotor: render context invoked with no command</status>\n";
- }
+ //just invoking sID
+ if (request.getMethod()=="DELETE") {
+ task->cancel();
+ XML.addValue("status","1");
+ status=HTTPResponse::HTTP_OK;
+ }
+ else {
+ XML.addValue("error","Render context invoked with no command");
+ }
}
else { //session modifier command- to be passed to render context
//some commands need to return error codes
@@ -201,23 +185,25 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
}
sc.push_back(body);
- Rotor::Command_response response=((Poco::AutoPtr<Rotor::Render_context>)task)->session_command(sc);
-
- content=response.description;
- status=response.status;
+ //Rotor::Command_response response=((Poco::AutoPtr<Rotor::Render_context>)task)->session_command(sc);
+ ((Poco::AutoPtr<Rotor::Render_context>)task)->session_command(sc,XML,status);
+ //content=response.description;
+ //status=response.status;
}
}
}
if (!found) {
status=HTTPResponse::HTTP_NOT_FOUND;
- content="<status>Rotor: render context not found</status>\n";
+ XML.addValue("error","Render context not found");
}
}
}
else {
- content="<status>Rotor: empty request</status>";
+ XML.addValue("error","Emoty request");
}
+ string content;
+ XML.copyXmlToString(content);
return new RenderContextHandler(content, status);
}