c@71
|
1
|
c@71
|
2 #include <iostream>
|
c@71
|
3 #include <dlfcn.h>
|
c@71
|
4
|
c@71
|
5 using namespace std;
|
c@71
|
6
|
c@76
|
7 int main(int, char **)
|
c@71
|
8 {
|
c@71
|
9 string example = "./example.so";
|
c@71
|
10
|
c@71
|
11 void *lib = dlopen(example.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
c@71
|
12 if (!lib) {
|
c@71
|
13 cerr << "failed to open " + example + ": " << dlerror() << endl;
|
c@71
|
14 return 1;
|
c@71
|
15 }
|
c@71
|
16
|
c@71
|
17 typedef const char *(*RequestFn)(const char *);
|
c@71
|
18 RequestFn reqFn = (RequestFn)dlsym(lib, "vampipeRequestJson");
|
c@71
|
19 if (!reqFn) {
|
c@71
|
20 cerr << "failed to find request function in " +
|
c@71
|
21 example + ": " << dlerror() << endl;
|
c@71
|
22 return 1;
|
c@71
|
23 }
|
c@71
|
24
|
c@71
|
25 typedef void (*FreeFn)(const char *);
|
c@71
|
26 FreeFn freeFn = (FreeFn)dlsym(lib, "vampipeFreeJson");
|
c@71
|
27 if (!freeFn) {
|
c@71
|
28 cerr << "failed to find free function in " +
|
c@71
|
29 example + ": " << dlerror() << endl;
|
c@71
|
30 return 1;
|
c@71
|
31 }
|
c@71
|
32
|
c@71
|
33 string listRequest = "{\"type\": \"list\"}";
|
c@71
|
34 const char *listResponse = reqFn(listRequest.c_str());
|
c@71
|
35 cout << listResponse << endl;
|
c@71
|
36 freeFn(listResponse);
|
c@73
|
37
|
c@76
|
38 string loadRequest = "{\"type\":\"load\",\"content\": {\"pluginKey\":\"vamp-example-plugins:powerspectrum\",\"inputSampleRate\":44100,\"adapterFlags\":[\"AdaptAllSafe\"]}}";
|
c@73
|
39 const char *loadResponse = reqFn(loadRequest.c_str());
|
c@73
|
40 cout << loadResponse << endl;
|
c@73
|
41 freeFn(loadResponse);
|
c@76
|
42
|
c@76
|
43 string configRequest = "{\"type\":\"configure\",\"content\":{\"pluginHandle\":1,\"configuration\":{\"blockSize\":8,\"channelCount\":1,\"stepSize\":8}}}";
|
c@76
|
44 const char *configResponse = reqFn(configRequest.c_str());
|
c@76
|
45 cout << configResponse << endl;
|
c@76
|
46 freeFn(configResponse);
|
c@76
|
47
|
c@76
|
48 string processRequest = "{\"type\":\"process\",\"content\":{\"pluginHandle\":1,\"processInput\":{\"timestamp\":{\"s\":0,\"n\":0},\"inputBuffers\":[{\"values\":[0,1,0,-1,0,1,0,-1]}]}}}";
|
c@76
|
49 const char *processResponse = reqFn(processRequest.c_str());
|
c@76
|
50 cout << processResponse << endl;
|
c@76
|
51 freeFn(processResponse);
|
c@81
|
52
|
c@81
|
53 string b64processRequest = "{\"type\":\"process\",\"content\":{\"pluginHandle\":1,\"processInput\":{\"timestamp\":{\"s\":0,\"n\":0},\"inputBuffers\":[{\"b64values\":\"AAAAAAAAgD8AAAAAAACAvwAAAAAAAIA/AAAAAAAAgL8\"}]}}}";
|
c@81
|
54 const char *b64processResponse = reqFn(b64processRequest.c_str());
|
c@81
|
55 cout << b64processResponse << endl;
|
c@81
|
56 freeFn(b64processResponse);
|
c@76
|
57
|
c@76
|
58 string finishRequest = "{\"type\":\"finish\",\"content\":{\"pluginHandle\":1}}";
|
c@76
|
59 const char *finishResponse = reqFn(finishRequest.c_str());
|
c@76
|
60 cout << finishResponse << endl;
|
c@76
|
61 freeFn(finishResponse);
|
c@71
|
62 }
|
c@71
|
63
|