Mercurial > hg > piper-cpp
comparison vamp-client/stub.h @ 80:d9e85a65d45b
Inching toward a client
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Tue, 11 Oct 2016 15:49:28 +0100 |
parents | f4b5c0e70771 |
children | db9a6ab618bc |
comparison
equal
deleted
inserted
replaced
79:f4497c1da43d | 80:d9e85a65d45b |
---|---|
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 | 8 |
9 namespace piper { //!!! should be something else | 9 namespace piper { //!!! should be something else |
10 | 10 |
11 typedef int32_t PiperPluginHandle; | 11 class PiperStubPlugin; |
12 | 12 |
13 class PiperClientBase | 13 class PiperClientBase |
14 { | 14 { |
15 public: | 15 public: |
16 virtual | 16 virtual |
17 Vamp::Plugin::OutputList | 17 Vamp::Plugin::OutputList |
18 configure(PiperPluginHandle handle, | 18 configure(PiperStubPlugin *plugin, |
19 Vamp::HostExt::PluginConfiguration config) = 0; | 19 Vamp::HostExt::PluginConfiguration config) = 0; |
20 | 20 |
21 virtual | 21 virtual |
22 Vamp::Plugin::FeatureSet | 22 Vamp::Plugin::FeatureSet |
23 process(PiperPluginHandle handle, | 23 process(PiperStubPlugin *plugin, |
24 const float *const *inputBuffers, | 24 const float *const *inputBuffers, |
25 Vamp::RealTime timestamp) = 0; | 25 Vamp::RealTime timestamp) = 0; |
26 | 26 |
27 virtual Vamp::Plugin::FeatureSet | 27 virtual Vamp::Plugin::FeatureSet |
28 finish(PiperPluginHandle handle) = 0; | 28 finish(PiperStubPlugin *plugin) = 0; |
29 }; | 29 }; |
30 | 30 |
31 class PiperStubPlugin : public Vamp::Plugin | 31 class PiperStubPlugin : public Vamp::Plugin |
32 { | 32 { |
33 enum State { | 33 enum State { |
34 Loaded, Configured, Finished | 34 Loaded, Configured, Finished |
35 }; | 35 }; |
36 | 36 |
37 public: | 37 public: |
38 PiperStubPlugin(PiperClientBase *client, | 38 PiperStubPlugin(PiperClientBase *client, |
39 PiperPluginHandle handle, | |
40 float inputSampleRate, | 39 float inputSampleRate, |
41 Vamp::HostExt::PluginStaticData psd, | 40 Vamp::HostExt::PluginStaticData psd, |
42 Vamp::HostExt::PluginConfiguration defaultConfig) : | 41 Vamp::HostExt::PluginConfiguration defaultConfig) : |
43 Plugin(inputSampleRate), | 42 Plugin(inputSampleRate), |
44 m_client(client), | 43 m_client(client), |
45 m_handle(handle), | |
46 m_state(Loaded), | 44 m_state(Loaded), |
47 m_psd(psd), | 45 m_psd(psd), |
48 m_defaultConfig(defaultConfig), | 46 m_defaultConfig(defaultConfig), |
49 m_config(defaultConfig) | 47 m_config(defaultConfig) |
50 { } | 48 { } |
51 | 49 |
52 virtual ~PiperStubPlugin() { | 50 virtual ~PiperStubPlugin() { |
53 if (m_state != Finished) { | 51 if (m_state != Finished) { |
54 (void)m_client->finish(m_handle); | 52 std::cerr << "WARNING: PiperStubPlugin destroyed without finish() call, may be a server-side resource leak" << std::endl; |
55 m_state = Finished; | |
56 } | 53 } |
57 } | 54 } |
58 | 55 |
59 virtual std::string getIdentifier() const { | 56 virtual std::string getIdentifier() const { |
60 return m_psd.basic.identifier; | 57 return m_psd.basic.identifier; |
124 | 121 |
125 m_config.channelCount = inputChannels; | 122 m_config.channelCount = inputChannels; |
126 m_config.stepSize = stepSize; | 123 m_config.stepSize = stepSize; |
127 m_config.blockSize = blockSize; | 124 m_config.blockSize = blockSize; |
128 | 125 |
129 m_outputs = m_client->configure(m_handle, m_config); | 126 m_outputs = m_client->configure(this, m_config); |
130 | 127 |
131 if (!m_outputs.empty()) { | 128 if (!m_outputs.empty()) { |
132 m_state = Configured; | 129 m_state = Configured; |
133 return true; | 130 return true; |
134 } else { | 131 } else { |
190 } | 187 } |
191 if (m_state == Finished) { | 188 if (m_state == Finished) { |
192 throw std::logic_error("Plugin has already been disposed of"); | 189 throw std::logic_error("Plugin has already been disposed of"); |
193 } | 190 } |
194 | 191 |
195 return m_client->process(m_handle, inputBuffers, timestamp); | 192 return m_client->process(this, inputBuffers, timestamp); |
196 } | 193 } |
197 | 194 |
198 virtual FeatureSet getRemainingFeatures() { | 195 virtual FeatureSet getRemainingFeatures() { |
199 | 196 |
200 if (m_state == Loaded) { | 197 if (m_state == Loaded) { |
204 throw std::logic_error("Plugin has already been disposed of"); | 201 throw std::logic_error("Plugin has already been disposed of"); |
205 } | 202 } |
206 | 203 |
207 m_state = Finished; | 204 m_state = Finished; |
208 | 205 |
209 return m_client->finish(m_handle); | 206 return m_client->finish(this); |
210 } | 207 } |
211 | 208 |
212 private: | 209 private: |
213 PiperClientBase *m_client; | 210 PiperClientBase *m_client; |
214 PiperPluginHandle m_handle; | |
215 State m_state; | 211 State m_state; |
216 Vamp::HostExt::PluginStaticData m_psd; | 212 Vamp::HostExt::PluginStaticData m_psd; |
217 OutputList m_outputs; | 213 OutputList m_outputs; |
218 Vamp::HostExt::PluginConfiguration m_defaultConfig; | 214 Vamp::HostExt::PluginConfiguration m_defaultConfig; |
219 Vamp::HostExt::PluginConfiguration m_config; | 215 Vamp::HostExt::PluginConfiguration m_config; |