1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
#include "rotord.h"
/*
ultimately- audio analysis request will spawn a task - there will be another call that will check progress
audio analysis will be saved - to a file? into a db?
for now - dump analysis into the http request
architecture - running rendering process
main vamp library segmenter, beat detector
http://127.0.0.1:9000/vamp/qm-vamp-plugins/qm-segmenter/01.wav
Running plugin: "qm-segmenter"...
Using block size = 26460, step size = 8820
Plugin accepts 1 -> 1 channel(s)
Sound file has 2 (will mix/augment if necessary)
Output is: "segmentation"
Done
./rotord: symbol lookup error: /usr/local/lib/vamp/qm-vamp-plugins.so: undefined symbol: clapack_dgetrf
http://www.codeproject.com/Articles/252827/Learning-Poco-A-simple-HTTP-server
next:
load a movie and retreive frames
save a movie
how do we deal with frames in libavcodec - can we request a frame by number
how do we deal with resolution
*/
RotorRequestHandler::RotorRequestHandler(const std::string& format): _format(format){
}
void RotorRequestHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) {
Timestamp now;
std::string dt(DateTimeFormatter::format(now, _format));
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
std::ostream& ostr = response.send();
ostr << "<html><head><title>RotorServer powered by "
"POCO C++ Libraries</title>";
ostr << "</head>";
ostr << "<body><p style=\"text-align: center; "
"font-size: 48px;\">";
ostr << dt;
ostr << "</p></body></html>";
}
AudioAnalyserHandler::AudioAnalyserHandler(const vampHost::Settings& _settings): settings(_settings){
}
void AudioAnalyserHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) {
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
//string audioData=vampHost::runPlugin();
std::ostream& ostr = response.send();
ostr << "<html><head><title>RotorServer powered by "
"POCO C++ Libraries</title>";
ostr << "</head>";
ostr << "<body><p style=\"text-align: center; "
"font-size: 48px;\">";
vampHost::runPlugin("",settings.soname,settings.filtername, "",0, settings.inputFile, ostr,true);
ostr << "</p></body></html>";
}
RenderContextHandler::RenderContextHandler(const std::string _content,const HTTPServerResponse::HTTPStatus _status){
content=_content;
status=_status;
}
void RenderContextHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) {
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
response.setStatus(status);
std::ostream& ostr = response.send();
ostr << "<?xml version='1.0' encoding='ISO-8859-1'?>\n";
ostr << content;
}
HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& request){
Application& app = Application::instance();
Poco::URI theuri=Poco::URI(request.getURI());
std::vector <std::string> command;
theuri.getPathSegments(command);
app.logger().information(request.clientAddress().toString()+" "+request.getMethod());
string content="";
HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_OK;
/*
if (segments.size() == 0) {
return new RotorRequestHandler(_format);
}
else if (segments[0]=="vamp"&&segments.size()>3) {
// vamp/plugin/filter/filename
// how do deal with error condition?
//Settings(string _so="",string _filter="",string _id="",string _input="");
return new AudioAnalyserHandler(vampHost::Settings(segments[1],segments[2],segments[3]));
//string audioData=runPlugin(string myname, string soname, string id,
// string output, int outputNo, string wavname,
// string outfilename, bool useFrames);
return 0;
}
else if (segments[0]=="new") {
// create a new render context
return 0;
}
else {
return 0;
}
*/
//at this point we are within app
//making a new contexthandler?
//how will this have access to the thread that it refers to
//how will messages be passed
//we need to do testing etc here and
//what does the handler do?
//it gets passed the response- gets to set response code
if (command.size()) {
if (command[0]=="new") {
string sID=idGen.createOne().toString(); //create() seems to cause problems
//Creates a new time-based UUID, using the MAC address of one of the system's ethernet adapters.
//Throws a SystemException if no MAC address can be obtained.
//
//seems to hang, to me
printf("Rotor: starting thread\n");
manager.start(new Rotor::Render_context(sID));
content="<sID>"+sID+"</sID>\n";
}
else if (command[0]=="list") {
//std::list < Poco::AutoPtr < Poco::Task > >::iterator it;
//it=manager.taskList().begin();
//for (it=manager.taskList().begin();it !=manager.taskList().end();++it) {
//content+="<sID>"+(*it)->name()+"</sID>\n";
//}
//massive problems making an iterator for the tasklist, the above crashes
//solution: auto type range-based for-loop
//this is c++11 specific but works
for (auto& task: manager.taskList()) //c++11
{
content+="<sID>"+task->name()+" </sID>\n";
}
}
else {
bool found=false;
for (auto& task: manager.taskList()) //c++11
{
if(task->name()==command[0]) {
//valid session command
found=true;
if (command.size()==1) {
//just invoking sID
if (request.getMethod()=="DELETE") {
task->cancel();
content="<status>1</status>\n";
}
else {
status=HTTPResponse::HTTP_BAD_REQUEST;
content="<status>Rotor: render context invoked with no command</status>\n";
}
}
else { //session modifier command- to be passed to render context
//some commands need to return error codes
//ie where the audio file isn't found
//on the other hand, some commands need to know state of the renderer?
std::string s;
std::ostringstream os;
os<<request.stream().rdbuf();
s=os.str();
vector<string> sc; //method,id,command1,{command2,}{body}
sc.push_back(request.getMethod());
for (auto& i: command){
sc.push_back(i);
}
sc.push_back(s);
Rotor::Command_response response=((Poco::AutoPtr<Rotor::Render_context>)task)->session_command(sc);
content=response.description;
status=response.status;
}
}
}
if (!found) {
status=HTTPResponse::HTTP_NOT_FOUND;
content="<status>Rotor: render context not found</status>\n";
}
}
}
else {
content="<status>Rotor: empty request</status>";
}
return new RenderContextHandler(content, status);
}
RotorServer::RotorServer(): _helpRequested(false)
{
}
RotorServer::~RotorServer()
{
}
void RotorServer::initialize(Application& self){
loadConfiguration();
ServerApplication::initialize(self);
}
void RotorServer::uninitialize(){
ServerApplication::uninitialize();
}
void RotorServer::defineOptions(OptionSet& options) {
ServerApplication::defineOptions(options);
options.addOption(
Option("help", "h", "display argument help information")
.required(false)
.repeatable(false)
.callback(OptionCallback<RotorServer>(this, &RotorServer::handleHelp)
)
);
}
void RotorServer::handleHelp(const std::string& name, const std::string& value){
HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader(
"Rotor");
helpFormatter.format(std::cout);
stopOptionsProcessing();
_helpRequested = true;
}
int RotorServer::main(const std::vector<std::string>& args){
if (!_helpRequested) {
unsigned short port = (unsigned short) config().getInt("port", 9980);
std::string format(config().getString("format", DateTimeFormat::SORTABLE_FORMAT));
ServerSocket svs(port);
HTTPServer srv(new RotorRequestHandlerFactory(),svs, new HTTPServerParams);
srv.start();
waitForTerminationRequest();
srv.stop();
}
return Application::EXIT_OK;
}
|