comparison VamPipePluginLibrary.cpp @ 110:2f621b00747e

Merge from branch jsonrpc
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 06 Oct 2016 14:33:12 +0100
parents 9d20eb251fbc
children 873ce3bfa776
comparison
equal deleted inserted replaced
107:f272e46f5615 110:2f621b00747e
52 err = "invalid json: " + err; 52 err = "invalid json: " + err;
53 return {}; 53 return {};
54 } 54 }
55 if (!j.is_object()) { 55 if (!j.is_object()) {
56 err = "object expected at top level"; 56 err = "object expected at top level";
57 } else if (!j["type"].is_string()) {
58 err = "string expected for type field";
59 } else if (!j["content"].is_null() && !j["content"].is_object()) {
60 err = "object expected for content field";
61 } 57 }
62 return j; 58 return j;
63 } 59 }
64 60
65 VamPipePluginLibrary::VamPipePluginLibrary(vector<VamPipeAdapterInterface *> pp) : 61 VamPipePluginLibrary::VamPipePluginLibrary(vector<VamPipeAdapterInterface *> pp) :
128 124
129 return response; 125 return response;
130 } 126 }
131 127
132 string 128 string
133 VamPipePluginLibrary::processRawImpl(int pluginHandle, 129 VamPipePluginLibrary::processRawImpl(int handle,
134 const float *const *inputBuffers, 130 const float *const *inputBuffers,
135 int sec, 131 int sec,
136 int nsec) 132 int nsec)
137 { 133 {
138 Vamp::Plugin *plugin = m_mapper.handleToPlugin(pluginHandle); 134 Vamp::Plugin *plugin = m_mapper.handleToPlugin(handle);
139 if (!plugin) { 135 if (!plugin) {
140 return VampJson::fromError("unknown plugin handle", RRType::Process) 136 return VampJson::fromError("unknown plugin handle", RRType::Process)
141 .dump(); 137 .dump();
142 } 138 }
143 139
144 if (!m_mapper.isConfigured(pluginHandle)) { 140 if (!m_mapper.isConfigured(handle)) {
145 return VampJson::fromError("plugin has not been configured", RRType::Process) 141 return VampJson::fromError("plugin has not been configured", RRType::Process)
146 .dump(); 142 .dump();
147 } 143 }
148 144
149 Vamp::RealTime timestamp(sec, nsec); 145 Vamp::RealTime timestamp(sec, nsec);
152 resp.plugin = plugin; 148 resp.plugin = plugin;
153 resp.features = plugin->process(inputBuffers, timestamp); 149 resp.features = plugin->process(inputBuffers, timestamp);
154 150
155 m_useBase64 = true; 151 m_useBase64 = true;
156 152
157 return VampJson::fromVampResponse_Process 153 return VampJson::fromRpcResponse_Process
158 (resp, m_mapper, 154 (resp, m_mapper,
159 VampJson::BufferSerialisation::Base64) 155 VampJson::BufferSerialisation::Base64)
160 .dump(); 156 .dump();
161 } 157 }
162 158
183 Json rj; 179 Json rj;
184 180
185 switch (type) { 181 switch (type) {
186 182
187 case RRType::List: 183 case RRType::List:
188 rj = VampJson::fromVampResponse_List(listPluginData()); 184 rj = VampJson::fromRpcResponse_List(listPluginData());
189 break; 185 break;
190 186
191 case RRType::Load: 187 case RRType::Load:
192 { 188 {
193 auto req = VampJson::toVampRequest_Load(j, err); 189 auto req = VampJson::toRpcRequest_Load(j, err);
194 if (err != "") { 190 if (err != "") {
195 rj = VampJson::fromError(err, type); 191 rj = VampJson::fromError(err, type);
196 } else { 192 } else {
197 auto resp = loadPlugin(req, err); 193 auto resp = loadPlugin(req, err);
198 if (err != "") { 194 if (err != "") {
199 rj = VampJson::fromError(err, type); 195 rj = VampJson::fromError(err, type);
200 } else { 196 } else {
201 m_mapper.addPlugin(resp.plugin); 197 m_mapper.addPlugin(resp.plugin);
202 rj = VampJson::fromVampResponse_Load(resp, m_mapper); 198 rj = VampJson::fromRpcResponse_Load(resp, m_mapper);
203 } 199 }
204 } 200 }
205 break; 201 break;
206 } 202 }
207 203
208 case RRType::Configure: 204 case RRType::Configure:
209 { 205 {
210 auto req = VampJson::toVampRequest_Configure(j, m_mapper, err); 206 auto req = VampJson::toRpcRequest_Configure(j, m_mapper, err);
211 if (err != "") { 207 if (err != "") {
212 rj = VampJson::fromError(err, type); 208 rj = VampJson::fromError(err, type);
213 } else { 209 } else {
214 auto h = m_mapper.pluginToHandle(req.plugin); 210 auto h = m_mapper.pluginToHandle(req.plugin);
215 if (h == m_mapper.INVALID_HANDLE) { 211 if (h == m_mapper.INVALID_HANDLE) {
222 rj = VampJson::fromError(err, type); 218 rj = VampJson::fromError(err, type);
223 } else { 219 } else {
224 m_mapper.markConfigured(h, 220 m_mapper.markConfigured(h,
225 req.configuration.channelCount, 221 req.configuration.channelCount,
226 req.configuration.blockSize); 222 req.configuration.blockSize);
227 rj = VampJson::fromVampResponse_Configure(resp, m_mapper); 223 rj = VampJson::fromRpcResponse_Configure(resp, m_mapper);
228 } 224 }
229 } 225 }
230 } 226 }
231 break; 227 break;
232 } 228 }
233 229
234 case RRType::Process: 230 case RRType::Process:
235 { 231 {
236 VampJson::BufferSerialisation serialisation; 232 VampJson::BufferSerialisation serialisation;
237 233
238 auto req = VampJson::toVampRequest_Process(j, m_mapper, 234 auto req = VampJson::toRpcRequest_Process(j, m_mapper,
239 serialisation, err); 235 serialisation, err);
240 if (err != "") { 236 if (err != "") {
241 rj = VampJson::fromError(err, type); 237 rj = VampJson::fromError(err, type);
242 } else { 238 } else {
243 auto h = m_mapper.pluginToHandle(req.plugin); 239 auto h = m_mapper.pluginToHandle(req.plugin);
270 if (fbuffers) { 266 if (fbuffers) {
271 Vamp::HostExt::ProcessResponse resp; 267 Vamp::HostExt::ProcessResponse resp;
272 resp.plugin = req.plugin; 268 resp.plugin = req.plugin;
273 resp.features = req.plugin->process(fbuffers, req.timestamp); 269 resp.features = req.plugin->process(fbuffers, req.timestamp);
274 delete[] fbuffers; 270 delete[] fbuffers;
275 rj = VampJson::fromVampResponse_Process 271 rj = VampJson::fromRpcResponse_Process
276 (resp, m_mapper, serialisation); 272 (resp, m_mapper, serialisation);
277 } 273 }
278 } 274 }
279 } 275 }
280 break; 276 break;
281 } 277 }
282 278
283 case RRType::Finish: 279 case RRType::Finish:
284 { 280 {
285 auto req = VampJson::toVampRequest_Finish(j, m_mapper, err); 281 auto req = VampJson::toRpcRequest_Finish(j, m_mapper, err);
286 if (err != "") { 282 if (err != "") {
287 rj = VampJson::fromError(err, type); 283 rj = VampJson::fromError(err, type);
288 } else { 284 } else {
289 auto h = m_mapper.pluginToHandle(req.plugin); 285 auto h = m_mapper.pluginToHandle(req.plugin);
290 if (h == m_mapper.INVALID_HANDLE) { 286 if (h == m_mapper.INVALID_HANDLE) {
295 291
296 Vamp::HostExt::ProcessResponse resp; 292 Vamp::HostExt::ProcessResponse resp;
297 resp.plugin = req.plugin; 293 resp.plugin = req.plugin;
298 resp.features = req.plugin->getRemainingFeatures(); 294 resp.features = req.plugin->getRemainingFeatures();
299 295
300 rj = VampJson::fromVampResponse_Finish 296 rj = VampJson::fromRpcResponse_Finish
301 (resp, m_mapper, serialisation); 297 (resp, m_mapper, serialisation);
302 298
303 m_mapper.removePlugin(h); 299 m_mapper.removePlugin(h);
304 delete req.plugin; 300 delete req.plugin;
305 } 301 }