Mercurial > hg > piper-cpp
comparison vamp-client/PiperCapnpClient.h @ 92:21f8af53eaf0
Reorganise some classes
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 13 Oct 2016 12:02:44 +0100 |
parents | c897c9a8daf1 |
children |
comparison
equal
deleted
inserted
replaced
91:c897c9a8daf1 | 92:21f8af53eaf0 |
---|---|
1 | 1 |
2 #ifndef PIPER_CAPNP_CLIENT_H | 2 #ifndef PIPER_CAPNP_CLIENT_H |
3 #define PIPER_CAPNP_CLIENT_H | 3 #define PIPER_CAPNP_CLIENT_H |
4 | 4 |
5 #include "PiperClient.h" | 5 #include "PiperClient.h" |
6 #include "PiperPluginStub.h" | |
6 #include "SynchronousTransport.h" | 7 #include "SynchronousTransport.h" |
7 | 8 |
8 #include "vamp-support/AssignedPluginHandleMapper.h" | 9 #include "vamp-support/AssignedPluginHandleMapper.h" |
9 #include "vamp-capnp/VampnProto.h" | 10 #include "vamp-capnp/VampnProto.h" |
10 | 11 |
12 #include <capnp/serialize.h> | |
13 | |
11 namespace piper { //!!! change | 14 namespace piper { //!!! change |
12 | 15 |
13 class PiperCapnpClient : public PiperStubPluginClientInterface | 16 class PiperCapnpClient : public PiperPluginClientInterface, |
17 public PiperLoaderInterface | |
14 { | 18 { |
15 // unsigned to avoid undefined behaviour on possible wrap | 19 // unsigned to avoid undefined behaviour on possible wrap |
16 typedef uint32_t ReqId; | 20 typedef uint32_t ReqId; |
21 | |
22 class CompletenessChecker : public MessageCompletenessChecker { | |
23 public: | |
24 bool isComplete(const std::vector<char> &message) const override { | |
25 auto karr = toKJArray(message); | |
26 size_t words = karr.size(); | |
27 size_t expected = capnp::expectedSizeInWordsFromPrefix(karr); | |
28 if (words > expected) { | |
29 std::cerr << "WARNING: obtained more data than expected (" | |
30 << words << " " << sizeof(capnp::word) | |
31 << "-byte words, expected " | |
32 << expected << ")" << std::endl; | |
33 } | |
34 return words >= expected; | |
35 } | |
36 }; | |
17 | 37 |
18 public: | 38 public: |
19 PiperCapnpClient(SynchronousTransport *transport) : //!!! ownership? shared ptr? | 39 PiperCapnpClient(SynchronousTransport *transport) : //!!! ownership? shared ptr? |
20 m_transport(transport) { | 40 m_transport(transport), |
41 m_completenessChecker(new CompletenessChecker) { | |
42 transport->setCompletenessChecker(m_completenessChecker); | |
21 } | 43 } |
22 | 44 |
23 ~PiperCapnpClient() { | 45 ~PiperCapnpClient() { |
46 delete m_completenessChecker; | |
24 } | 47 } |
25 | 48 |
26 //!!! obviously, factor out all repetitive guff | 49 //!!! obviously, factor out all repetitive guff |
27 | 50 |
28 //!!! list and load are supposed to be called by application code, | 51 //!!! list and load are supposed to be called by application code, |
39 Vamp::HostExt::PluginStaticData psd; | 62 Vamp::HostExt::PluginStaticData psd; |
40 Vamp::HostExt::PluginConfiguration defaultConfig; | 63 Vamp::HostExt::PluginConfiguration defaultConfig; |
41 PluginHandleMapper::Handle handle = | 64 PluginHandleMapper::Handle handle = |
42 serverLoad(key, inputSampleRate, adapterFlags, psd, defaultConfig); | 65 serverLoad(key, inputSampleRate, adapterFlags, psd, defaultConfig); |
43 | 66 |
44 Vamp::Plugin *plugin = new PiperStubPlugin(this, | 67 Vamp::Plugin *plugin = new PiperPluginStub(this, |
45 key, | 68 key, |
46 inputSampleRate, | 69 inputSampleRate, |
47 adapterFlags, | 70 adapterFlags, |
48 psd, | 71 psd, |
49 defaultConfig); | 72 defaultConfig); |
93 }; | 116 }; |
94 | 117 |
95 protected: | 118 protected: |
96 virtual | 119 virtual |
97 Vamp::Plugin::OutputList | 120 Vamp::Plugin::OutputList |
98 configure(PiperStubPlugin *plugin, | 121 configure(PiperPluginStub *plugin, |
99 Vamp::HostExt::PluginConfiguration config) override { | 122 Vamp::HostExt::PluginConfiguration config) override { |
100 | 123 |
101 if (!m_transport->isOK()) { | 124 if (!m_transport->isOK()) { |
102 throw std::runtime_error("Piper server failed to start"); | 125 throw std::runtime_error("Piper server failed to start"); |
103 } | 126 } |
132 return cr.outputs; | 155 return cr.outputs; |
133 }; | 156 }; |
134 | 157 |
135 virtual | 158 virtual |
136 Vamp::Plugin::FeatureSet | 159 Vamp::Plugin::FeatureSet |
137 process(PiperStubPlugin *plugin, | 160 process(PiperPluginStub *plugin, |
138 std::vector<std::vector<float> > inputBuffers, | 161 std::vector<std::vector<float> > inputBuffers, |
139 Vamp::RealTime timestamp) override { | 162 Vamp::RealTime timestamp) override { |
140 | 163 |
141 if (!m_transport->isOK()) { | 164 if (!m_transport->isOK()) { |
142 throw std::runtime_error("Piper server failed to start"); | 165 throw std::runtime_error("Piper server failed to start"); |
172 | 195 |
173 return pr.features; | 196 return pr.features; |
174 } | 197 } |
175 | 198 |
176 virtual Vamp::Plugin::FeatureSet | 199 virtual Vamp::Plugin::FeatureSet |
177 finish(PiperStubPlugin *plugin) override { | 200 finish(PiperPluginStub *plugin) override { |
178 | 201 |
179 if (!m_transport->isOK()) { | 202 if (!m_transport->isOK()) { |
180 throw std::runtime_error("Piper server failed to start"); | 203 throw std::runtime_error("Piper server failed to start"); |
181 } | 204 } |
182 | 205 |
213 | 236 |
214 return pr.features; | 237 return pr.features; |
215 } | 238 } |
216 | 239 |
217 virtual void | 240 virtual void |
218 reset(PiperStubPlugin *plugin, | 241 reset(PiperPluginStub *plugin, |
219 Vamp::HostExt::PluginConfiguration config) override { | 242 Vamp::HostExt::PluginConfiguration config) override { |
220 | 243 |
221 // Reload the plugin on the server side, and configure it as requested | 244 // Reload the plugin on the server side, and configure it as requested |
222 | 245 |
223 if (!m_transport->isOK()) { | 246 if (!m_transport->isOK()) { |
247 //!!! todo: mutex | 270 //!!! todo: mutex |
248 static ReqId m_nextId = 0; | 271 static ReqId m_nextId = 0; |
249 return m_nextId++; | 272 return m_nextId++; |
250 } | 273 } |
251 | 274 |
275 static | |
252 kj::Array<capnp::word> | 276 kj::Array<capnp::word> |
253 toKJArray(const std::vector<char> &buffer) { | 277 toKJArray(const std::vector<char> &buffer) { |
254 // We could do this whole thing with fewer copies, but let's | 278 // We could do this whole thing with fewer copies, but let's |
255 // see whether it matters first | 279 // see whether it matters first |
256 size_t wordSize = sizeof(capnp::word); | 280 size_t wordSize = sizeof(capnp::word); |
273 } | 297 } |
274 } | 298 } |
275 | 299 |
276 private: | 300 private: |
277 SynchronousTransport *m_transport; //!!! I don't own this, but should I? | 301 SynchronousTransport *m_transport; //!!! I don't own this, but should I? |
302 CompletenessChecker *m_completenessChecker; // I own this | |
278 }; | 303 }; |
279 | 304 |
280 } | 305 } |
281 | 306 |
282 #endif | 307 #endif |