comparison vamp-client/PluginStub.h @ 186:52322dde68ea

Fix erroneous logic for handling step and block size in prior commit The earlier change had a logical misconception. If PluginStub is receiving the correct step and block size back from the configure call, the plugin on the server side must have already been successfully initialised, as the step and block size are only returned in a successful configure response. This means the test for a failed initialise and redo with the correct parameters must be done on the server side (in LoaderRequests) not the client. The client has a more complicated job, which is to notice that a *successful* configure had returned different framing parameters from those passed to the initialise call, and to pretend that it had actually failed until the host called again with the correct parameters. We definitely need tests for this!
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 06 Feb 2017 16:44:33 +0000
parents 3eb00e5c76c4
children ad6025dc0b04
comparison
equal deleted inserted replaced
185:3eb00e5c76c4 186:52322dde68ea
51 namespace client { 51 namespace client {
52 52
53 class PluginStub : public Vamp::Plugin 53 class PluginStub : public Vamp::Plugin
54 { 54 {
55 enum State { 55 enum State {
56 Loaded, Configured, Finished, Failed 56 /**
57 * The plugin's corresponding Piper feature extractor has been
58 * loaded but no subsequent state change has happened. This is
59 * the initial state of PluginStub on construction, since it
60 * is associated with a pre-loaded handle.
61 */
62 Loaded,
63
64 /**
65 * The plugin has been configured, and the step and block size
66 * received from the host in its last call to initialise()
67 * match those that were returned in the configuration
68 * response (i.e. the server's desired step and block
69 * size). Our m_config record reflects these correct
70 * values. The plugin is ready to process.
71 */
72 Configured,
73
74 /**
75 * The plugin has been configured, but the step and block size
76 * received from the host in its last call to initialise()
77 * differ from those returned by the server in the
78 * configuration response. Our initialise() call therefore
79 * returned false, and the plugin cannot be used until the
80 * host calls initialise() again with the "correct" step and
81 * block size. Our m_config record reflects these correct
82 * values, so the host can retrieve them through
83 * getPreferredStepSize and getPreferredBlockSize.
84 */
85 Misconfigured,
86
87 /**
88 * The finish() function has been called and the plugin
89 * unloaded. No further plugin activity is possible.
90 */
91 Finished,
92
93 /**
94 * A call has failed unrecoverably. No further plugin activity
95 * is possible.
96 */
97 Failed
57 }; 98 };
58 99
59 public: 100 public:
60 PluginStub(PluginClient *client, 101 PluginStub(PluginClient *client,
61 std::string pluginKey, 102 std::string pluginKey,
155 size_t blockSize) { 196 size_t blockSize) {
156 197
157 if (m_state == Failed) { 198 if (m_state == Failed) {
158 throw std::logic_error("Plugin is in failed state"); 199 throw std::logic_error("Plugin is in failed state");
159 } 200 }
201
202 if (m_state == Misconfigured) {
203 if (int(stepSize) == m_config.framing.stepSize &&
204 int(blockSize) == m_config.framing.blockSize) {
205 m_state = Configured;
206 return true;
207 } else {
208 return false;
209 }
210 }
211
160 if (m_state != Loaded) { 212 if (m_state != Loaded) {
161 m_state = Failed; 213 m_state = Failed;
162 throw std::logic_error("Plugin has already been initialised"); 214 throw std::logic_error("Plugin has already been initialised");
163 } 215 }
164 216
167 m_config.framing.blockSize = int(blockSize); 219 m_config.framing.blockSize = int(blockSize);
168 220
169 try { 221 try {
170 auto response = m_client->configure(this, m_config); 222 auto response = m_client->configure(this, m_config);
171 m_outputs = response.outputs; 223 m_outputs = response.outputs;
172 224
173 // Update with the new preferred step and block size now 225 // Update with the new preferred step and block size now
174 // that the plugin has taken into account its parameter 226 // that the plugin has taken into account its parameter
175 // settings. If the values passed in to initialise() 227 // settings. If the values passed in to initialise()
176 // weren't suitable, then this ensures that a subsequent 228 // weren't suitable, then this ensures that a subsequent
177 // call to getPreferredStepSize/BlockSize on this plugin 229 // call to getPreferredStepSize/BlockSize on this plugin
178 // object will at least get acceptable values from now on 230 // object will at least get acceptable values from now on
179 m_config.framing = response.framing; 231 m_config.framing = response.framing;
232
233 // And if they didn't match up with the passed-in ones,
234 // lodge ourselves in Misconfigured state and report
235 // failure so as to provoke the host to call initialise()
236 // again before any processing.
237 if (m_config.framing.stepSize != int(stepSize) ||
238 m_config.framing.blockSize != int(blockSize)) {
239 m_state = Misconfigured;
240 return false;
241 }
180 242
181 } catch (const std::exception &e) { 243 } catch (const std::exception &e) {
182 m_state = Failed; 244 m_state = Failed;
183 throw; 245 throw;
184 } 246 }
194 virtual void reset() { 256 virtual void reset() {
195 257
196 if (m_state == Failed) { 258 if (m_state == Failed) {
197 throw std::logic_error("Plugin is in failed state"); 259 throw std::logic_error("Plugin is in failed state");
198 } 260 }
199 if (m_state == Loaded) { 261 if (m_state == Loaded || m_state == Misconfigured) {
200 // reset is a no-op if the plugin hasn't been initialised yet 262 // reset is a no-op if the plugin hasn't been initialised yet
201 return; 263 return;
202 } 264 }
203 265
204 try { 266 try {
266 Vamp::RealTime timestamp) { 328 Vamp::RealTime timestamp) {
267 329
268 if (m_state == Failed) { 330 if (m_state == Failed) {
269 throw std::logic_error("Plugin is in failed state"); 331 throw std::logic_error("Plugin is in failed state");
270 } 332 }
271 if (m_state == Loaded) { 333 if (m_state == Loaded || m_state == Misconfigured) {
272 m_state = Failed; 334 m_state = Failed;
273 throw std::logic_error("Plugin has not been initialised"); 335 throw std::logic_error("Plugin has not been initialised");
274 } 336 }
275 if (m_state == Finished) { 337 if (m_state == Finished) {
276 m_state = Failed; 338 m_state = Failed;
295 virtual FeatureSet getRemainingFeatures() { 357 virtual FeatureSet getRemainingFeatures() {
296 358
297 if (m_state == Failed) { 359 if (m_state == Failed) {
298 throw std::logic_error("Plugin is in failed state"); 360 throw std::logic_error("Plugin is in failed state");
299 } 361 }
300 if (m_state == Loaded) { 362 if (m_state == Loaded || m_state == Misconfigured) {
301 m_state = Failed; 363 m_state = Failed;
302 throw std::logic_error("Plugin has not been configured"); 364 throw std::logic_error("Plugin has not been configured");
303 } 365 }
304 if (m_state == Finished) { 366 if (m_state == Finished) {
305 m_state = Failed; 367 m_state = Failed;