comparison vamp-client/client.cpp @ 88:bf2e6f939f9f

Rename, + adjust finish
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 12 Oct 2016 19:02:31 +0100
parents 7a77a374b6b2
children 03ed2e0a6c8f
comparison
equal deleted inserted replaced
87:7a77a374b6b2 88:bf2e6f939f9f
28 // Next level: Capnp RPC, but I want to get the first level to work 28 // Next level: Capnp RPC, but I want to get the first level to work
29 // first, not least because the server already exists. 29 // first, not least because the server already exists.
30 30
31 namespace piper { //!!! probably something different 31 namespace piper { //!!! probably something different
32 32
33 class PiperClient : public PiperClientBase 33 class PiperClient : public PiperClientStubRequirements
34 { 34 {
35 // unsigned to avoid undefined behaviour on possible wrap 35 // unsigned to avoid undefined behaviour on possible wrap
36 typedef uint32_t ReqId; 36 typedef uint32_t ReqId;
37 37
38 public: 38 public:
58 } 58 }
59 } 59 }
60 60
61 //!!! obviously, factor out all repetitive guff 61 //!!! obviously, factor out all repetitive guff
62 62
63 //!!! list and load are supposed to be called by application code,
64 //!!! but the rest are only supposed to be called by the plugin --
65 //!!! sort out the api here
66
63 Vamp::Plugin * 67 Vamp::Plugin *
64 load(std::string key, float inputSampleRate, int adapterFlags) { 68 load(std::string key, float inputSampleRate, int adapterFlags) {
65 69
66 if (!m_process) { 70 if (!m_process) {
67 throw std::runtime_error("Piper server failed to start"); 71 throw std::runtime_error("Piper server failed to start");
86 //!!! (from another thread) 90 //!!! (from another thread)
87 91
88 QByteArray buffer = readResponseBuffer(); 92 QByteArray buffer = readResponseBuffer();
89 auto karr = toKJArray(buffer); 93 auto karr = toKJArray(buffer);
90 capnp::FlatArrayMessageReader responseMessage(karr); 94 capnp::FlatArrayMessageReader responseMessage(karr);
91 cerr << "made reader" << endl;
92 RpcResponse::Reader reader = responseMessage.getRoot<RpcResponse>(); 95 RpcResponse::Reader reader = responseMessage.getRoot<RpcResponse>();
93 96
94 //!!! handle (explicit) error case 97 //!!! handle (explicit) error case
95 98
96 checkResponseType(reader, RpcResponse::Response::Which::LOAD, id); 99 checkResponseType(reader, RpcResponse::Response::Which::LOAD, id);
227 VampnProto::readFinishResponse(pr, 230 VampnProto::readFinishResponse(pr,
228 reader.getResponse().getFinish(), 231 reader.getResponse().getFinish(),
229 m_mapper); 232 m_mapper);
230 233
231 m_mapper.removePlugin(m_mapper.pluginToHandle(plugin)); 234 m_mapper.removePlugin(m_mapper.pluginToHandle(plugin));
232 delete plugin; 235
236 // Don't delete the plugin. It's the plugin that is supposed
237 // to be calling us here
233 238
234 return pr.features; 239 return pr.features;
235 } 240 }
236 241
237 private: 242 private:
247 toKJArray(QByteArray qarr) { 252 toKJArray(QByteArray qarr) {
248 // We could do this whole thing with fewer copies, but let's 253 // We could do this whole thing with fewer copies, but let's
249 // see whether it matters first 254 // see whether it matters first
250 size_t wordSize = sizeof(capnp::word); 255 size_t wordSize = sizeof(capnp::word);
251 size_t words = qarr.size() / wordSize; 256 size_t words = qarr.size() / wordSize;
252 cerr << "converting " << words << " words (" << (words * wordSize) << " bytes)" << endl;
253 kj::Array<capnp::word> karr(kj::heapArray<capnp::word>(words)); 257 kj::Array<capnp::word> karr(kj::heapArray<capnp::word>(words));
254 memcpy(karr.begin(), qarr.data(), words * wordSize); 258 memcpy(karr.begin(), qarr.data(), words * wordSize);
255 return karr; 259 return karr;
256 } 260 }
257 261
276 } else { 280 } else {
277 buffer.append(m_process->read(wordCount * wordSize)); 281 buffer.append(m_process->read(wordCount * wordSize));
278 size_t haveWords = buffer.size() / wordSize; 282 size_t haveWords = buffer.size() / wordSize;
279 size_t expectedWords = 283 size_t expectedWords =
280 capnp::expectedSizeInWordsFromPrefix(toKJArray(buffer)); 284 capnp::expectedSizeInWordsFromPrefix(toKJArray(buffer));
281
282 cerr << "haveWords = " << haveWords << ", expectedWords = " << expectedWords << endl;
283
284 if (haveWords >= expectedWords) { 285 if (haveWords >= expectedWords) {
285 if (haveWords > expectedWords) { 286 if (haveWords > expectedWords) {
286 cerr << "WARNING: obtained more data than expected (" 287 cerr << "WARNING: obtained more data than expected ("
287 << haveWords << " words, expected " << expectedWords 288 << haveWords << " words, expected " << expectedWords
288 << ")" << endl; 289 << ")" << endl;
333 auto fl(features[0]); 334 auto fl(features[0]);
334 for (const auto &f: fl) { 335 for (const auto &f: fl) {
335 cerr << f.values[0] << endl; 336 cerr << f.values[0] << endl;
336 } 337 }
337 } 338 }
338 //!!! todo: make it possible to do both of the following -- 339
339 (void)plugin->getRemainingFeatures(); 340 (void)plugin->getRemainingFeatures();
340 // delete plugin; 341 delete plugin;
341 //!!! -- and also implement reset(), which will need to reconstruct internally 342 //!!! -- and also implement reset(), which will need to reconstruct internally
342 } 343 }
343 344