Revision 532:569fc23fa37a src/vamp-sdk/PluginAdapter.cpp
| src/vamp-sdk/PluginAdapter.cpp | ||
|---|---|---|
| 39 | 39 |
#include <cstring> |
| 40 | 40 |
#include <cstdlib> |
| 41 | 41 |
|
| 42 |
#if ( VAMP_SDK_MAJOR_VERSION != 2 || VAMP_SDK_MINOR_VERSION != 8 ) |
|
| 42 |
#include <mutex> |
|
| 43 |
|
|
| 44 |
#if ( VAMP_SDK_MAJOR_VERSION != 2 || VAMP_SDK_MINOR_VERSION != 9 ) |
|
| 43 | 45 |
#error Unexpected version of Vamp SDK header included |
| 44 | 46 |
#endif |
| 45 | 47 |
|
| 48 |
using std::map; |
|
| 49 |
using std::vector; |
|
| 50 |
using std::string; |
|
| 51 |
using std::cerr; |
|
| 52 |
using std::endl; |
|
| 53 |
using std::mutex; |
|
| 54 |
using std::lock_guard; |
|
| 46 | 55 |
|
| 47 | 56 |
//#define DEBUG_PLUGIN_ADAPTER 1 |
| 48 | 57 |
|
| ... | ... | |
| 103 | 112 |
|
| 104 | 113 |
void cleanup(Plugin *plugin); |
| 105 | 114 |
unsigned int getOutputCount(Plugin *plugin); |
| 106 |
VampOutputDescriptor *getOutputDescriptor(Plugin *plugin, |
|
| 107 |
unsigned int i); |
|
| 115 |
VampOutputDescriptor *getOutputDescriptor(Plugin *plugin, unsigned int i); |
|
| 108 | 116 |
VampFeatureList *process(Plugin *plugin, |
| 109 | 117 |
const float *const *inputBuffers, |
| 110 | 118 |
int sec, int nsec); |
| ... | ... | |
| 113 | 121 |
const Plugin::FeatureSet &features); |
| 114 | 122 |
|
| 115 | 123 |
// maps both plugins and descriptors to adapters |
| 116 |
typedef std::map<const void *, Impl *> AdapterMap; |
|
| 124 |
typedef map<const void *, Impl *> AdapterMap; |
|
| 125 |
|
|
| 117 | 126 |
static AdapterMap *m_adapterMap; |
| 127 |
|
|
| 128 |
static mutex &adapterMapMutex() {
|
|
| 129 |
// If this mutex was a global static, then it might be |
|
| 130 |
// destroyed before the last adapter, and we would end up |
|
| 131 |
// trying to lock an invalid mutex when removing an adapter |
|
| 132 |
// from the adapter map. To ensure it outlasts the adapters, |
|
| 133 |
// we need to ensure it is constructed before the construction |
|
| 134 |
// of any of them is complete, since destruction order is |
|
| 135 |
// reverse of construction. So we have to make sure this is |
|
| 136 |
// called from the PluginAdapterBase::Impl constructor below. |
|
| 137 |
static mutex m; |
|
| 138 |
return m; |
|
| 139 |
} |
|
| 140 |
|
|
| 118 | 141 |
static Impl *lookupAdapter(VampPluginHandle); |
| 119 | 142 |
|
| 143 |
mutex m_mutex; // guards all of the below |
|
| 144 |
|
|
| 120 | 145 |
bool m_populated; |
| 121 | 146 |
VampPluginDescriptor m_descriptor; |
| 122 | 147 |
Plugin::ParameterList m_parameters; |
| 123 | 148 |
Plugin::ProgramList m_programs; |
| 124 | 149 |
|
| 125 |
typedef std::map<Plugin *, Plugin::OutputList *> OutputMap;
|
|
| 150 |
typedef map<Plugin *, Plugin::OutputList *> OutputMap; |
|
| 126 | 151 |
OutputMap m_pluginOutputs; |
| 127 | 152 |
|
| 128 |
std::map<Plugin *, VampFeatureList *> m_fs;
|
|
| 129 |
std::map<Plugin *, std::vector<size_t> > m_fsizes;
|
|
| 130 |
std::map<Plugin *, std::vector<std::vector<size_t> > > m_fvsizes;
|
|
| 153 |
map<Plugin *, VampFeatureList *> m_fs; |
|
| 154 |
map<Plugin *, vector<size_t> > m_fsizes;
|
|
| 155 |
map<Plugin *, vector<vector<size_t> > > m_fvsizes;
|
|
| 131 | 156 |
void resizeFS(Plugin *plugin, int n); |
| 132 | 157 |
void resizeFL(Plugin *plugin, int n, size_t sz); |
| 133 | 158 |
void resizeFV(Plugin *plugin, int n, int j, size_t sz); |
| ... | ... | |
| 154 | 179 |
m_populated(false) |
| 155 | 180 |
{
|
| 156 | 181 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 157 |
std::cerr << "PluginAdapterBase::Impl[" << this << "]::Impl" << std::endl;
|
|
| 182 |
cerr << "PluginAdapterBase::Impl[" << this << "]::Impl" << endl;
|
|
| 158 | 183 |
#endif |
| 184 |
|
|
| 185 |
(void)adapterMapMutex(); // see comment in adapterMapMutex function above |
|
| 159 | 186 |
} |
| 160 | 187 |
|
| 161 | 188 |
const VampPluginDescriptor * |
| 162 | 189 |
PluginAdapterBase::Impl::getDescriptor() |
| 163 | 190 |
{
|
| 164 | 191 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 165 |
std::cerr << "PluginAdapterBase::Impl[" << this << "]::getDescriptor" << std::endl;
|
|
| 192 |
cerr << "PluginAdapterBase::Impl[" << this << "]::getDescriptor" << endl;
|
|
| 166 | 193 |
#endif |
| 167 | 194 |
|
| 195 |
lock_guard<mutex> guard(m_mutex); |
|
| 196 |
|
|
| 168 | 197 |
if (m_populated) return &m_descriptor; |
| 169 | 198 |
|
| 170 | 199 |
Plugin *plugin = m_base->createPlugin(48000); |
| 171 | 200 |
|
| 172 | 201 |
if (!plugin) {
|
| 173 |
std::cerr << "PluginAdapterBase::Impl::getDescriptor: Failed to create plugin" << std::endl;
|
|
| 202 |
cerr << "PluginAdapterBase::Impl::getDescriptor: Failed to create plugin" << endl;
|
|
| 174 | 203 |
return 0; |
| 175 | 204 |
} |
| 176 | 205 |
|
| 177 | 206 |
if (plugin->getVampApiVersion() != VAMP_API_VERSION) {
|
| 178 |
std::cerr << "Vamp::PluginAdapterBase::Impl::getDescriptor: ERROR: "
|
|
| 179 |
<< "API version " << plugin->getVampApiVersion()
|
|
| 180 |
<< " for\nplugin \"" << plugin->getIdentifier() << "\" "
|
|
| 181 |
<< "differs from version "
|
|
| 182 |
<< VAMP_API_VERSION << " for adapter.\n"
|
|
| 183 |
<< "This plugin is probably linked against a different version of the Vamp SDK\n"
|
|
| 184 |
<< "from the version it was compiled with. It will need to be re-linked correctly\n"
|
|
| 185 |
<< "before it can be used." << std::endl;
|
|
| 207 |
cerr << "Vamp::PluginAdapterBase::Impl::getDescriptor: ERROR: " |
|
| 208 |
<< "API version " << plugin->getVampApiVersion() |
|
| 209 |
<< " for\nplugin \"" << plugin->getIdentifier() << "\" " |
|
| 210 |
<< "differs from version " |
|
| 211 |
<< VAMP_API_VERSION << " for adapter.\n" |
|
| 212 |
<< "This plugin is probably linked against a different version of the Vamp SDK\n" |
|
| 213 |
<< "from the version it was compiled with. It will need to be re-linked correctly\n" |
|
| 214 |
<< "before it can be used." << endl;
|
|
| 186 | 215 |
delete plugin; |
| 187 | 216 |
return 0; |
| 188 | 217 |
} |
| ... | ... | |
| 260 | 289 |
m_descriptor.process = vampProcess; |
| 261 | 290 |
m_descriptor.getRemainingFeatures = vampGetRemainingFeatures; |
| 262 | 291 |
m_descriptor.releaseFeatureSet = vampReleaseFeatureSet; |
| 292 |
|
|
| 293 |
lock_guard<mutex> adapterMapGuard(adapterMapMutex()); |
|
| 263 | 294 |
|
| 264 | 295 |
if (!m_adapterMap) {
|
| 265 | 296 |
m_adapterMap = new AdapterMap; |
| ... | ... | |
| 275 | 306 |
PluginAdapterBase::Impl::~Impl() |
| 276 | 307 |
{
|
| 277 | 308 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 278 |
std::cerr << "PluginAdapterBase::Impl[" << this << "]::~Impl" << std::endl;
|
|
| 309 |
cerr << "PluginAdapterBase::Impl[" << this << "]::~Impl" << endl;
|
|
| 279 | 310 |
#endif |
| 280 | 311 |
|
| 312 |
lock_guard<mutex> guard(m_mutex); |
|
| 313 |
|
|
| 281 | 314 |
if (!m_populated) return; |
| 282 | 315 |
|
| 283 | 316 |
free((void *)m_descriptor.identifier); |
| ... | ... | |
| 307 | 340 |
} |
| 308 | 341 |
free((void *)m_descriptor.programs); |
| 309 | 342 |
|
| 343 |
lock_guard<mutex> adapterMapGuard(adapterMapMutex()); |
|
| 344 |
|
|
| 310 | 345 |
if (m_adapterMap) {
|
| 311 | 346 |
|
| 312 | 347 |
m_adapterMap->erase(&m_descriptor); |
| 313 |
|
|
| 348 |
|
|
| 314 | 349 |
if (m_adapterMap->empty()) {
|
| 315 | 350 |
delete m_adapterMap; |
| 316 | 351 |
m_adapterMap = 0; |
| ... | ... | |
| 322 | 357 |
PluginAdapterBase::Impl::lookupAdapter(VampPluginHandle handle) |
| 323 | 358 |
{
|
| 324 | 359 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 325 |
std::cerr << "PluginAdapterBase::Impl::lookupAdapter(" << handle << ")" << std::endl;
|
|
| 360 |
cerr << "PluginAdapterBase::Impl::lookupAdapter(" << handle << ")" << endl;
|
|
| 326 | 361 |
#endif |
| 327 | 362 |
|
| 363 |
lock_guard<mutex> adapterMapGuard(adapterMapMutex()); |
|
| 364 |
|
|
| 328 | 365 |
if (!m_adapterMap) return 0; |
| 329 | 366 |
AdapterMap::const_iterator i = m_adapterMap->find(handle); |
| 330 | 367 |
if (i == m_adapterMap->end()) return 0; |
| ... | ... | |
| 336 | 373 |
float inputSampleRate) |
| 337 | 374 |
{
|
| 338 | 375 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 339 |
std::cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << ")" << std::endl;
|
|
| 376 |
cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << ")" << endl;
|
|
| 340 | 377 |
#endif |
| 341 | 378 |
|
| 379 |
lock_guard<mutex> adapterMapGuard(adapterMapMutex()); |
|
| 380 |
|
|
| 342 | 381 |
if (!m_adapterMap) {
|
| 343 | 382 |
m_adapterMap = new AdapterMap(); |
| 344 | 383 |
} |
| 345 | 384 |
|
| 346 | 385 |
if (m_adapterMap->find(desc) == m_adapterMap->end()) {
|
| 347 |
std::cerr << "WARNING: PluginAdapterBase::Impl::vampInstantiate: Descriptor " << desc << " not in adapter map" << std::endl;
|
|
| 386 |
cerr << "WARNING: PluginAdapterBase::Impl::vampInstantiate: Descriptor " << desc << " not in adapter map" << endl;
|
|
| 348 | 387 |
return 0; |
| 349 | 388 |
} |
| 350 | 389 |
|
| ... | ... | |
| 357 | 396 |
} |
| 358 | 397 |
|
| 359 | 398 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 360 |
std::cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << "): returning handle " << plugin << std::endl;
|
|
| 399 |
cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << "): returning handle " << plugin << endl;
|
|
| 361 | 400 |
#endif |
| 362 | 401 |
|
| 363 | 402 |
return plugin; |
| ... | ... | |
| 367 | 406 |
PluginAdapterBase::Impl::vampCleanup(VampPluginHandle handle) |
| 368 | 407 |
{
|
| 369 | 408 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 370 |
std::cerr << "PluginAdapterBase::Impl::vampCleanup(" << handle << ")" << std::endl;
|
|
| 409 |
cerr << "PluginAdapterBase::Impl::vampCleanup(" << handle << ")" << endl;
|
|
| 371 | 410 |
#endif |
| 372 | 411 |
|
| 373 | 412 |
Impl *adapter = lookupAdapter(handle); |
| ... | ... | |
| 385 | 424 |
unsigned int blockSize) |
| 386 | 425 |
{
|
| 387 | 426 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 388 |
std::cerr << "PluginAdapterBase::Impl::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << std::endl;
|
|
| 427 |
cerr << "PluginAdapterBase::Impl::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << endl;
|
|
| 389 | 428 |
#endif |
| 390 | 429 |
|
| 391 | 430 |
Impl *adapter = lookupAdapter(handle); |
| ... | ... | |
| 399 | 438 |
PluginAdapterBase::Impl::vampReset(VampPluginHandle handle) |
| 400 | 439 |
{
|
| 401 | 440 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 402 |
std::cerr << "PluginAdapterBase::Impl::vampReset(" << handle << ")" << std::endl;
|
|
| 441 |
cerr << "PluginAdapterBase::Impl::vampReset(" << handle << ")" << endl;
|
|
| 403 | 442 |
#endif |
| 404 | 443 |
|
| 405 | 444 |
((Plugin *)handle)->reset(); |
| ... | ... | |
| 410 | 449 |
int param) |
| 411 | 450 |
{
|
| 412 | 451 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 413 |
std::cerr << "PluginAdapterBase::Impl::vampGetParameter(" << handle << ", " << param << ")" << std::endl;
|
|
| 452 |
cerr << "PluginAdapterBase::Impl::vampGetParameter(" << handle << ", " << param << ")" << endl;
|
|
| 414 | 453 |
#endif |
| 415 | 454 |
|
| 416 | 455 |
Impl *adapter = lookupAdapter(handle); |
| ... | ... | |
| 424 | 463 |
int param, float value) |
| 425 | 464 |
{
|
| 426 | 465 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 427 |
std::cerr << "PluginAdapterBase::Impl::vampSetParameter(" << handle << ", " << param << ", " << value << ")" << std::endl;
|
|
| 466 |
cerr << "PluginAdapterBase::Impl::vampSetParameter(" << handle << ", " << param << ", " << value << ")" << endl;
|
|
| 428 | 467 |
#endif |
| 429 | 468 |
|
| 430 | 469 |
Impl *adapter = lookupAdapter(handle); |
| ... | ... | |
| 438 | 477 |
PluginAdapterBase::Impl::vampGetCurrentProgram(VampPluginHandle handle) |
| 439 | 478 |
{
|
| 440 | 479 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 441 |
std::cerr << "PluginAdapterBase::Impl::vampGetCurrentProgram(" << handle << ")" << std::endl;
|
|
| 480 |
cerr << "PluginAdapterBase::Impl::vampGetCurrentProgram(" << handle << ")" << endl;
|
|
| 442 | 481 |
#endif |
| 443 | 482 |
|
| 444 | 483 |
Impl *adapter = lookupAdapter(handle); |
| 445 | 484 |
if (!adapter) return 0; |
| 446 | 485 |
Plugin::ProgramList &list = adapter->m_programs; |
| 447 |
std::string program = ((Plugin *)handle)->getCurrentProgram();
|
|
| 486 |
string program = ((Plugin *)handle)->getCurrentProgram(); |
|
| 448 | 487 |
for (unsigned int i = 0; i < list.size(); ++i) {
|
| 449 | 488 |
if (list[i] == program) return i; |
| 450 | 489 |
} |
| ... | ... | |
| 456 | 495 |
unsigned int program) |
| 457 | 496 |
{
|
| 458 | 497 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 459 |
std::cerr << "PluginAdapterBase::Impl::vampSelectProgram(" << handle << ", " << program << ")" << std::endl;
|
|
| 498 |
cerr << "PluginAdapterBase::Impl::vampSelectProgram(" << handle << ", " << program << ")" << endl;
|
|
| 460 | 499 |
#endif |
| 461 | 500 |
|
| 462 | 501 |
Impl *adapter = lookupAdapter(handle); |
| ... | ... | |
| 472 | 511 |
PluginAdapterBase::Impl::vampGetPreferredStepSize(VampPluginHandle handle) |
| 473 | 512 |
{
|
| 474 | 513 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 475 |
std::cerr << "PluginAdapterBase::Impl::vampGetPreferredStepSize(" << handle << ")" << std::endl;
|
|
| 514 |
cerr << "PluginAdapterBase::Impl::vampGetPreferredStepSize(" << handle << ")" << endl;
|
|
| 476 | 515 |
#endif |
| 477 | 516 |
|
| 478 | 517 |
return ((Plugin *)handle)->getPreferredStepSize(); |
| ... | ... | |
| 482 | 521 |
PluginAdapterBase::Impl::vampGetPreferredBlockSize(VampPluginHandle handle) |
| 483 | 522 |
{
|
| 484 | 523 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 485 |
std::cerr << "PluginAdapterBase::Impl::vampGetPreferredBlockSize(" << handle << ")" << std::endl;
|
|
| 524 |
cerr << "PluginAdapterBase::Impl::vampGetPreferredBlockSize(" << handle << ")" << endl;
|
|
| 486 | 525 |
#endif |
| 487 | 526 |
|
| 488 | 527 |
return ((Plugin *)handle)->getPreferredBlockSize(); |
| ... | ... | |
| 492 | 531 |
PluginAdapterBase::Impl::vampGetMinChannelCount(VampPluginHandle handle) |
| 493 | 532 |
{
|
| 494 | 533 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 495 |
std::cerr << "PluginAdapterBase::Impl::vampGetMinChannelCount(" << handle << ")" << std::endl;
|
|
| 534 |
cerr << "PluginAdapterBase::Impl::vampGetMinChannelCount(" << handle << ")" << endl;
|
|
| 496 | 535 |
#endif |
| 497 | 536 |
|
| 498 | 537 |
return ((Plugin *)handle)->getMinChannelCount(); |
| ... | ... | |
| 502 | 541 |
PluginAdapterBase::Impl::vampGetMaxChannelCount(VampPluginHandle handle) |
| 503 | 542 |
{
|
| 504 | 543 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 505 |
std::cerr << "PluginAdapterBase::Impl::vampGetMaxChannelCount(" << handle << ")" << std::endl;
|
|
| 544 |
cerr << "PluginAdapterBase::Impl::vampGetMaxChannelCount(" << handle << ")" << endl;
|
|
| 506 | 545 |
#endif |
| 507 | 546 |
|
| 508 | 547 |
return ((Plugin *)handle)->getMaxChannelCount(); |
| ... | ... | |
| 512 | 551 |
PluginAdapterBase::Impl::vampGetOutputCount(VampPluginHandle handle) |
| 513 | 552 |
{
|
| 514 | 553 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 515 |
std::cerr << "PluginAdapterBase::Impl::vampGetOutputCount(" << handle << ")" << std::endl;
|
|
| 554 |
cerr << "PluginAdapterBase::Impl::vampGetOutputCount(" << handle << ")" << endl;
|
|
| 516 | 555 |
#endif |
| 517 | 556 |
|
| 518 | 557 |
Impl *adapter = lookupAdapter(handle); |
| 519 | 558 |
|
| 520 |
// std::cerr << "vampGetOutputCount: handle " << handle << " -> adapter "<< adapter << std::endl;
|
|
| 559 |
// cerr << "vampGetOutputCount: handle " << handle << " -> adapter "<< adapter << endl;
|
|
| 521 | 560 |
|
| 522 | 561 |
if (!adapter) return 0; |
| 523 | 562 |
return adapter->getOutputCount((Plugin *)handle); |
| ... | ... | |
| 528 | 567 |
unsigned int i) |
| 529 | 568 |
{
|
| 530 | 569 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 531 |
std::cerr << "PluginAdapterBase::Impl::vampGetOutputDescriptor(" << handle << ", " << i << ")" << std::endl;
|
|
| 570 |
cerr << "PluginAdapterBase::Impl::vampGetOutputDescriptor(" << handle << ", " << i << ")" << endl;
|
|
| 532 | 571 |
#endif |
| 533 | 572 |
|
| 534 | 573 |
Impl *adapter = lookupAdapter(handle); |
| 535 | 574 |
|
| 536 |
// std::cerr << "vampGetOutputDescriptor: handle " << handle << " -> adapter "<< adapter << std::endl;
|
|
| 575 |
// cerr << "vampGetOutputDescriptor: handle " << handle << " -> adapter "<< adapter << endl;
|
|
| 537 | 576 |
|
| 538 | 577 |
if (!adapter) return 0; |
| 539 | 578 |
return adapter->getOutputDescriptor((Plugin *)handle, i); |
| ... | ... | |
| 543 | 582 |
PluginAdapterBase::Impl::vampReleaseOutputDescriptor(VampOutputDescriptor *desc) |
| 544 | 583 |
{
|
| 545 | 584 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 546 |
std::cerr << "PluginAdapterBase::Impl::vampReleaseOutputDescriptor(" << desc << ")" << std::endl;
|
|
| 585 |
cerr << "PluginAdapterBase::Impl::vampReleaseOutputDescriptor(" << desc << ")" << endl;
|
|
| 547 | 586 |
#endif |
| 548 | 587 |
|
| 549 | 588 |
if (desc->identifier) free((void *)desc->identifier); |
| ... | ... | |
| 568 | 607 |
int nsec) |
| 569 | 608 |
{
|
| 570 | 609 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 571 |
std::cerr << "PluginAdapterBase::Impl::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << std::endl;
|
|
| 610 |
cerr << "PluginAdapterBase::Impl::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << endl;
|
|
| 572 | 611 |
#endif |
| 573 | 612 |
|
| 574 | 613 |
Impl *adapter = lookupAdapter(handle); |
| ... | ... | |
| 580 | 619 |
PluginAdapterBase::Impl::vampGetRemainingFeatures(VampPluginHandle handle) |
| 581 | 620 |
{
|
| 582 | 621 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 583 |
std::cerr << "PluginAdapterBase::Impl::vampGetRemainingFeatures(" << handle << ")" << std::endl;
|
|
| 622 |
cerr << "PluginAdapterBase::Impl::vampGetRemainingFeatures(" << handle << ")" << endl;
|
|
| 584 | 623 |
#endif |
| 585 | 624 |
|
| 586 | 625 |
Impl *adapter = lookupAdapter(handle); |
| ... | ... | |
| 592 | 631 |
PluginAdapterBase::Impl::vampReleaseFeatureSet(VampFeatureList *) |
| 593 | 632 |
{
|
| 594 | 633 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 595 |
std::cerr << "PluginAdapterBase::Impl::vampReleaseFeatureSet" << std::endl;
|
|
| 634 |
cerr << "PluginAdapterBase::Impl::vampReleaseFeatureSet" << endl;
|
|
| 596 | 635 |
#endif |
| 597 | 636 |
} |
| 598 | 637 |
|
| 599 | 638 |
void |
| 600 | 639 |
PluginAdapterBase::Impl::cleanup(Plugin *plugin) |
| 601 | 640 |
{
|
| 641 |
// at this point no mutex is held |
|
| 642 |
|
|
| 643 |
lock_guard<mutex> adapterMapGuard(adapterMapMutex()); |
|
| 644 |
lock_guard<mutex> guard(m_mutex); |
|
| 645 |
|
|
| 602 | 646 |
if (m_fs.find(plugin) != m_fs.end()) {
|
| 603 | 647 |
size_t outputCount = 0; |
| 604 | 648 |
if (m_pluginOutputs[plugin]) {
|
| 605 | 649 |
outputCount = m_pluginOutputs[plugin]->size(); |
| 606 | 650 |
} |
| 607 | 651 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 608 |
std::cerr << "PluginAdapterBase::Impl::cleanup: " << outputCount << " output(s)" << std::endl;
|
|
| 652 |
cerr << "PluginAdapterBase::Impl::cleanup: " << outputCount << " output(s)" << endl;
|
|
| 609 | 653 |
#endif |
| 610 | 654 |
VampFeatureList *list = m_fs[plugin]; |
| 611 | 655 |
for (unsigned int i = 0; i < outputCount; ++i) {
|
| ... | ... | |
| 645 | 689 |
void |
| 646 | 690 |
PluginAdapterBase::Impl::checkOutputMap(Plugin *plugin) |
| 647 | 691 |
{
|
| 692 |
// must be called with m_mutex held |
|
| 693 |
|
|
| 648 | 694 |
OutputMap::iterator i = m_pluginOutputs.find(plugin); |
| 649 | 695 |
|
| 650 | 696 |
if (i == m_pluginOutputs.end() || !i->second) {
|
| ... | ... | |
| 652 | 698 |
m_pluginOutputs[plugin] = new Plugin::OutputList |
| 653 | 699 |
(plugin->getOutputDescriptors()); |
| 654 | 700 |
|
| 655 |
// std::cerr << "PluginAdapterBase::Impl::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << std::endl;
|
|
| 701 |
// cerr << "PluginAdapterBase::Impl::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << endl;
|
|
| 656 | 702 |
} |
| 657 | 703 |
} |
| 658 | 704 |
|
| 659 | 705 |
void |
| 660 | 706 |
PluginAdapterBase::Impl::markOutputsChanged(Plugin *plugin) |
| 661 | 707 |
{
|
| 708 |
lock_guard<mutex> guard(m_mutex); |
|
| 709 |
|
|
| 662 | 710 |
OutputMap::iterator i = m_pluginOutputs.find(plugin); |
| 663 | 711 |
|
| 664 |
// std::cerr << "PluginAdapterBase::Impl::markOutputsChanged" << std::endl;
|
|
| 712 |
// cerr << "PluginAdapterBase::Impl::markOutputsChanged" << endl;
|
|
| 665 | 713 |
|
| 666 | 714 |
if (i != m_pluginOutputs.end()) {
|
| 667 | 715 |
|
| ... | ... | |
| 674 | 722 |
unsigned int |
| 675 | 723 |
PluginAdapterBase::Impl::getOutputCount(Plugin *plugin) |
| 676 | 724 |
{
|
| 725 |
lock_guard<mutex> guard(m_mutex); |
|
| 726 |
|
|
| 677 | 727 |
checkOutputMap(plugin); |
| 678 | 728 |
|
| 679 | 729 |
return m_pluginOutputs[plugin]->size(); |
| ... | ... | |
| 683 | 733 |
PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin, |
| 684 | 734 |
unsigned int i) |
| 685 | 735 |
{
|
| 736 |
lock_guard<mutex> guard(m_mutex); |
|
| 737 |
|
|
| 686 | 738 |
checkOutputMap(plugin); |
| 687 | 739 |
|
| 688 | 740 |
Plugin::OutputDescriptor &od = |
| ... | ... | |
| 744 | 796 |
const float *const *inputBuffers, |
| 745 | 797 |
int sec, int nsec) |
| 746 | 798 |
{
|
| 747 |
// std::cerr << "PluginAdapterBase::Impl::process" << std::endl; |
|
| 799 |
// cerr << "PluginAdapterBase::Impl::process" << endl; |
|
| 800 |
|
|
| 748 | 801 |
RealTime rt(sec, nsec); |
| 749 |
checkOutputMap(plugin); |
|
| 802 |
|
|
| 803 |
// We don't want to hold the mutex during the actual process call, |
|
| 804 |
// only while looking up the associated metadata |
|
| 805 |
{
|
|
| 806 |
lock_guard<mutex> guard(m_mutex); |
|
| 807 |
checkOutputMap(plugin); |
|
| 808 |
} |
|
| 809 |
|
|
| 750 | 810 |
return convertFeatures(plugin, plugin->process(inputBuffers, rt)); |
| 751 | 811 |
} |
| 752 | 812 |
|
| 753 | 813 |
VampFeatureList * |
| 754 | 814 |
PluginAdapterBase::Impl::getRemainingFeatures(Plugin *plugin) |
| 755 | 815 |
{
|
| 756 |
// std::cerr << "PluginAdapterBase::Impl::getRemainingFeatures" << std::endl; |
|
| 757 |
checkOutputMap(plugin); |
|
| 816 |
// cerr << "PluginAdapterBase::Impl::getRemainingFeatures" << endl; |
|
| 817 |
|
|
| 818 |
// We don't want to hold the mutex during the actual call, only |
|
| 819 |
// while looking up the associated metadata |
|
| 820 |
{
|
|
| 821 |
lock_guard<mutex> guard(m_mutex); |
|
| 822 |
checkOutputMap(plugin); |
|
| 823 |
} |
|
| 824 |
|
|
| 758 | 825 |
return convertFeatures(plugin, plugin->getRemainingFeatures()); |
| 759 | 826 |
} |
| 760 | 827 |
|
| ... | ... | |
| 762 | 829 |
PluginAdapterBase::Impl::convertFeatures(Plugin *plugin, |
| 763 | 830 |
const Plugin::FeatureSet &features) |
| 764 | 831 |
{
|
| 832 |
lock_guard<mutex> guard(m_mutex); |
|
| 833 |
|
|
| 765 | 834 |
int lastN = -1; |
| 766 | 835 |
|
| 767 | 836 |
int outputCount = 0; |
| ... | ... | |
| 770 | 839 |
resizeFS(plugin, outputCount); |
| 771 | 840 |
VampFeatureList *fs = m_fs[plugin]; |
| 772 | 841 |
|
| 773 |
// std::cerr << "PluginAdapter(v2)::convertFeatures: NOTE: sizeof(Feature) == " << sizeof(Plugin::Feature) << ", sizeof(VampFeature) == " << sizeof(VampFeature) << ", sizeof(VampFeatureList) == " << sizeof(VampFeatureList) << std::endl;
|
|
| 842 |
// cerr << "PluginAdapter(v2)::convertFeatures: NOTE: sizeof(Feature) == " << sizeof(Plugin::Feature) << ", sizeof(VampFeature) == " << sizeof(VampFeature) << ", sizeof(VampFeatureList) == " << sizeof(VampFeatureList) << endl;
|
|
| 774 | 843 |
|
| 775 | 844 |
for (Plugin::FeatureSet::const_iterator fi = features.begin(); |
| 776 | 845 |
fi != features.end(); ++fi) {
|
| 777 | 846 |
|
| 778 | 847 |
int n = fi->first; |
| 779 | 848 |
|
| 780 |
// std::cerr << "PluginAdapterBase::Impl::convertFeatures: n = " << n << std::endl;
|
|
| 849 |
// cerr << "PluginAdapterBase::Impl::convertFeatures: n = " << n << endl;
|
|
| 781 | 850 |
|
| 782 | 851 |
if (n >= int(outputCount)) {
|
| 783 |
std::cerr << "WARNING: PluginAdapterBase::Impl::convertFeatures: Too many outputs from plugin (" << n+1 << ", only should be " << outputCount << ")" << std::endl;
|
|
| 852 |
cerr << "WARNING: PluginAdapterBase::Impl::convertFeatures: Too many outputs from plugin (" << n+1 << ", only should be " << outputCount << ")" << endl;
|
|
| 784 | 853 |
continue; |
| 785 | 854 |
} |
| 786 | 855 |
|
| ... | ... | |
| 798 | 867 |
|
| 799 | 868 |
for (size_t j = 0; j < sz; ++j) {
|
| 800 | 869 |
|
| 801 |
// std::cerr << "PluginAdapterBase::Impl::convertFeatures: j = " << j << std::endl;
|
|
| 870 |
// cerr << "PluginAdapterBase::Impl::convertFeatures: j = " << j << endl;
|
|
| 802 | 871 |
|
| 803 | 872 |
VampFeature *feature = &fs[n].features[j].v1; |
| 804 | 873 |
|
| ... | ... | |
| 826 | 895 |
} |
| 827 | 896 |
|
| 828 | 897 |
for (unsigned int k = 0; k < feature->valueCount; ++k) {
|
| 829 |
// std::cerr << "PluginAdapterBase::Impl::convertFeatures: k = " << k << std::endl;
|
|
| 898 |
// cerr << "PluginAdapterBase::Impl::convertFeatures: k = " << k << endl;
|
|
| 830 | 899 |
feature->values[k] = fl[j].values[k]; |
| 831 | 900 |
} |
| 832 | 901 |
} |
| ... | ... | |
| 842 | 911 |
} |
| 843 | 912 |
} |
| 844 | 913 |
|
| 845 |
// std::cerr << "PluginAdapter(v2)::convertFeatures: NOTE: have " << outputCount << " outputs" << std::endl;
|
|
| 914 |
// cerr << "PluginAdapter(v2)::convertFeatures: NOTE: have " << outputCount << " outputs" << endl;
|
|
| 846 | 915 |
// for (int i = 0; i < outputCount; ++i) {
|
| 847 |
// std::cerr << "PluginAdapter(v2)::convertFeatures: NOTE: output " << i << " has " << fs[i].featureCount << " features" << std::endl;
|
|
| 916 |
// cerr << "PluginAdapter(v2)::convertFeatures: NOTE: output " << i << " has " << fs[i].featureCount << " features" << endl;
|
|
| 848 | 917 |
// } |
| 849 | 918 |
|
| 850 | 919 |
|
| ... | ... | |
| 854 | 923 |
void |
| 855 | 924 |
PluginAdapterBase::Impl::resizeFS(Plugin *plugin, int n) |
| 856 | 925 |
{
|
| 926 |
// called with m_mutex held |
|
| 927 |
|
|
| 857 | 928 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 858 |
std::cerr << "PluginAdapterBase::Impl::resizeFS(" << plugin << ", " << n << ")" << std::endl;
|
|
| 929 |
cerr << "PluginAdapterBase::Impl::resizeFS(" << plugin << ", " << n << ")" << endl;
|
|
| 859 | 930 |
#endif |
| 860 | 931 |
|
| 861 | 932 |
int i = m_fsizes[plugin].size(); |
| 862 | 933 |
if (i >= n) return; |
| 863 | 934 |
|
| 864 | 935 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 865 |
std::cerr << "resizing from " << i << std::endl;
|
|
| 936 |
cerr << "resizing from " << i << endl;
|
|
| 866 | 937 |
#endif |
| 867 | 938 |
|
| 868 | 939 |
m_fs[plugin] = (VampFeatureList *)realloc |
| ... | ... | |
| 872 | 943 |
m_fs[plugin][i].featureCount = 0; |
| 873 | 944 |
m_fs[plugin][i].features = 0; |
| 874 | 945 |
m_fsizes[plugin].push_back(0); |
| 875 |
m_fvsizes[plugin].push_back(std::vector<size_t>());
|
|
| 946 |
m_fvsizes[plugin].push_back(vector<size_t>()); |
|
| 876 | 947 |
i++; |
| 877 | 948 |
} |
| 878 | 949 |
} |
| ... | ... | |
| 880 | 951 |
void |
| 881 | 952 |
PluginAdapterBase::Impl::resizeFL(Plugin *plugin, int n, size_t sz) |
| 882 | 953 |
{
|
| 954 |
// called with m_mutex held |
|
| 955 |
|
|
| 883 | 956 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 884 |
std::cerr << "PluginAdapterBase::Impl::resizeFL(" << plugin << ", " << n << ", "
|
|
| 885 |
<< sz << ")" << std::endl;
|
|
| 957 |
cerr << "PluginAdapterBase::Impl::resizeFL(" << plugin << ", " << n << ", "
|
|
| 958 |
<< sz << ")" << endl; |
|
| 886 | 959 |
#endif |
| 887 | 960 |
|
| 888 | 961 |
size_t i = m_fsizes[plugin][n]; |
| 889 | 962 |
if (i >= sz) return; |
| 890 | 963 |
|
| 891 | 964 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 892 |
std::cerr << "resizing from " << i << std::endl;
|
|
| 965 |
cerr << "resizing from " << i << endl;
|
|
| 893 | 966 |
#endif |
| 894 | 967 |
|
| 895 | 968 |
m_fs[plugin][n].features = (VampFeatureUnion *)realloc |
| ... | ... | |
| 909 | 982 |
void |
| 910 | 983 |
PluginAdapterBase::Impl::resizeFV(Plugin *plugin, int n, int j, size_t sz) |
| 911 | 984 |
{
|
| 985 |
// called with m_mutex held |
|
| 986 |
|
|
| 912 | 987 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 913 |
std::cerr << "PluginAdapterBase::Impl::resizeFV(" << plugin << ", " << n << ", "
|
|
| 914 |
<< j << ", " << sz << ")" << std::endl;
|
|
| 988 |
cerr << "PluginAdapterBase::Impl::resizeFV(" << plugin << ", " << n << ", "
|
|
| 989 |
<< j << ", " << sz << ")" << endl; |
|
| 915 | 990 |
#endif |
| 916 | 991 |
|
| 917 | 992 |
size_t i = m_fvsizes[plugin][n][j]; |
| 918 | 993 |
if (i >= sz) return; |
| 919 | 994 |
|
| 920 | 995 |
#ifdef DEBUG_PLUGIN_ADAPTER |
| 921 |
std::cerr << "resizing from " << i << std::endl;
|
|
| 996 |
cerr << "resizing from " << i << endl;
|
|
| 922 | 997 |
#endif |
| 923 | 998 |
|
| 924 | 999 |
m_fs[plugin][n].features[j].v1.values = (float *)realloc |
Also available in: Unified diff