diff options
| -rw-r--r-- | rotord/bin/settings_default.xml | 7 | ||||
| -rw-r--r-- | rotord/rotord.cbp | 2 | ||||
| -rw-r--r-- | rotord/src/graph.h | 21 | ||||
| -rw-r--r-- | rotord/src/rendercontext.h | 1 | ||||
| -rw-r--r-- | rotord/src/rotord.cpp | 78 | ||||
| -rw-r--r-- | rotord/src/rotord.h | 9 |
6 files changed, 113 insertions, 5 deletions
diff --git a/rotord/bin/settings_default.xml b/rotord/bin/settings_default.xml index fa8b043..1db0d48 100644 --- a/rotord/bin/settings_default.xml +++ b/rotord/bin/settings_default.xml @@ -1,2 +1,7 @@ -<Rotor port="9000" graph_dir="/mnt/rotor/graphs/" media_dir="/mnt/rotor/media/" output_dir="/mnt/rotor/output/" /> +<Rotor port="9000" + graph_dir="/mnt/rotor/graphs/" + media_dir="/mnt/rotor/media/" + output_dir="/mnt/rotor/output/" + thumbnail_dir="/mnt/rotor/thumbnails/" +/> diff --git a/rotord/rotord.cbp b/rotord/rotord.cbp index 9c76a19..a3258c2 100644 --- a/rotord/rotord.cbp +++ b/rotord/rotord.cbp @@ -55,6 +55,7 @@ <Unit filename="src/cvimage.cpp" /> <Unit filename="src/cvimage.h" /> <Unit filename="src/graph.cpp" /> + <Unit filename="src/graph.h" /> <Unit filename="src/image.h" /> <Unit filename="src/libavwrapper.cpp" /> <Unit filename="src/libavwrapper.h" /> @@ -65,7 +66,6 @@ <Unit filename="src/nodes_maths.h" /> <Unit filename="src/nodes_transform.h" /> <Unit filename="src/ofUtils.cpp" /> - <Unit filename="src/ofUtils.h" /> <Unit filename="src/params.h" /> <Unit filename="src/rendercontext.cpp" /> <Unit filename="src/rendercontext.h" /> diff --git a/rotord/src/graph.h b/rotord/src/graph.h index b2132b9..6ade53e 100644 --- a/rotord/src/graph.h +++ b/rotord/src/graph.h @@ -1,6 +1,8 @@ #ifndef GRAPH_H #define GRAPH_H +#include "Poco/StringTokenizer.h" + #include "rotor.h" #include "nodes_audio_analysis.h" @@ -31,7 +33,7 @@ namespace Rotor { for (auto n: nodes) { delete n.second; } - nodes.clear(); + nodes.clear(); } string uid; //every version of a graph has a UUID, no particular need to actually read its data(?) //?? is it faster than using strings?? @@ -64,5 +66,22 @@ namespace Rotor { int outW,outH; }; + class Thumbnailer{ + public: + bool make(const string &inputfilename,int w,int h,const string &outputfilename) { + if (player.open(inputfilename)){ + if (player.fetchFrame(w,h,player.getNumberOfFrames()/4)) { + Image i; + i.setup_fromRGB(w,h,player.frame->Data[0],player.frame->Linesize[0]-(w*3)); + cv::imwrite(outputfilename.c_str(),i.rgb); + return true; + + } + } + return false; + } + private: + libav::ffms2_decoder player; + }; } #endif diff --git a/rotord/src/rendercontext.h b/rotord/src/rendercontext.h index 62eb7f4..16d007d 100644 --- a/rotord/src/rendercontext.h +++ b/rotord/src/rendercontext.h @@ -29,6 +29,7 @@ namespace Rotor { #define ANALYSE_AUDIO 1 #define PREVIEW 2 #define RENDER 3 + #define LOAD_GRAPH 4 class Session_command { public: diff --git a/rotord/src/rotord.cpp b/rotord/src/rotord.cpp index bae169f..49770a4 100644 --- a/rotord/src/rotord.cpp +++ b/rotord/src/rotord.cpp @@ -45,7 +45,61 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS //can tinyxml output to a string? is there any reason to use poco instead? if (command.size()) { - if (command[0]=="new") { + if (command[0]=="thumbnail") { + XML.pushTag("rotor"); + if (request.getMethod()=="POST") { + if (body.size()){ + int w=360; + int h=180; + if (command.size()>1){ + Poco::StringTokenizer t1(command[1],","); + if (t1.count()>1){ + int _w=toInt(t1[0]); + int _h=toInt(t1[1]); + if (_h>16&&_w>16){ + w=_w; + h=_h; + } + } + } + Thumbnailer thumb; + Poco::StringTokenizer t1(body,"."); + if (t1.count()>1){ + if (thumb.make(media_dir+body,w,h,thumbnail_dir+t1[0]+".jpg")){ + status=HTTPResponse::HTTP_OK; + XML.addValue("thumbnail",t1[0]+".jpg"); + } + else { + status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; + logger.error("ERROR: could not create thumbnail for "+media_dir+body); + XML.addValue("error","could not create thumbnail for "+media_dir+body); + } + } + else { + if (thumb.make(media_dir+body,w,h,thumbnail_dir+body+".jpg")){ + status=HTTPResponse::HTTP_OK; + XML.addValue("thumbnail",body+".jpg"); + } + else { + status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; + logger.error("ERROR: could not create thumbnail for "+media_dir+body); + XML.addValue("error","could not create thumbnail for "+media_dir+body); + } + } + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Body missing"); + XML.addValue("error","Body missing"); + } + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Invalid command combination"); + XML.addValue("error","Invalid command combination"); + } + } + else if (command[0]=="new") { XML.pushTag("rotor"); if (request.getMethod()=="GET") { string sID=idGen.createOne().toString(); //create() seems to cause problems @@ -59,7 +113,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS XML.addValue("sID",sID); status=HTTPResponse::HTTP_OK; } - if (request.getMethod()=="PUT") { //unofficial manual thread name + else if (request.getMethod()=="PUT") { //unofficial manual thread name if (body.size()) { string sID=body; bool found=false; @@ -78,6 +132,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } } } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Body missing"); + XML.addValue("error","Body missing"); + } } else if (command[0]=="list") { XML.pushTag("rotor"); @@ -98,6 +157,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } status=HTTPResponse::HTTP_OK; } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Invalid command combination"); + XML.addValue("error","Invalid command combination"); + } } else if (command[0]=="listnodes") { if (command.size()>1){ @@ -129,6 +193,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS Node_factory factory; if (factory.list_node(body,XML)) status=HTTPResponse::HTTP_OK; } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Invalid command combination"); + XML.addValue("error","Invalid command combination"); + } } else if (command[0]=="listrenders") { XML.pushTag("rotor"); @@ -168,6 +237,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } status=HTTPResponse::HTTP_OK; } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Invalid command combination"); + XML.addValue("error","Invalid command combination"); + } } else if (command[0]=="exit") { logger.information("exiting"); diff --git a/rotord/src/rotord.h b/rotord/src/rotord.h index 25ff3e3..ecdfefc 100644 --- a/rotord/src/rotord.h +++ b/rotord/src/rotord.h @@ -86,6 +86,13 @@ class RenderContextHandler: public HTTPRequestHandler class RotorRequestHandlerFactory: public HTTPRequestHandlerFactory { public: + RotorRequestHandlerFactory(){ + xmlIO xml; + if(xml.loadFile("settings.xml") ){ + media_dir=xml.getAttribute("Rotor","media_dir","",0); + thumbnail_dir=xml.getAttribute("Rotor","thumbnail_dir","",0); + } + } HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request); private: @@ -93,6 +100,8 @@ class RotorRequestHandlerFactory: public HTTPRequestHandlerFactory std::unordered_map<std::string,std::string> renders; Poco::UUIDGenerator idGen; Poco::TaskManager manager; + std::string media_dir; + std::string thumbnail_dir; }; class RotorServer: public Poco::Util::ServerApplication |
