diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-09-12 14:28:32 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-09-12 14:28:32 +0100 |
| commit | fd2cdacf49b101658de7e0a624c84897a398e62e (patch) | |
| tree | 6ced81a91b56e20182d5dff77a1e09cffb2a0e29 /rotord/src | |
| parent | 119dbdb43b859b529112d49dbeb3e05831372f68 (diff) | |
thumbnail function
Diffstat (limited to 'rotord/src')
| -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 |
4 files changed, 106 insertions, 3 deletions
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 |
