comparison vamp-sdk/PluginAdapter.cpp @ 76:6683f99107cf

* Use m_impl structure for PluginAdapter as well * Doc updates
author cannam
date Thu, 07 Jun 2007 14:15:24 +0000
parents b907557b2fb9
children 1e7ab0399852
comparison
equal deleted inserted replaced
75:0f8524203677 76:6683f99107cf
39 //#define DEBUG_PLUGIN_ADAPTER 1 39 //#define DEBUG_PLUGIN_ADAPTER 1
40 40
41 41
42 namespace Vamp { 42 namespace Vamp {
43 43
44 PluginAdapterBase::PluginAdapterBase() : 44 class PluginAdapterBase::Impl
45 m_populated(false) 45 {
46 { 46 public:
47 #ifdef DEBUG_PLUGIN_ADAPTER 47 Impl(PluginAdapterBase *);
48 std::cerr << "PluginAdapterBase[" << this << "]::PluginAdapterBase" << std::endl; 48 ~Impl();
49 #endif 49
50 const VampPluginDescriptor *getDescriptor();
51
52 protected:
53 PluginAdapterBase *m_base;
54
55 static VampPluginHandle vampInstantiate(const VampPluginDescriptor *desc,
56 float inputSampleRate);
57
58 static void vampCleanup(VampPluginHandle handle);
59
60 static int vampInitialise(VampPluginHandle handle, unsigned int channels,
61 unsigned int stepSize, unsigned int blockSize);
62
63 static void vampReset(VampPluginHandle handle);
64
65 static float vampGetParameter(VampPluginHandle handle, int param);
66 static void vampSetParameter(VampPluginHandle handle, int param, float value);
67
68 static unsigned int vampGetCurrentProgram(VampPluginHandle handle);
69 static void vampSelectProgram(VampPluginHandle handle, unsigned int program);
70
71 static unsigned int vampGetPreferredStepSize(VampPluginHandle handle);
72 static unsigned int vampGetPreferredBlockSize(VampPluginHandle handle);
73 static unsigned int vampGetMinChannelCount(VampPluginHandle handle);
74 static unsigned int vampGetMaxChannelCount(VampPluginHandle handle);
75
76 static unsigned int vampGetOutputCount(VampPluginHandle handle);
77
78 static VampOutputDescriptor *vampGetOutputDescriptor(VampPluginHandle handle,
79 unsigned int i);
80
81 static void vampReleaseOutputDescriptor(VampOutputDescriptor *desc);
82
83 static VampFeatureList *vampProcess(VampPluginHandle handle,
84 const float *const *inputBuffers,
85 int sec,
86 int nsec);
87
88 static VampFeatureList *vampGetRemainingFeatures(VampPluginHandle handle);
89
90 static void vampReleaseFeatureSet(VampFeatureList *fs);
91
92 void cleanup(Plugin *plugin);
93 void checkOutputMap(Plugin *plugin);
94 unsigned int getOutputCount(Plugin *plugin);
95 VampOutputDescriptor *getOutputDescriptor(Plugin *plugin,
96 unsigned int i);
97 VampFeatureList *process(Plugin *plugin,
98 const float *const *inputBuffers,
99 int sec, int nsec);
100 VampFeatureList *getRemainingFeatures(Plugin *plugin);
101 VampFeatureList *convertFeatures(Plugin *plugin,
102 const Plugin::FeatureSet &features);
103
104 // maps both plugins and descriptors to adapters
105 typedef std::map<const void *, Impl *> AdapterMap;
106 static AdapterMap *m_adapterMap;
107 static Impl *lookupAdapter(VampPluginHandle);
108
109 bool m_populated;
110 VampPluginDescriptor m_descriptor;
111 Plugin::ParameterList m_parameters;
112 Plugin::ProgramList m_programs;
113
114 typedef std::map<Plugin *, Plugin::OutputList *> OutputMap;
115 OutputMap m_pluginOutputs;
116
117 std::map<Plugin *, VampFeatureList *> m_fs;
118 std::map<Plugin *, std::vector<size_t> > m_fsizes;
119 std::map<Plugin *, std::vector<std::vector<size_t> > > m_fvsizes;
120 void resizeFS(Plugin *plugin, int n);
121 void resizeFL(Plugin *plugin, int n, size_t sz);
122 void resizeFV(Plugin *plugin, int n, int j, size_t sz);
123 };
124
125 PluginAdapterBase::PluginAdapterBase()
126 {
127 m_impl = new Impl(this);
128 }
129
130 PluginAdapterBase::~PluginAdapterBase()
131 {
132 delete m_impl;
50 } 133 }
51 134
52 const VampPluginDescriptor * 135 const VampPluginDescriptor *
53 PluginAdapterBase::getDescriptor() 136 PluginAdapterBase::getDescriptor()
54 { 137 {
55 #ifdef DEBUG_PLUGIN_ADAPTER 138 return m_impl->getDescriptor();
56 std::cerr << "PluginAdapterBase[" << this << "]::getDescriptor" << std::endl; 139 }
140
141 PluginAdapterBase::Impl::Impl(PluginAdapterBase *base) :
142 m_base(base),
143 m_populated(false)
144 {
145 #ifdef DEBUG_PLUGIN_ADAPTER
146 std::cerr << "PluginAdapterBase::Impl[" << this << "]::Impl" << std::endl;
147 #endif
148 }
149
150 const VampPluginDescriptor *
151 PluginAdapterBase::Impl::getDescriptor()
152 {
153 #ifdef DEBUG_PLUGIN_ADAPTER
154 std::cerr << "PluginAdapterBase::Impl[" << this << "]::getDescriptor" << std::endl;
57 #endif 155 #endif
58 156
59 if (m_populated) return &m_descriptor; 157 if (m_populated) return &m_descriptor;
60 158
61 Plugin *plugin = createPlugin(48000); 159 Plugin *plugin = m_base->createPlugin(48000);
62 160
63 if (plugin->getVampApiVersion() != VAMP_API_VERSION) { 161 if (plugin->getVampApiVersion() != VAMP_API_VERSION) {
64 std::cerr << "Vamp::PluginAdapterBase::getDescriptor: ERROR: " 162 std::cerr << "Vamp::PluginAdapterBase::Impl::getDescriptor: ERROR: "
65 << "Plugin object API version " 163 << "Plugin object API version "
66 << plugin->getVampApiVersion() 164 << plugin->getVampApiVersion()
67 << " does not match actual API version " 165 << " does not match actual API version "
68 << VAMP_API_VERSION << std::endl; 166 << VAMP_API_VERSION << std::endl;
69 delete plugin; 167 delete plugin;
153 251
154 m_populated = true; 252 m_populated = true;
155 return &m_descriptor; 253 return &m_descriptor;
156 } 254 }
157 255
158 PluginAdapterBase::~PluginAdapterBase() 256 PluginAdapterBase::Impl::~Impl()
159 { 257 {
160 #ifdef DEBUG_PLUGIN_ADAPTER 258 #ifdef DEBUG_PLUGIN_ADAPTER
161 std::cerr << "PluginAdapterBase[" << this << "]::~PluginAdapterBase" << std::endl; 259 std::cerr << "PluginAdapterBase::Impl[" << this << "]::~Impl" << std::endl;
162 #endif 260 #endif
163 261
164 if (!m_populated) return; 262 if (!m_populated) return;
165 263
166 free((void *)m_descriptor.identifier); 264 free((void *)m_descriptor.identifier);
198 m_adapterMap = 0; 296 m_adapterMap = 0;
199 } 297 }
200 } 298 }
201 } 299 }
202 300
203 PluginAdapterBase * 301 PluginAdapterBase::Impl *
204 PluginAdapterBase::lookupAdapter(VampPluginHandle handle) 302 PluginAdapterBase::Impl::lookupAdapter(VampPluginHandle handle)
205 { 303 {
206 #ifdef DEBUG_PLUGIN_ADAPTER 304 #ifdef DEBUG_PLUGIN_ADAPTER
207 std::cerr << "PluginAdapterBase::lookupAdapter(" << handle << ")" << std::endl; 305 std::cerr << "PluginAdapterBase::Impl::lookupAdapter(" << handle << ")" << std::endl;
208 #endif 306 #endif
209 307
210 if (!m_adapterMap) return 0; 308 if (!m_adapterMap) return 0;
211 AdapterMap::const_iterator i = m_adapterMap->find(handle); 309 AdapterMap::const_iterator i = m_adapterMap->find(handle);
212 if (i == m_adapterMap->end()) return 0; 310 if (i == m_adapterMap->end()) return 0;
213 return i->second; 311 return i->second;
214 } 312 }
215 313
216 VampPluginHandle 314 VampPluginHandle
217 PluginAdapterBase::vampInstantiate(const VampPluginDescriptor *desc, 315 PluginAdapterBase::Impl::vampInstantiate(const VampPluginDescriptor *desc,
218 float inputSampleRate) 316 float inputSampleRate)
219 { 317 {
220 #ifdef DEBUG_PLUGIN_ADAPTER 318 #ifdef DEBUG_PLUGIN_ADAPTER
221 std::cerr << "PluginAdapterBase::vampInstantiate(" << desc << ")" << std::endl; 319 std::cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << ")" << std::endl;
222 #endif 320 #endif
223 321
224 if (!m_adapterMap) { 322 if (!m_adapterMap) {
225 m_adapterMap = new AdapterMap(); 323 m_adapterMap = new AdapterMap();
226 } 324 }
227 325
228 if (m_adapterMap->find(desc) == m_adapterMap->end()) { 326 if (m_adapterMap->find(desc) == m_adapterMap->end()) {
229 std::cerr << "WARNING: PluginAdapterBase::vampInstantiate: Descriptor " << desc << " not in adapter map" << std::endl; 327 std::cerr << "WARNING: PluginAdapterBase::Impl::vampInstantiate: Descriptor " << desc << " not in adapter map" << std::endl;
230 return 0; 328 return 0;
231 } 329 }
232 330
233 PluginAdapterBase *adapter = (*m_adapterMap)[desc]; 331 Impl *adapter = (*m_adapterMap)[desc];
234 if (desc != &adapter->m_descriptor) return 0; 332 if (desc != &adapter->m_descriptor) return 0;
235 333
236 Plugin *plugin = adapter->createPlugin(inputSampleRate); 334 Plugin *plugin = adapter->m_base->createPlugin(inputSampleRate);
237 if (plugin) { 335 if (plugin) {
238 (*m_adapterMap)[plugin] = adapter; 336 (*m_adapterMap)[plugin] = adapter;
239 } 337 }
240 338
241 #ifdef DEBUG_PLUGIN_ADAPTER 339 #ifdef DEBUG_PLUGIN_ADAPTER
242 std::cerr << "PluginAdapterBase::vampInstantiate(" << desc << "): returning handle " << plugin << std::endl; 340 std::cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << "): returning handle " << plugin << std::endl;
243 #endif 341 #endif
244 342
245 return plugin; 343 return plugin;
246 } 344 }
247 345
248 void 346 void
249 PluginAdapterBase::vampCleanup(VampPluginHandle handle) 347 PluginAdapterBase::Impl::vampCleanup(VampPluginHandle handle)
250 { 348 {
251 #ifdef DEBUG_PLUGIN_ADAPTER 349 #ifdef DEBUG_PLUGIN_ADAPTER
252 std::cerr << "PluginAdapterBase::vampCleanup(" << handle << ")" << std::endl; 350 std::cerr << "PluginAdapterBase::Impl::vampCleanup(" << handle << ")" << std::endl;
253 #endif 351 #endif
254 352
255 PluginAdapterBase *adapter = lookupAdapter(handle); 353 Impl *adapter = lookupAdapter(handle);
256 if (!adapter) { 354 if (!adapter) {
257 delete ((Plugin *)handle); 355 delete ((Plugin *)handle);
258 return; 356 return;
259 } 357 }
260 adapter->cleanup(((Plugin *)handle)); 358 adapter->cleanup(((Plugin *)handle));
261 } 359 }
262 360
263 int 361 int
264 PluginAdapterBase::vampInitialise(VampPluginHandle handle, 362 PluginAdapterBase::Impl::vampInitialise(VampPluginHandle handle,
265 unsigned int channels, 363 unsigned int channels,
266 unsigned int stepSize, 364 unsigned int stepSize,
267 unsigned int blockSize) 365 unsigned int blockSize)
268 { 366 {
269 #ifdef DEBUG_PLUGIN_ADAPTER 367 #ifdef DEBUG_PLUGIN_ADAPTER
270 std::cerr << "PluginAdapterBase::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << std::endl; 368 std::cerr << "PluginAdapterBase::Impl::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << std::endl;
271 #endif 369 #endif
272 370
273 bool result = ((Plugin *)handle)->initialise 371 bool result = ((Plugin *)handle)->initialise
274 (channels, stepSize, blockSize); 372 (channels, stepSize, blockSize);
275 return result ? 1 : 0; 373 return result ? 1 : 0;
276 } 374 }
277 375
278 void 376 void
279 PluginAdapterBase::vampReset(VampPluginHandle handle) 377 PluginAdapterBase::Impl::vampReset(VampPluginHandle handle)
280 { 378 {
281 #ifdef DEBUG_PLUGIN_ADAPTER 379 #ifdef DEBUG_PLUGIN_ADAPTER
282 std::cerr << "PluginAdapterBase::vampReset(" << handle << ")" << std::endl; 380 std::cerr << "PluginAdapterBase::Impl::vampReset(" << handle << ")" << std::endl;
283 #endif 381 #endif
284 382
285 ((Plugin *)handle)->reset(); 383 ((Plugin *)handle)->reset();
286 } 384 }
287 385
288 float 386 float
289 PluginAdapterBase::vampGetParameter(VampPluginHandle handle, 387 PluginAdapterBase::Impl::vampGetParameter(VampPluginHandle handle,
290 int param) 388 int param)
291 { 389 {
292 #ifdef DEBUG_PLUGIN_ADAPTER 390 #ifdef DEBUG_PLUGIN_ADAPTER
293 std::cerr << "PluginAdapterBase::vampGetParameter(" << handle << ", " << param << ")" << std::endl; 391 std::cerr << "PluginAdapterBase::Impl::vampGetParameter(" << handle << ", " << param << ")" << std::endl;
294 #endif 392 #endif
295 393
296 PluginAdapterBase *adapter = lookupAdapter(handle); 394 Impl *adapter = lookupAdapter(handle);
297 if (!adapter) return 0.0; 395 if (!adapter) return 0.0;
298 Plugin::ParameterList &list = adapter->m_parameters; 396 Plugin::ParameterList &list = adapter->m_parameters;
299 return ((Plugin *)handle)->getParameter(list[param].identifier); 397 return ((Plugin *)handle)->getParameter(list[param].identifier);
300 } 398 }
301 399
302 void 400 void
303 PluginAdapterBase::vampSetParameter(VampPluginHandle handle, 401 PluginAdapterBase::Impl::vampSetParameter(VampPluginHandle handle,
304 int param, float value) 402 int param, float value)
305 { 403 {
306 #ifdef DEBUG_PLUGIN_ADAPTER 404 #ifdef DEBUG_PLUGIN_ADAPTER
307 std::cerr << "PluginAdapterBase::vampSetParameter(" << handle << ", " << param << ", " << value << ")" << std::endl; 405 std::cerr << "PluginAdapterBase::Impl::vampSetParameter(" << handle << ", " << param << ", " << value << ")" << std::endl;
308 #endif 406 #endif
309 407
310 PluginAdapterBase *adapter = lookupAdapter(handle); 408 Impl *adapter = lookupAdapter(handle);
311 if (!adapter) return; 409 if (!adapter) return;
312 Plugin::ParameterList &list = adapter->m_parameters; 410 Plugin::ParameterList &list = adapter->m_parameters;
313 ((Plugin *)handle)->setParameter(list[param].identifier, value); 411 ((Plugin *)handle)->setParameter(list[param].identifier, value);
314 } 412 }
315 413
316 unsigned int 414 unsigned int
317 PluginAdapterBase::vampGetCurrentProgram(VampPluginHandle handle) 415 PluginAdapterBase::Impl::vampGetCurrentProgram(VampPluginHandle handle)
318 { 416 {
319 #ifdef DEBUG_PLUGIN_ADAPTER 417 #ifdef DEBUG_PLUGIN_ADAPTER
320 std::cerr << "PluginAdapterBase::vampGetCurrentProgram(" << handle << ")" << std::endl; 418 std::cerr << "PluginAdapterBase::Impl::vampGetCurrentProgram(" << handle << ")" << std::endl;
321 #endif 419 #endif
322 420
323 PluginAdapterBase *adapter = lookupAdapter(handle); 421 Impl *adapter = lookupAdapter(handle);
324 if (!adapter) return 0; 422 if (!adapter) return 0;
325 Plugin::ProgramList &list = adapter->m_programs; 423 Plugin::ProgramList &list = adapter->m_programs;
326 std::string program = ((Plugin *)handle)->getCurrentProgram(); 424 std::string program = ((Plugin *)handle)->getCurrentProgram();
327 for (unsigned int i = 0; i < list.size(); ++i) { 425 for (unsigned int i = 0; i < list.size(); ++i) {
328 if (list[i] == program) return i; 426 if (list[i] == program) return i;
329 } 427 }
330 return 0; 428 return 0;
331 } 429 }
332 430
333 void 431 void
334 PluginAdapterBase::vampSelectProgram(VampPluginHandle handle, 432 PluginAdapterBase::Impl::vampSelectProgram(VampPluginHandle handle,
335 unsigned int program) 433 unsigned int program)
336 { 434 {
337 #ifdef DEBUG_PLUGIN_ADAPTER 435 #ifdef DEBUG_PLUGIN_ADAPTER
338 std::cerr << "PluginAdapterBase::vampSelectProgram(" << handle << ", " << program << ")" << std::endl; 436 std::cerr << "PluginAdapterBase::Impl::vampSelectProgram(" << handle << ", " << program << ")" << std::endl;
339 #endif 437 #endif
340 438
341 PluginAdapterBase *adapter = lookupAdapter(handle); 439 Impl *adapter = lookupAdapter(handle);
342 if (!adapter) return; 440 if (!adapter) return;
343 Plugin::ProgramList &list = adapter->m_programs; 441 Plugin::ProgramList &list = adapter->m_programs;
344 ((Plugin *)handle)->selectProgram(list[program]); 442 ((Plugin *)handle)->selectProgram(list[program]);
345 } 443 }
346 444
347 unsigned int 445 unsigned int
348 PluginAdapterBase::vampGetPreferredStepSize(VampPluginHandle handle) 446 PluginAdapterBase::Impl::vampGetPreferredStepSize(VampPluginHandle handle)
349 { 447 {
350 #ifdef DEBUG_PLUGIN_ADAPTER 448 #ifdef DEBUG_PLUGIN_ADAPTER
351 std::cerr << "PluginAdapterBase::vampGetPreferredStepSize(" << handle << ")" << std::endl; 449 std::cerr << "PluginAdapterBase::Impl::vampGetPreferredStepSize(" << handle << ")" << std::endl;
352 #endif 450 #endif
353 451
354 return ((Plugin *)handle)->getPreferredStepSize(); 452 return ((Plugin *)handle)->getPreferredStepSize();
355 } 453 }
356 454
357 unsigned int 455 unsigned int
358 PluginAdapterBase::vampGetPreferredBlockSize(VampPluginHandle handle) 456 PluginAdapterBase::Impl::vampGetPreferredBlockSize(VampPluginHandle handle)
359 { 457 {
360 #ifdef DEBUG_PLUGIN_ADAPTER 458 #ifdef DEBUG_PLUGIN_ADAPTER
361 std::cerr << "PluginAdapterBase::vampGetPreferredBlockSize(" << handle << ")" << std::endl; 459 std::cerr << "PluginAdapterBase::Impl::vampGetPreferredBlockSize(" << handle << ")" << std::endl;
362 #endif 460 #endif
363 461
364 return ((Plugin *)handle)->getPreferredBlockSize(); 462 return ((Plugin *)handle)->getPreferredBlockSize();
365 } 463 }
366 464
367 unsigned int 465 unsigned int
368 PluginAdapterBase::vampGetMinChannelCount(VampPluginHandle handle) 466 PluginAdapterBase::Impl::vampGetMinChannelCount(VampPluginHandle handle)
369 { 467 {
370 #ifdef DEBUG_PLUGIN_ADAPTER 468 #ifdef DEBUG_PLUGIN_ADAPTER
371 std::cerr << "PluginAdapterBase::vampGetMinChannelCount(" << handle << ")" << std::endl; 469 std::cerr << "PluginAdapterBase::Impl::vampGetMinChannelCount(" << handle << ")" << std::endl;
372 #endif 470 #endif
373 471
374 return ((Plugin *)handle)->getMinChannelCount(); 472 return ((Plugin *)handle)->getMinChannelCount();
375 } 473 }
376 474
377 unsigned int 475 unsigned int
378 PluginAdapterBase::vampGetMaxChannelCount(VampPluginHandle handle) 476 PluginAdapterBase::Impl::vampGetMaxChannelCount(VampPluginHandle handle)
379 { 477 {
380 #ifdef DEBUG_PLUGIN_ADAPTER 478 #ifdef DEBUG_PLUGIN_ADAPTER
381 std::cerr << "PluginAdapterBase::vampGetMaxChannelCount(" << handle << ")" << std::endl; 479 std::cerr << "PluginAdapterBase::Impl::vampGetMaxChannelCount(" << handle << ")" << std::endl;
382 #endif 480 #endif
383 481
384 return ((Plugin *)handle)->getMaxChannelCount(); 482 return ((Plugin *)handle)->getMaxChannelCount();
385 } 483 }
386 484
387 unsigned int 485 unsigned int
388 PluginAdapterBase::vampGetOutputCount(VampPluginHandle handle) 486 PluginAdapterBase::Impl::vampGetOutputCount(VampPluginHandle handle)
389 { 487 {
390 #ifdef DEBUG_PLUGIN_ADAPTER 488 #ifdef DEBUG_PLUGIN_ADAPTER
391 std::cerr << "PluginAdapterBase::vampGetOutputCount(" << handle << ")" << std::endl; 489 std::cerr << "PluginAdapterBase::Impl::vampGetOutputCount(" << handle << ")" << std::endl;
392 #endif 490 #endif
393 491
394 PluginAdapterBase *adapter = lookupAdapter(handle); 492 Impl *adapter = lookupAdapter(handle);
395 493
396 // std::cerr << "vampGetOutputCount: handle " << handle << " -> adapter "<< adapter << std::endl; 494 // std::cerr << "vampGetOutputCount: handle " << handle << " -> adapter "<< adapter << std::endl;
397 495
398 if (!adapter) return 0; 496 if (!adapter) return 0;
399 return adapter->getOutputCount((Plugin *)handle); 497 return adapter->getOutputCount((Plugin *)handle);
400 } 498 }
401 499
402 VampOutputDescriptor * 500 VampOutputDescriptor *
403 PluginAdapterBase::vampGetOutputDescriptor(VampPluginHandle handle, 501 PluginAdapterBase::Impl::vampGetOutputDescriptor(VampPluginHandle handle,
404 unsigned int i) 502 unsigned int i)
405 { 503 {
406 #ifdef DEBUG_PLUGIN_ADAPTER 504 #ifdef DEBUG_PLUGIN_ADAPTER
407 std::cerr << "PluginAdapterBase::vampGetOutputDescriptor(" << handle << ", " << i << ")" << std::endl; 505 std::cerr << "PluginAdapterBase::Impl::vampGetOutputDescriptor(" << handle << ", " << i << ")" << std::endl;
408 #endif 506 #endif
409 507
410 PluginAdapterBase *adapter = lookupAdapter(handle); 508 Impl *adapter = lookupAdapter(handle);
411 509
412 // std::cerr << "vampGetOutputDescriptor: handle " << handle << " -> adapter "<< adapter << std::endl; 510 // std::cerr << "vampGetOutputDescriptor: handle " << handle << " -> adapter "<< adapter << std::endl;
413 511
414 if (!adapter) return 0; 512 if (!adapter) return 0;
415 return adapter->getOutputDescriptor((Plugin *)handle, i); 513 return adapter->getOutputDescriptor((Plugin *)handle, i);
416 } 514 }
417 515
418 void 516 void
419 PluginAdapterBase::vampReleaseOutputDescriptor(VampOutputDescriptor *desc) 517 PluginAdapterBase::Impl::vampReleaseOutputDescriptor(VampOutputDescriptor *desc)
420 { 518 {
421 #ifdef DEBUG_PLUGIN_ADAPTER 519 #ifdef DEBUG_PLUGIN_ADAPTER
422 std::cerr << "PluginAdapterBase::vampReleaseOutputDescriptor(" << desc << ")" << std::endl; 520 std::cerr << "PluginAdapterBase::Impl::vampReleaseOutputDescriptor(" << desc << ")" << std::endl;
423 #endif 521 #endif
424 522
425 if (desc->identifier) free((void *)desc->identifier); 523 if (desc->identifier) free((void *)desc->identifier);
426 if (desc->name) free((void *)desc->name); 524 if (desc->name) free((void *)desc->name);
427 if (desc->description) free((void *)desc->description); 525 if (desc->description) free((void *)desc->description);
436 if (desc->binNames) free((void *)desc->binNames); 534 if (desc->binNames) free((void *)desc->binNames);
437 free((void *)desc); 535 free((void *)desc);
438 } 536 }
439 537
440 VampFeatureList * 538 VampFeatureList *
441 PluginAdapterBase::vampProcess(VampPluginHandle handle, 539 PluginAdapterBase::Impl::vampProcess(VampPluginHandle handle,
442 const float *const *inputBuffers, 540 const float *const *inputBuffers,
443 int sec, 541 int sec,
444 int nsec) 542 int nsec)
445 { 543 {
446 #ifdef DEBUG_PLUGIN_ADAPTER 544 #ifdef DEBUG_PLUGIN_ADAPTER
447 std::cerr << "PluginAdapterBase::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << std::endl; 545 std::cerr << "PluginAdapterBase::Impl::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << std::endl;
448 #endif 546 #endif
449 547
450 PluginAdapterBase *adapter = lookupAdapter(handle); 548 Impl *adapter = lookupAdapter(handle);
451 if (!adapter) return 0; 549 if (!adapter) return 0;
452 return adapter->process((Plugin *)handle, 550 return adapter->process((Plugin *)handle,
453 inputBuffers, sec, nsec); 551 inputBuffers, sec, nsec);
454 } 552 }
455 553
456 VampFeatureList * 554 VampFeatureList *
457 PluginAdapterBase::vampGetRemainingFeatures(VampPluginHandle handle) 555 PluginAdapterBase::Impl::vampGetRemainingFeatures(VampPluginHandle handle)
458 { 556 {
459 #ifdef DEBUG_PLUGIN_ADAPTER 557 #ifdef DEBUG_PLUGIN_ADAPTER
460 std::cerr << "PluginAdapterBase::vampGetRemainingFeatures(" << handle << ")" << std::endl; 558 std::cerr << "PluginAdapterBase::Impl::vampGetRemainingFeatures(" << handle << ")" << std::endl;
461 #endif 559 #endif
462 560
463 PluginAdapterBase *adapter = lookupAdapter(handle); 561 Impl *adapter = lookupAdapter(handle);
464 if (!adapter) return 0; 562 if (!adapter) return 0;
465 return adapter->getRemainingFeatures((Plugin *)handle); 563 return adapter->getRemainingFeatures((Plugin *)handle);
466 } 564 }
467 565
468 void 566 void
469 PluginAdapterBase::vampReleaseFeatureSet(VampFeatureList *fs) 567 PluginAdapterBase::Impl::vampReleaseFeatureSet(VampFeatureList *fs)
470 { 568 {
471 #ifdef DEBUG_PLUGIN_ADAPTER 569 #ifdef DEBUG_PLUGIN_ADAPTER
472 std::cerr << "PluginAdapterBase::vampReleaseFeatureSet" << std::endl; 570 std::cerr << "PluginAdapterBase::Impl::vampReleaseFeatureSet" << std::endl;
473 #endif 571 #endif
474 } 572 }
475 573
476 void 574 void
477 PluginAdapterBase::cleanup(Plugin *plugin) 575 PluginAdapterBase::Impl::cleanup(Plugin *plugin)
478 { 576 {
479 if (m_fs.find(plugin) != m_fs.end()) { 577 if (m_fs.find(plugin) != m_fs.end()) {
480 size_t outputCount = 0; 578 size_t outputCount = 0;
481 if (m_pluginOutputs[plugin]) { 579 if (m_pluginOutputs[plugin]) {
482 outputCount = m_pluginOutputs[plugin]->size(); 580 outputCount = m_pluginOutputs[plugin]->size();
514 612
515 delete ((Plugin *)plugin); 613 delete ((Plugin *)plugin);
516 } 614 }
517 615
518 void 616 void
519 PluginAdapterBase::checkOutputMap(Plugin *plugin) 617 PluginAdapterBase::Impl::checkOutputMap(Plugin *plugin)
520 { 618 {
521 if (m_pluginOutputs.find(plugin) == m_pluginOutputs.end() || 619 if (m_pluginOutputs.find(plugin) == m_pluginOutputs.end() ||
522 !m_pluginOutputs[plugin]) { 620 !m_pluginOutputs[plugin]) {
523 m_pluginOutputs[plugin] = new Plugin::OutputList 621 m_pluginOutputs[plugin] = new Plugin::OutputList
524 (plugin->getOutputDescriptors()); 622 (plugin->getOutputDescriptors());
525 // std::cerr << "PluginAdapterBase::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << std::endl; 623 // std::cerr << "PluginAdapterBase::Impl::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << std::endl;
526 } 624 }
527 } 625 }
528 626
529 unsigned int 627 unsigned int
530 PluginAdapterBase::getOutputCount(Plugin *plugin) 628 PluginAdapterBase::Impl::getOutputCount(Plugin *plugin)
531 { 629 {
532 checkOutputMap(plugin); 630 checkOutputMap(plugin);
533 return m_pluginOutputs[plugin]->size(); 631 return m_pluginOutputs[plugin]->size();
534 } 632 }
535 633
536 VampOutputDescriptor * 634 VampOutputDescriptor *
537 PluginAdapterBase::getOutputDescriptor(Plugin *plugin, 635 PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin,
538 unsigned int i) 636 unsigned int i)
539 { 637 {
540 checkOutputMap(plugin); 638 checkOutputMap(plugin);
541 Plugin::OutputDescriptor &od = 639 Plugin::OutputDescriptor &od =
542 (*m_pluginOutputs[plugin])[i]; 640 (*m_pluginOutputs[plugin])[i];
585 683
586 return desc; 684 return desc;
587 } 685 }
588 686
589 VampFeatureList * 687 VampFeatureList *
590 PluginAdapterBase::process(Plugin *plugin, 688 PluginAdapterBase::Impl::process(Plugin *plugin,
591 const float *const *inputBuffers, 689 const float *const *inputBuffers,
592 int sec, int nsec) 690 int sec, int nsec)
593 { 691 {
594 // std::cerr << "PluginAdapterBase::process" << std::endl; 692 // std::cerr << "PluginAdapterBase::Impl::process" << std::endl;
595 RealTime rt(sec, nsec); 693 RealTime rt(sec, nsec);
596 checkOutputMap(plugin); 694 checkOutputMap(plugin);
597 return convertFeatures(plugin, plugin->process(inputBuffers, rt)); 695 return convertFeatures(plugin, plugin->process(inputBuffers, rt));
598 } 696 }
599 697
600 VampFeatureList * 698 VampFeatureList *
601 PluginAdapterBase::getRemainingFeatures(Plugin *plugin) 699 PluginAdapterBase::Impl::getRemainingFeatures(Plugin *plugin)
602 { 700 {
603 // std::cerr << "PluginAdapterBase::getRemainingFeatures" << std::endl; 701 // std::cerr << "PluginAdapterBase::Impl::getRemainingFeatures" << std::endl;
604 checkOutputMap(plugin); 702 checkOutputMap(plugin);
605 return convertFeatures(plugin, plugin->getRemainingFeatures()); 703 return convertFeatures(plugin, plugin->getRemainingFeatures());
606 } 704 }
607 705
608 VampFeatureList * 706 VampFeatureList *
609 PluginAdapterBase::convertFeatures(Plugin *plugin, 707 PluginAdapterBase::Impl::convertFeatures(Plugin *plugin,
610 const Plugin::FeatureSet &features) 708 const Plugin::FeatureSet &features)
611 { 709 {
612 int lastN = -1; 710 int lastN = -1;
613 711
614 int outputCount = 0; 712 int outputCount = 0;
620 for (Plugin::FeatureSet::const_iterator fi = features.begin(); 718 for (Plugin::FeatureSet::const_iterator fi = features.begin();
621 fi != features.end(); ++fi) { 719 fi != features.end(); ++fi) {
622 720
623 int n = fi->first; 721 int n = fi->first;
624 722
625 // std::cerr << "PluginAdapterBase::convertFeatures: n = " << n << std::endl; 723 // std::cerr << "PluginAdapterBase::Impl::convertFeatures: n = " << n << std::endl;
626 724
627 if (n >= int(outputCount)) { 725 if (n >= int(outputCount)) {
628 std::cerr << "WARNING: PluginAdapterBase::convertFeatures: Too many outputs from plugin (" << n+1 << ", only should be " << outputCount << ")" << std::endl; 726 std::cerr << "WARNING: PluginAdapterBase::Impl::convertFeatures: Too many outputs from plugin (" << n+1 << ", only should be " << outputCount << ")" << std::endl;
629 continue; 727 continue;
630 } 728 }
631 729
632 if (n > lastN + 1) { 730 if (n > lastN + 1) {
633 for (int i = lastN + 1; i < n; ++i) { 731 for (int i = lastN + 1; i < n; ++i) {
641 if (sz > m_fsizes[plugin][n]) resizeFL(plugin, n, sz); 739 if (sz > m_fsizes[plugin][n]) resizeFL(plugin, n, sz);
642 fs[n].featureCount = sz; 740 fs[n].featureCount = sz;
643 741
644 for (size_t j = 0; j < sz; ++j) { 742 for (size_t j = 0; j < sz; ++j) {
645 743
646 // std::cerr << "PluginAdapterBase::convertFeatures: j = " << j << std::endl; 744 // std::cerr << "PluginAdapterBase::Impl::convertFeatures: j = " << j << std::endl;
647 745
648 VampFeature *feature = &fs[n].features[j]; 746 VampFeature *feature = &fs[n].features[j];
649 747
650 feature->hasTimestamp = fl[j].hasTimestamp; 748 feature->hasTimestamp = fl[j].hasTimestamp;
651 feature->sec = fl[j].timestamp.sec; 749 feature->sec = fl[j].timestamp.sec;
663 if (feature->valueCount > m_fvsizes[plugin][n][j]) { 761 if (feature->valueCount > m_fvsizes[plugin][n][j]) {
664 resizeFV(plugin, n, j, feature->valueCount); 762 resizeFV(plugin, n, j, feature->valueCount);
665 } 763 }
666 764
667 for (unsigned int k = 0; k < feature->valueCount; ++k) { 765 for (unsigned int k = 0; k < feature->valueCount; ++k) {
668 // std::cerr << "PluginAdapterBase::convertFeatures: k = " << k << std::endl; 766 // std::cerr << "PluginAdapterBase::Impl::convertFeatures: k = " << k << std::endl;
669 feature->values[k] = fl[j].values[k]; 767 feature->values[k] = fl[j].values[k];
670 } 768 }
671 } 769 }
672 770
673 lastN = n; 771 lastN = n;
683 781
684 return fs; 782 return fs;
685 } 783 }
686 784
687 void 785 void
688 PluginAdapterBase::resizeFS(Plugin *plugin, int n) 786 PluginAdapterBase::Impl::resizeFS(Plugin *plugin, int n)
689 { 787 {
690 // std::cerr << "PluginAdapterBase::resizeFS(" << plugin << ", " << n << ")" << std::endl; 788 // std::cerr << "PluginAdapterBase::Impl::resizeFS(" << plugin << ", " << n << ")" << std::endl;
691 789
692 int i = m_fsizes[plugin].size(); 790 int i = m_fsizes[plugin].size();
693 if (i >= n) return; 791 if (i >= n) return;
694 792
695 // std::cerr << "resizing from " << i << std::endl; 793 // std::cerr << "resizing from " << i << std::endl;
705 i++; 803 i++;
706 } 804 }
707 } 805 }
708 806
709 void 807 void
710 PluginAdapterBase::resizeFL(Plugin *plugin, int n, size_t sz) 808 PluginAdapterBase::Impl::resizeFL(Plugin *plugin, int n, size_t sz)
711 { 809 {
712 // std::cerr << "PluginAdapterBase::resizeFL(" << plugin << ", " << n << ", " 810 // std::cerr << "PluginAdapterBase::Impl::resizeFL(" << plugin << ", " << n << ", "
713 // << sz << ")" << std::endl; 811 // << sz << ")" << std::endl;
714 812
715 size_t i = m_fsizes[plugin][n]; 813 size_t i = m_fsizes[plugin][n];
716 if (i >= sz) return; 814 if (i >= sz) return;
717 815
728 m_fsizes[plugin][n]++; 826 m_fsizes[plugin][n]++;
729 } 827 }
730 } 828 }
731 829
732 void 830 void
733 PluginAdapterBase::resizeFV(Plugin *plugin, int n, int j, size_t sz) 831 PluginAdapterBase::Impl::resizeFV(Plugin *plugin, int n, int j, size_t sz)
734 { 832 {
735 // std::cerr << "PluginAdapterBase::resizeFV(" << plugin << ", " << n << ", " 833 // std::cerr << "PluginAdapterBase::Impl::resizeFV(" << plugin << ", " << n << ", "
736 // << j << ", " << sz << ")" << std::endl; 834 // << j << ", " << sz << ")" << std::endl;
737 835
738 size_t i = m_fvsizes[plugin][n][j]; 836 size_t i = m_fvsizes[plugin][n][j];
739 if (i >= sz) return; 837 if (i >= sz) return;
740 838
744 (m_fs[plugin][n].features[j].values, sz * sizeof(float)); 842 (m_fs[plugin][n].features[j].values, sz * sizeof(float));
745 843
746 m_fvsizes[plugin][n][j] = sz; 844 m_fvsizes[plugin][n][j] = sz;
747 } 845 }
748 846
749 PluginAdapterBase::AdapterMap * 847 PluginAdapterBase::Impl::AdapterMap *
750 PluginAdapterBase::m_adapterMap = 0; 848 PluginAdapterBase::Impl::m_adapterMap = 0;
751 849
752 } 850 }
753 851