annotate src/vamp-sdk/PluginAdapter.cpp @ 535:45b2bd15d8ae

Show error code if library can't be loaded
author Chris Cannam
date Tue, 03 Mar 2020 11:47:52 +0000
parents db2cd87cef6f
children 15a89a89aa9b
rev   line source
cannam@3 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@3 2
cannam@3 3 /*
cannam@3 4 Vamp
cannam@3 5
cannam@3 6 An API for audio analysis and feature extraction plugins.
cannam@3 7
cannam@3 8 Centre for Digital Music, Queen Mary, University of London.
cannam@3 9 Copyright 2006 Chris Cannam.
cannam@3 10
cannam@3 11 Permission is hereby granted, free of charge, to any person
cannam@3 12 obtaining a copy of this software and associated documentation
cannam@3 13 files (the "Software"), to deal in the Software without
cannam@3 14 restriction, including without limitation the rights to use, copy,
cannam@3 15 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@3 16 of the Software, and to permit persons to whom the Software is
cannam@3 17 furnished to do so, subject to the following conditions:
cannam@3 18
cannam@3 19 The above copyright notice and this permission notice shall be
cannam@3 20 included in all copies or substantial portions of the Software.
cannam@3 21
cannam@3 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@3 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@3 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@6 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@3 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@3 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@3 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@3 29
cannam@3 30 Except as contained in this notice, the names of the Centre for
cannam@3 31 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@3 32 shall not be used in advertising or otherwise to promote the sale,
cannam@3 33 use or other dealings in this Software without prior written
cannam@3 34 authorization.
cannam@3 35 */
cannam@3 36
cannam@230 37 #include <vamp-sdk/PluginAdapter.h>
cannam@3 38
cannam@130 39 #include <cstring>
cannam@130 40 #include <cstdlib>
cannam@130 41
Chris@523 42 #include <mutex>
Chris@523 43
Chris@528 44 #if ( VAMP_SDK_MAJOR_VERSION != 2 || VAMP_SDK_MINOR_VERSION != 9 )
cannam@308 45 #error Unexpected version of Vamp SDK header included
cannam@234 46 #endif
cannam@234 47
Chris@523 48 using std::map;
Chris@523 49 using std::vector;
Chris@523 50 using std::string;
Chris@523 51 using std::cerr;
Chris@523 52 using std::endl;
Chris@523 53 using std::mutex;
Chris@523 54 using std::lock_guard;
cannam@234 55
cannam@23 56 //#define DEBUG_PLUGIN_ADAPTER 1
cannam@22 57
cannam@233 58 _VAMP_SDK_PLUGSPACE_BEGIN(PluginAdapter.cpp)
cannam@230 59
cannam@3 60 namespace Vamp {
cannam@3 61
cannam@76 62 class PluginAdapterBase::Impl
cannam@3 63 {
cannam@76 64 public:
cannam@76 65 Impl(PluginAdapterBase *);
cannam@76 66 ~Impl();
cannam@76 67
cannam@76 68 const VampPluginDescriptor *getDescriptor();
cannam@76 69
cannam@76 70 protected:
cannam@76 71 PluginAdapterBase *m_base;
cannam@76 72
cannam@76 73 static VampPluginHandle vampInstantiate(const VampPluginDescriptor *desc,
cannam@167 74 float inputSampleRate);
cannam@76 75
cannam@76 76 static void vampCleanup(VampPluginHandle handle);
cannam@76 77
cannam@76 78 static int vampInitialise(VampPluginHandle handle, unsigned int channels,
cannam@76 79 unsigned int stepSize, unsigned int blockSize);
cannam@76 80
cannam@76 81 static void vampReset(VampPluginHandle handle);
cannam@76 82
cannam@76 83 static float vampGetParameter(VampPluginHandle handle, int param);
cannam@76 84 static void vampSetParameter(VampPluginHandle handle, int param, float value);
cannam@76 85
cannam@76 86 static unsigned int vampGetCurrentProgram(VampPluginHandle handle);
cannam@76 87 static void vampSelectProgram(VampPluginHandle handle, unsigned int program);
cannam@76 88
cannam@76 89 static unsigned int vampGetPreferredStepSize(VampPluginHandle handle);
cannam@76 90 static unsigned int vampGetPreferredBlockSize(VampPluginHandle handle);
cannam@76 91 static unsigned int vampGetMinChannelCount(VampPluginHandle handle);
cannam@76 92 static unsigned int vampGetMaxChannelCount(VampPluginHandle handle);
cannam@76 93
cannam@76 94 static unsigned int vampGetOutputCount(VampPluginHandle handle);
cannam@76 95
cannam@76 96 static VampOutputDescriptor *vampGetOutputDescriptor(VampPluginHandle handle,
cannam@76 97 unsigned int i);
cannam@76 98
cannam@76 99 static void vampReleaseOutputDescriptor(VampOutputDescriptor *desc);
cannam@76 100
cannam@76 101 static VampFeatureList *vampProcess(VampPluginHandle handle,
cannam@76 102 const float *const *inputBuffers,
cannam@76 103 int sec,
cannam@76 104 int nsec);
cannam@76 105
cannam@76 106 static VampFeatureList *vampGetRemainingFeatures(VampPluginHandle handle);
cannam@76 107
cannam@76 108 static void vampReleaseFeatureSet(VampFeatureList *fs);
cannam@76 109
cannam@268 110 void checkOutputMap(Plugin *plugin);
cannam@268 111 void markOutputsChanged(Plugin *plugin);
cannam@268 112
cannam@76 113 void cleanup(Plugin *plugin);
cannam@76 114 unsigned int getOutputCount(Plugin *plugin);
Chris@527 115 VampOutputDescriptor *getOutputDescriptor(Plugin *plugin, unsigned int i);
cannam@76 116 VampFeatureList *process(Plugin *plugin,
cannam@76 117 const float *const *inputBuffers,
cannam@76 118 int sec, int nsec);
cannam@76 119 VampFeatureList *getRemainingFeatures(Plugin *plugin);
cannam@76 120 VampFeatureList *convertFeatures(Plugin *plugin,
cannam@76 121 const Plugin::FeatureSet &features);
cannam@76 122
cannam@76 123 // maps both plugins and descriptors to adapters
Chris@523 124 typedef map<const void *, Impl *> AdapterMap;
Chris@527 125
cannam@76 126 static AdapterMap *m_adapterMap;
Chris@527 127
Chris@527 128 static mutex &adapterMapMutex() {
Chris@527 129 // If this mutex was a global static, then it might be
Chris@527 130 // destroyed before the last adapter, and we would end up
Chris@527 131 // trying to lock an invalid mutex when removing an adapter
Chris@527 132 // from the adapter map. To ensure it outlasts the adapters,
Chris@527 133 // we need to ensure it is constructed before the construction
Chris@527 134 // of any of them is complete, since destruction order is
Chris@527 135 // reverse of construction. So we have to make sure this is
Chris@527 136 // called from the PluginAdapterBase::Impl constructor below.
Chris@527 137 static mutex m;
Chris@527 138 return m;
Chris@527 139 }
Chris@527 140
cannam@76 141 static Impl *lookupAdapter(VampPluginHandle);
cannam@76 142
Chris@523 143 mutex m_mutex; // guards all of the below
Chris@523 144
cannam@76 145 bool m_populated;
cannam@76 146 VampPluginDescriptor m_descriptor;
cannam@76 147 Plugin::ParameterList m_parameters;
cannam@76 148 Plugin::ProgramList m_programs;
cannam@76 149
Chris@523 150 typedef map<Plugin *, Plugin::OutputList *> OutputMap;
cannam@76 151 OutputMap m_pluginOutputs;
cannam@76 152
Chris@523 153 map<Plugin *, VampFeatureList *> m_fs;
Chris@523 154 map<Plugin *, vector<size_t> > m_fsizes;
Chris@523 155 map<Plugin *, vector<vector<size_t> > > m_fvsizes;
cannam@76 156 void resizeFS(Plugin *plugin, int n);
cannam@76 157 void resizeFL(Plugin *plugin, int n, size_t sz);
cannam@76 158 void resizeFV(Plugin *plugin, int n, int j, size_t sz);
cannam@76 159 };
cannam@76 160
cannam@76 161 PluginAdapterBase::PluginAdapterBase()
cannam@76 162 {
cannam@76 163 m_impl = new Impl(this);
cannam@76 164 }
cannam@76 165
cannam@76 166 PluginAdapterBase::~PluginAdapterBase()
cannam@76 167 {
cannam@76 168 delete m_impl;
cannam@3 169 }
cannam@3 170
cannam@3 171 const VampPluginDescriptor *
cannam@3 172 PluginAdapterBase::getDescriptor()
cannam@3 173 {
cannam@76 174 return m_impl->getDescriptor();
cannam@76 175 }
cannam@76 176
cannam@76 177 PluginAdapterBase::Impl::Impl(PluginAdapterBase *base) :
cannam@76 178 m_base(base),
cannam@76 179 m_populated(false)
cannam@76 180 {
cannam@22 181 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 182 cerr << "PluginAdapterBase::Impl[" << this << "]::Impl" << endl;
cannam@76 183 #endif
Chris@527 184
Chris@527 185 (void)adapterMapMutex(); // see comment in adapterMapMutex function above
cannam@76 186 }
cannam@76 187
cannam@76 188 const VampPluginDescriptor *
cannam@76 189 PluginAdapterBase::Impl::getDescriptor()
cannam@76 190 {
cannam@76 191 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 192 cerr << "PluginAdapterBase::Impl[" << this << "]::getDescriptor" << endl;
cannam@22 193 #endif
cannam@22 194
Chris@523 195 lock_guard<mutex> guard(m_mutex);
Chris@523 196
cannam@3 197 if (m_populated) return &m_descriptor;
Chris@467 198
cannam@76 199 Plugin *plugin = m_base->createPlugin(48000);
cannam@285 200
cannam@285 201 if (!plugin) {
Chris@523 202 cerr << "PluginAdapterBase::Impl::getDescriptor: Failed to create plugin" << endl;
cannam@285 203 return 0;
cannam@285 204 }
cannam@3 205
cannam@50 206 if (plugin->getVampApiVersion() != VAMP_API_VERSION) {
Chris@523 207 cerr << "Vamp::PluginAdapterBase::Impl::getDescriptor: ERROR: "
Chris@523 208 << "API version " << plugin->getVampApiVersion()
Chris@523 209 << " for\nplugin \"" << plugin->getIdentifier() << "\" "
Chris@523 210 << "differs from version "
Chris@523 211 << VAMP_API_VERSION << " for adapter.\n"
Chris@523 212 << "This plugin is probably linked against a different version of the Vamp SDK\n"
Chris@523 213 << "from the version it was compiled with. It will need to be re-linked correctly\n"
Chris@523 214 << "before it can be used." << endl;
cannam@50 215 delete plugin;
cannam@50 216 return 0;
cannam@50 217 }
cannam@50 218
cannam@3 219 m_parameters = plugin->getParameterDescriptors();
cannam@3 220 m_programs = plugin->getPrograms();
cannam@50 221
cannam@50 222 m_descriptor.vampApiVersion = plugin->getVampApiVersion();
cannam@49 223 m_descriptor.identifier = strdup(plugin->getIdentifier().c_str());
cannam@3 224 m_descriptor.name = strdup(plugin->getName().c_str());
cannam@3 225 m_descriptor.description = strdup(plugin->getDescription().c_str());
cannam@3 226 m_descriptor.maker = strdup(plugin->getMaker().c_str());
cannam@3 227 m_descriptor.pluginVersion = plugin->getPluginVersion();
cannam@3 228 m_descriptor.copyright = strdup(plugin->getCopyright().c_str());
cannam@3 229
cannam@3 230 m_descriptor.parameterCount = m_parameters.size();
cannam@3 231 m_descriptor.parameters = (const VampParameterDescriptor **)
cannam@3 232 malloc(m_parameters.size() * sizeof(VampParameterDescriptor));
cannam@7 233
cannam@7 234 unsigned int i;
cannam@3 235
cannam@7 236 for (i = 0; i < m_parameters.size(); ++i) {
cannam@3 237 VampParameterDescriptor *desc = (VampParameterDescriptor *)
cannam@3 238 malloc(sizeof(VampParameterDescriptor));
cannam@49 239 desc->identifier = strdup(m_parameters[i].identifier.c_str());
cannam@3 240 desc->name = strdup(m_parameters[i].name.c_str());
cannam@3 241 desc->description = strdup(m_parameters[i].description.c_str());
cannam@3 242 desc->unit = strdup(m_parameters[i].unit.c_str());
cannam@3 243 desc->minValue = m_parameters[i].minValue;
cannam@3 244 desc->maxValue = m_parameters[i].maxValue;
cannam@3 245 desc->defaultValue = m_parameters[i].defaultValue;
cannam@3 246 desc->isQuantized = m_parameters[i].isQuantized;
cannam@3 247 desc->quantizeStep = m_parameters[i].quantizeStep;
cannam@9 248 desc->valueNames = 0;
cannam@9 249 if (desc->isQuantized && !m_parameters[i].valueNames.empty()) {
cannam@9 250 desc->valueNames = (const char **)
cannam@9 251 malloc((m_parameters[i].valueNames.size()+1) * sizeof(char *));
cannam@9 252 for (unsigned int j = 0; j < m_parameters[i].valueNames.size(); ++j) {
cannam@9 253 desc->valueNames[j] = strdup(m_parameters[i].valueNames[j].c_str());
cannam@9 254 }
cannam@9 255 desc->valueNames[m_parameters[i].valueNames.size()] = 0;
cannam@9 256 }
cannam@3 257 m_descriptor.parameters[i] = desc;
cannam@3 258 }
cannam@3 259
cannam@3 260 m_descriptor.programCount = m_programs.size();
cannam@3 261 m_descriptor.programs = (const char **)
cannam@3 262 malloc(m_programs.size() * sizeof(const char *));
cannam@3 263
cannam@7 264 for (i = 0; i < m_programs.size(); ++i) {
cannam@3 265 m_descriptor.programs[i] = strdup(m_programs[i].c_str());
cannam@3 266 }
cannam@3 267
cannam@3 268 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
cannam@3 269 m_descriptor.inputDomain = vampFrequencyDomain;
cannam@3 270 } else {
cannam@3 271 m_descriptor.inputDomain = vampTimeDomain;
cannam@3 272 }
cannam@3 273
cannam@3 274 m_descriptor.instantiate = vampInstantiate;
cannam@3 275 m_descriptor.cleanup = vampCleanup;
cannam@3 276 m_descriptor.initialise = vampInitialise;
cannam@3 277 m_descriptor.reset = vampReset;
cannam@3 278 m_descriptor.getParameter = vampGetParameter;
cannam@3 279 m_descriptor.setParameter = vampSetParameter;
cannam@3 280 m_descriptor.getCurrentProgram = vampGetCurrentProgram;
cannam@3 281 m_descriptor.selectProgram = vampSelectProgram;
cannam@3 282 m_descriptor.getPreferredStepSize = vampGetPreferredStepSize;
cannam@3 283 m_descriptor.getPreferredBlockSize = vampGetPreferredBlockSize;
cannam@3 284 m_descriptor.getMinChannelCount = vampGetMinChannelCount;
cannam@3 285 m_descriptor.getMaxChannelCount = vampGetMaxChannelCount;
cannam@3 286 m_descriptor.getOutputCount = vampGetOutputCount;
cannam@3 287 m_descriptor.getOutputDescriptor = vampGetOutputDescriptor;
cannam@3 288 m_descriptor.releaseOutputDescriptor = vampReleaseOutputDescriptor;
cannam@3 289 m_descriptor.process = vampProcess;
cannam@3 290 m_descriptor.getRemainingFeatures = vampGetRemainingFeatures;
cannam@3 291 m_descriptor.releaseFeatureSet = vampReleaseFeatureSet;
Chris@523 292
Chris@527 293 lock_guard<mutex> adapterMapGuard(adapterMapMutex());
cannam@3 294
cannam@13 295 if (!m_adapterMap) {
cannam@13 296 m_adapterMap = new AdapterMap;
cannam@13 297 }
cannam@15 298 (*m_adapterMap)[&m_descriptor] = this;
cannam@3 299
cannam@3 300 delete plugin;
cannam@3 301
cannam@3 302 m_populated = true;
cannam@3 303 return &m_descriptor;
cannam@3 304 }
cannam@3 305
cannam@76 306 PluginAdapterBase::Impl::~Impl()
cannam@3 307 {
cannam@22 308 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 309 cerr << "PluginAdapterBase::Impl[" << this << "]::~Impl" << endl;
cannam@22 310 #endif
cannam@22 311
Chris@523 312 lock_guard<mutex> guard(m_mutex);
Chris@523 313
cannam@3 314 if (!m_populated) return;
cannam@3 315
cannam@49 316 free((void *)m_descriptor.identifier);
cannam@3 317 free((void *)m_descriptor.name);
cannam@3 318 free((void *)m_descriptor.description);
cannam@3 319 free((void *)m_descriptor.maker);
cannam@3 320 free((void *)m_descriptor.copyright);
cannam@3 321
cannam@3 322 for (unsigned int i = 0; i < m_descriptor.parameterCount; ++i) {
cannam@3 323 const VampParameterDescriptor *desc = m_descriptor.parameters[i];
cannam@49 324 free((void *)desc->identifier);
cannam@3 325 free((void *)desc->name);
cannam@3 326 free((void *)desc->description);
cannam@3 327 free((void *)desc->unit);
cannam@9 328 if (desc->valueNames) {
cannam@9 329 for (unsigned int j = 0; desc->valueNames[j]; ++j) {
cannam@9 330 free((void *)desc->valueNames[j]);
cannam@9 331 }
cannam@9 332 free((void *)desc->valueNames);
cannam@9 333 }
Chris@467 334 free((void *)desc);
cannam@3 335 }
cannam@3 336 free((void *)m_descriptor.parameters);
cannam@3 337
cannam@3 338 for (unsigned int i = 0; i < m_descriptor.programCount; ++i) {
cannam@3 339 free((void *)m_descriptor.programs[i]);
cannam@3 340 }
cannam@3 341 free((void *)m_descriptor.programs);
cannam@3 342
Chris@527 343 lock_guard<mutex> adapterMapGuard(adapterMapMutex());
Chris@523 344
cannam@13 345 if (m_adapterMap) {
cannam@13 346
cannam@13 347 m_adapterMap->erase(&m_descriptor);
Chris@525 348
cannam@13 349 if (m_adapterMap->empty()) {
cannam@13 350 delete m_adapterMap;
cannam@13 351 m_adapterMap = 0;
cannam@13 352 }
cannam@13 353 }
cannam@3 354 }
cannam@3 355
cannam@76 356 PluginAdapterBase::Impl *
cannam@76 357 PluginAdapterBase::Impl::lookupAdapter(VampPluginHandle handle)
cannam@3 358 {
cannam@22 359 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 360 cerr << "PluginAdapterBase::Impl::lookupAdapter(" << handle << ")" << endl;
cannam@22 361 #endif
cannam@22 362
Chris@527 363 lock_guard<mutex> adapterMapGuard(adapterMapMutex());
Chris@523 364
cannam@13 365 if (!m_adapterMap) return 0;
cannam@13 366 AdapterMap::const_iterator i = m_adapterMap->find(handle);
cannam@13 367 if (i == m_adapterMap->end()) return 0;
cannam@3 368 return i->second;
cannam@3 369 }
cannam@3 370
cannam@3 371 VampPluginHandle
cannam@76 372 PluginAdapterBase::Impl::vampInstantiate(const VampPluginDescriptor *desc,
cannam@268 373 float inputSampleRate)
cannam@3 374 {
cannam@22 375 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 376 cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << ")" << endl;
cannam@22 377 #endif
cannam@22 378
Chris@527 379 lock_guard<mutex> adapterMapGuard(adapterMapMutex());
Chris@523 380
cannam@15 381 if (!m_adapterMap) {
cannam@15 382 m_adapterMap = new AdapterMap();
cannam@15 383 }
cannam@15 384
cannam@15 385 if (m_adapterMap->find(desc) == m_adapterMap->end()) {
Chris@523 386 cerr << "WARNING: PluginAdapterBase::Impl::vampInstantiate: Descriptor " << desc << " not in adapter map" << endl;
cannam@15 387 return 0;
cannam@15 388 }
cannam@15 389
cannam@76 390 Impl *adapter = (*m_adapterMap)[desc];
cannam@3 391 if (desc != &adapter->m_descriptor) return 0;
cannam@3 392
cannam@76 393 Plugin *plugin = adapter->m_base->createPlugin(inputSampleRate);
cannam@3 394 if (plugin) {
cannam@13 395 (*m_adapterMap)[plugin] = adapter;
cannam@3 396 }
cannam@3 397
cannam@22 398 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 399 cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << "): returning handle " << plugin << endl;
cannam@22 400 #endif
cannam@22 401
cannam@3 402 return plugin;
cannam@3 403 }
cannam@3 404
cannam@3 405 void
cannam@76 406 PluginAdapterBase::Impl::vampCleanup(VampPluginHandle handle)
cannam@3 407 {
cannam@22 408 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 409 cerr << "PluginAdapterBase::Impl::vampCleanup(" << handle << ")" << endl;
cannam@22 410 #endif
cannam@22 411
cannam@76 412 Impl *adapter = lookupAdapter(handle);
cannam@3 413 if (!adapter) {
cannam@3 414 delete ((Plugin *)handle);
cannam@3 415 return;
cannam@3 416 }
cannam@3 417 adapter->cleanup(((Plugin *)handle));
cannam@3 418 }
cannam@3 419
cannam@3 420 int
cannam@76 421 PluginAdapterBase::Impl::vampInitialise(VampPluginHandle handle,
cannam@268 422 unsigned int channels,
cannam@268 423 unsigned int stepSize,
cannam@268 424 unsigned int blockSize)
cannam@3 425 {
cannam@22 426 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 427 cerr << "PluginAdapterBase::Impl::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << endl;
cannam@22 428 #endif
cannam@22 429
cannam@268 430 Impl *adapter = lookupAdapter(handle);
cannam@268 431 if (!adapter) return 0;
cannam@268 432 bool result = ((Plugin *)handle)->initialise(channels, stepSize, blockSize);
cannam@268 433 adapter->markOutputsChanged((Plugin *)handle);
cannam@3 434 return result ? 1 : 0;
cannam@3 435 }
cannam@3 436
cannam@3 437 void
cannam@76 438 PluginAdapterBase::Impl::vampReset(VampPluginHandle handle)
cannam@3 439 {
cannam@22 440 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 441 cerr << "PluginAdapterBase::Impl::vampReset(" << handle << ")" << endl;
cannam@22 442 #endif
cannam@22 443
cannam@3 444 ((Plugin *)handle)->reset();
cannam@3 445 }
cannam@3 446
cannam@3 447 float
cannam@76 448 PluginAdapterBase::Impl::vampGetParameter(VampPluginHandle handle,
cannam@3 449 int param)
cannam@3 450 {
cannam@22 451 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 452 cerr << "PluginAdapterBase::Impl::vampGetParameter(" << handle << ", " << param << ")" << endl;
cannam@22 453 #endif
cannam@22 454
cannam@76 455 Impl *adapter = lookupAdapter(handle);
cannam@3 456 if (!adapter) return 0.0;
cannam@3 457 Plugin::ParameterList &list = adapter->m_parameters;
cannam@49 458 return ((Plugin *)handle)->getParameter(list[param].identifier);
cannam@3 459 }
cannam@3 460
cannam@3 461 void
cannam@76 462 PluginAdapterBase::Impl::vampSetParameter(VampPluginHandle handle,
cannam@3 463 int param, float value)
cannam@3 464 {
cannam@22 465 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 466 cerr << "PluginAdapterBase::Impl::vampSetParameter(" << handle << ", " << param << ", " << value << ")" << endl;
cannam@22 467 #endif
cannam@22 468
cannam@76 469 Impl *adapter = lookupAdapter(handle);
cannam@3 470 if (!adapter) return;
cannam@3 471 Plugin::ParameterList &list = adapter->m_parameters;
cannam@49 472 ((Plugin *)handle)->setParameter(list[param].identifier, value);
cannam@268 473 adapter->markOutputsChanged((Plugin *)handle);
cannam@3 474 }
cannam@3 475
cannam@3 476 unsigned int
cannam@76 477 PluginAdapterBase::Impl::vampGetCurrentProgram(VampPluginHandle handle)
cannam@3 478 {
cannam@22 479 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 480 cerr << "PluginAdapterBase::Impl::vampGetCurrentProgram(" << handle << ")" << endl;
cannam@22 481 #endif
cannam@22 482
cannam@76 483 Impl *adapter = lookupAdapter(handle);
cannam@3 484 if (!adapter) return 0;
cannam@3 485 Plugin::ProgramList &list = adapter->m_programs;
Chris@523 486 string program = ((Plugin *)handle)->getCurrentProgram();
cannam@3 487 for (unsigned int i = 0; i < list.size(); ++i) {
cannam@3 488 if (list[i] == program) return i;
cannam@3 489 }
cannam@3 490 return 0;
cannam@3 491 }
cannam@3 492
cannam@3 493 void
cannam@76 494 PluginAdapterBase::Impl::vampSelectProgram(VampPluginHandle handle,
cannam@268 495 unsigned int program)
cannam@3 496 {
cannam@22 497 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 498 cerr << "PluginAdapterBase::Impl::vampSelectProgram(" << handle << ", " << program << ")" << endl;
cannam@22 499 #endif
cannam@22 500
cannam@76 501 Impl *adapter = lookupAdapter(handle);
cannam@3 502 if (!adapter) return;
cannam@268 503
cannam@3 504 Plugin::ProgramList &list = adapter->m_programs;
cannam@3 505 ((Plugin *)handle)->selectProgram(list[program]);
cannam@268 506
cannam@268 507 adapter->markOutputsChanged((Plugin *)handle);
cannam@3 508 }
cannam@3 509
cannam@3 510 unsigned int
cannam@76 511 PluginAdapterBase::Impl::vampGetPreferredStepSize(VampPluginHandle handle)
cannam@3 512 {
cannam@22 513 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 514 cerr << "PluginAdapterBase::Impl::vampGetPreferredStepSize(" << handle << ")" << endl;
cannam@22 515 #endif
cannam@22 516
cannam@3 517 return ((Plugin *)handle)->getPreferredStepSize();
cannam@3 518 }
cannam@3 519
cannam@3 520 unsigned int
cannam@76 521 PluginAdapterBase::Impl::vampGetPreferredBlockSize(VampPluginHandle handle)
cannam@3 522 {
cannam@22 523 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 524 cerr << "PluginAdapterBase::Impl::vampGetPreferredBlockSize(" << handle << ")" << endl;
cannam@22 525 #endif
cannam@22 526
cannam@3 527 return ((Plugin *)handle)->getPreferredBlockSize();
cannam@3 528 }
cannam@3 529
cannam@3 530 unsigned int
cannam@76 531 PluginAdapterBase::Impl::vampGetMinChannelCount(VampPluginHandle handle)
cannam@3 532 {
cannam@22 533 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 534 cerr << "PluginAdapterBase::Impl::vampGetMinChannelCount(" << handle << ")" << endl;
cannam@22 535 #endif
cannam@22 536
cannam@3 537 return ((Plugin *)handle)->getMinChannelCount();
cannam@3 538 }
cannam@3 539
cannam@3 540 unsigned int
cannam@76 541 PluginAdapterBase::Impl::vampGetMaxChannelCount(VampPluginHandle handle)
cannam@3 542 {
cannam@22 543 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 544 cerr << "PluginAdapterBase::Impl::vampGetMaxChannelCount(" << handle << ")" << endl;
cannam@22 545 #endif
cannam@22 546
cannam@3 547 return ((Plugin *)handle)->getMaxChannelCount();
cannam@3 548 }
cannam@3 549
cannam@3 550 unsigned int
cannam@76 551 PluginAdapterBase::Impl::vampGetOutputCount(VampPluginHandle handle)
cannam@3 552 {
cannam@22 553 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 554 cerr << "PluginAdapterBase::Impl::vampGetOutputCount(" << handle << ")" << endl;
cannam@22 555 #endif
cannam@22 556
cannam@76 557 Impl *adapter = lookupAdapter(handle);
cannam@15 558
Chris@523 559 // cerr << "vampGetOutputCount: handle " << handle << " -> adapter "<< adapter << endl;
cannam@15 560
cannam@3 561 if (!adapter) return 0;
cannam@3 562 return adapter->getOutputCount((Plugin *)handle);
cannam@3 563 }
cannam@3 564
cannam@3 565 VampOutputDescriptor *
cannam@76 566 PluginAdapterBase::Impl::vampGetOutputDescriptor(VampPluginHandle handle,
cannam@268 567 unsigned int i)
cannam@3 568 {
cannam@22 569 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 570 cerr << "PluginAdapterBase::Impl::vampGetOutputDescriptor(" << handle << ", " << i << ")" << endl;
cannam@22 571 #endif
cannam@22 572
cannam@76 573 Impl *adapter = lookupAdapter(handle);
cannam@15 574
Chris@523 575 // cerr << "vampGetOutputDescriptor: handle " << handle << " -> adapter "<< adapter << endl;
cannam@15 576
cannam@3 577 if (!adapter) return 0;
cannam@3 578 return adapter->getOutputDescriptor((Plugin *)handle, i);
cannam@3 579 }
cannam@3 580
cannam@3 581 void
cannam@76 582 PluginAdapterBase::Impl::vampReleaseOutputDescriptor(VampOutputDescriptor *desc)
cannam@3 583 {
cannam@22 584 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 585 cerr << "PluginAdapterBase::Impl::vampReleaseOutputDescriptor(" << desc << ")" << endl;
cannam@22 586 #endif
cannam@22 587
cannam@49 588 if (desc->identifier) free((void *)desc->identifier);
cannam@3 589 if (desc->name) free((void *)desc->name);
cannam@3 590 if (desc->description) free((void *)desc->description);
cannam@3 591 if (desc->unit) free((void *)desc->unit);
cannam@40 592 if (desc->hasFixedBinCount && desc->binNames) {
cannam@40 593 for (unsigned int i = 0; i < desc->binCount; ++i) {
cannam@40 594 if (desc->binNames[i]) {
cannam@40 595 free((void *)desc->binNames[i]);
cannam@40 596 }
cannam@40 597 }
cannam@3 598 }
cannam@9 599 if (desc->binNames) free((void *)desc->binNames);
cannam@3 600 free((void *)desc);
cannam@3 601 }
cannam@3 602
cannam@12 603 VampFeatureList *
cannam@76 604 PluginAdapterBase::Impl::vampProcess(VampPluginHandle handle,
cannam@108 605 const float *const *inputBuffers,
cannam@108 606 int sec,
cannam@108 607 int nsec)
cannam@3 608 {
cannam@22 609 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 610 cerr << "PluginAdapterBase::Impl::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << endl;
cannam@22 611 #endif
cannam@22 612
cannam@76 613 Impl *adapter = lookupAdapter(handle);
cannam@3 614 if (!adapter) return 0;
cannam@268 615 return adapter->process((Plugin *)handle, inputBuffers, sec, nsec);
cannam@3 616 }
cannam@3 617
cannam@12 618 VampFeatureList *
cannam@76 619 PluginAdapterBase::Impl::vampGetRemainingFeatures(VampPluginHandle handle)
cannam@3 620 {
cannam@22 621 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 622 cerr << "PluginAdapterBase::Impl::vampGetRemainingFeatures(" << handle << ")" << endl;
cannam@22 623 #endif
cannam@22 624
cannam@76 625 Impl *adapter = lookupAdapter(handle);
cannam@3 626 if (!adapter) return 0;
cannam@3 627 return adapter->getRemainingFeatures((Plugin *)handle);
cannam@3 628 }
cannam@3 629
cannam@3 630 void
Chris@398 631 PluginAdapterBase::Impl::vampReleaseFeatureSet(VampFeatureList *)
cannam@3 632 {
cannam@22 633 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 634 cerr << "PluginAdapterBase::Impl::vampReleaseFeatureSet" << endl;
cannam@22 635 #endif
cannam@3 636 }
cannam@3 637
cannam@3 638 void
cannam@76 639 PluginAdapterBase::Impl::cleanup(Plugin *plugin)
cannam@3 640 {
Chris@523 641 // at this point no mutex is held
Chris@523 642
Chris@527 643 lock_guard<mutex> adapterMapGuard(adapterMapMutex());
Chris@523 644 lock_guard<mutex> guard(m_mutex);
Chris@523 645
cannam@12 646 if (m_fs.find(plugin) != m_fs.end()) {
cannam@12 647 size_t outputCount = 0;
cannam@12 648 if (m_pluginOutputs[plugin]) {
cannam@12 649 outputCount = m_pluginOutputs[plugin]->size();
cannam@12 650 }
Chris@471 651 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 652 cerr << "PluginAdapterBase::Impl::cleanup: " << outputCount << " output(s)" << endl;
Chris@471 653 #endif
cannam@12 654 VampFeatureList *list = m_fs[plugin];
cannam@12 655 for (unsigned int i = 0; i < outputCount; ++i) {
cannam@12 656 for (unsigned int j = 0; j < m_fsizes[plugin][i]; ++j) {
cannam@168 657 if (list[i].features[j].v1.label) {
cannam@168 658 free(list[i].features[j].v1.label);
cannam@12 659 }
cannam@168 660 if (list[i].features[j].v1.values) {
cannam@168 661 free(list[i].features[j].v1.values);
cannam@12 662 }
cannam@12 663 }
cannam@12 664 if (list[i].features) free(list[i].features);
cannam@12 665 }
Chris@467 666 if (list) free((void *)list);
cannam@12 667 m_fs.erase(plugin);
cannam@12 668 m_fsizes.erase(plugin);
cannam@12 669 m_fvsizes.erase(plugin);
cannam@12 670 }
cannam@12 671
cannam@3 672 if (m_pluginOutputs.find(plugin) != m_pluginOutputs.end()) {
cannam@3 673 delete m_pluginOutputs[plugin];
cannam@3 674 m_pluginOutputs.erase(plugin);
cannam@3 675 }
cannam@13 676
cannam@13 677 if (m_adapterMap) {
cannam@13 678 m_adapterMap->erase(plugin);
cannam@13 679
cannam@13 680 if (m_adapterMap->empty()) {
cannam@13 681 delete m_adapterMap;
cannam@13 682 m_adapterMap = 0;
cannam@13 683 }
cannam@13 684 }
cannam@13 685
cannam@3 686 delete ((Plugin *)plugin);
cannam@3 687 }
cannam@3 688
cannam@3 689 void
cannam@76 690 PluginAdapterBase::Impl::checkOutputMap(Plugin *plugin)
cannam@3 691 {
Chris@523 692 // must be called with m_mutex held
Chris@523 693
cannam@268 694 OutputMap::iterator i = m_pluginOutputs.find(plugin);
cannam@268 695
cannam@268 696 if (i == m_pluginOutputs.end() || !i->second) {
cannam@268 697
cannam@3 698 m_pluginOutputs[plugin] = new Plugin::OutputList
cannam@3 699 (plugin->getOutputDescriptors());
cannam@268 700
Chris@523 701 // cerr << "PluginAdapterBase::Impl::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << endl;
cannam@3 702 }
cannam@3 703 }
cannam@3 704
cannam@268 705 void
cannam@268 706 PluginAdapterBase::Impl::markOutputsChanged(Plugin *plugin)
cannam@268 707 {
Chris@523 708 lock_guard<mutex> guard(m_mutex);
Chris@523 709
cannam@268 710 OutputMap::iterator i = m_pluginOutputs.find(plugin);
cannam@268 711
Chris@523 712 // cerr << "PluginAdapterBase::Impl::markOutputsChanged" << endl;
cannam@268 713
cannam@268 714 if (i != m_pluginOutputs.end()) {
cannam@268 715
cannam@268 716 Plugin::OutputList *list = i->second;
cannam@268 717 m_pluginOutputs.erase(i);
cannam@268 718 delete list;
cannam@268 719 }
cannam@268 720 }
cannam@268 721
cannam@3 722 unsigned int
cannam@76 723 PluginAdapterBase::Impl::getOutputCount(Plugin *plugin)
cannam@3 724 {
Chris@523 725 lock_guard<mutex> guard(m_mutex);
Chris@523 726
cannam@3 727 checkOutputMap(plugin);
cannam@268 728
cannam@3 729 return m_pluginOutputs[plugin]->size();
cannam@3 730 }
cannam@3 731
cannam@3 732 VampOutputDescriptor *
cannam@76 733 PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin,
cannam@268 734 unsigned int i)
cannam@3 735 {
Chris@523 736 lock_guard<mutex> guard(m_mutex);
Chris@523 737
cannam@3 738 checkOutputMap(plugin);
cannam@268 739
cannam@3 740 Plugin::OutputDescriptor &od =
cannam@3 741 (*m_pluginOutputs[plugin])[i];
cannam@3 742
cannam@3 743 VampOutputDescriptor *desc = (VampOutputDescriptor *)
cannam@3 744 malloc(sizeof(VampOutputDescriptor));
cannam@3 745
cannam@49 746 desc->identifier = strdup(od.identifier.c_str());
cannam@3 747 desc->name = strdup(od.name.c_str());
cannam@3 748 desc->description = strdup(od.description.c_str());
cannam@3 749 desc->unit = strdup(od.unit.c_str());
cannam@9 750 desc->hasFixedBinCount = od.hasFixedBinCount;
cannam@9 751 desc->binCount = od.binCount;
cannam@3 752
cannam@240 753 if (od.hasFixedBinCount && od.binCount > 0
cannam@240 754 // We would like to do "&& !od.binNames.empty()" here -- but we
cannam@240 755 // can't, because it will crash older versions of the host adapter
cannam@240 756 // which try to copy the names across whenever the bin count is
cannam@240 757 // non-zero, regardless of whether they exist or not
cannam@240 758 ) {
cannam@9 759 desc->binNames = (const char **)
cannam@9 760 malloc(od.binCount * sizeof(const char *));
cannam@3 761
cannam@9 762 for (unsigned int i = 0; i < od.binCount; ++i) {
cannam@9 763 if (i < od.binNames.size()) {
cannam@9 764 desc->binNames[i] = strdup(od.binNames[i].c_str());
cannam@7 765 } else {
cannam@9 766 desc->binNames[i] = 0;
cannam@7 767 }
cannam@3 768 }
cannam@7 769 } else {
cannam@9 770 desc->binNames = 0;
cannam@3 771 }
cannam@3 772
cannam@3 773 desc->hasKnownExtents = od.hasKnownExtents;
cannam@3 774 desc->minValue = od.minValue;
cannam@3 775 desc->maxValue = od.maxValue;
cannam@3 776 desc->isQuantized = od.isQuantized;
cannam@3 777 desc->quantizeStep = od.quantizeStep;
cannam@3 778
cannam@3 779 switch (od.sampleType) {
cannam@3 780 case Plugin::OutputDescriptor::OneSamplePerStep:
cannam@3 781 desc->sampleType = vampOneSamplePerStep; break;
cannam@3 782 case Plugin::OutputDescriptor::FixedSampleRate:
cannam@3 783 desc->sampleType = vampFixedSampleRate; break;
cannam@3 784 case Plugin::OutputDescriptor::VariableSampleRate:
cannam@3 785 desc->sampleType = vampVariableSampleRate; break;
cannam@3 786 }
cannam@3 787
cannam@3 788 desc->sampleRate = od.sampleRate;
cannam@192 789 desc->hasDuration = od.hasDuration;
cannam@3 790
cannam@3 791 return desc;
cannam@3 792 }
cannam@3 793
cannam@12 794 VampFeatureList *
cannam@76 795 PluginAdapterBase::Impl::process(Plugin *plugin,
cannam@108 796 const float *const *inputBuffers,
cannam@108 797 int sec, int nsec)
cannam@3 798 {
Chris@523 799 // cerr << "PluginAdapterBase::Impl::process" << endl;
Chris@523 800
cannam@3 801 RealTime rt(sec, nsec);
Chris@523 802
Chris@523 803 // We don't want to hold the mutex during the actual process call,
Chris@523 804 // only while looking up the associated metadata
Chris@523 805 {
Chris@523 806 lock_guard<mutex> guard(m_mutex);
Chris@523 807 checkOutputMap(plugin);
Chris@523 808 }
Chris@523 809
cannam@12 810 return convertFeatures(plugin, plugin->process(inputBuffers, rt));
cannam@3 811 }
cannam@3 812
cannam@12 813 VampFeatureList *
cannam@76 814 PluginAdapterBase::Impl::getRemainingFeatures(Plugin *plugin)
cannam@3 815 {
Chris@523 816 // cerr << "PluginAdapterBase::Impl::getRemainingFeatures" << endl;
Chris@523 817
Chris@523 818 // We don't want to hold the mutex during the actual call, only
Chris@523 819 // while looking up the associated metadata
Chris@523 820 {
Chris@523 821 lock_guard<mutex> guard(m_mutex);
Chris@523 822 checkOutputMap(plugin);
Chris@523 823 }
Chris@523 824
cannam@12 825 return convertFeatures(plugin, plugin->getRemainingFeatures());
cannam@3 826 }
cannam@3 827
cannam@12 828 VampFeatureList *
cannam@76 829 PluginAdapterBase::Impl::convertFeatures(Plugin *plugin,
cannam@167 830 const Plugin::FeatureSet &features)
cannam@3 831 {
Chris@523 832 lock_guard<mutex> guard(m_mutex);
Chris@523 833
cannam@12 834 int lastN = -1;
cannam@3 835
cannam@12 836 int outputCount = 0;
cannam@12 837 if (m_pluginOutputs[plugin]) outputCount = m_pluginOutputs[plugin]->size();
cannam@12 838
cannam@12 839 resizeFS(plugin, outputCount);
cannam@12 840 VampFeatureList *fs = m_fs[plugin];
cannam@3 841
Chris@523 842 // cerr << "PluginAdapter(v2)::convertFeatures: NOTE: sizeof(Feature) == " << sizeof(Plugin::Feature) << ", sizeof(VampFeature) == " << sizeof(VampFeature) << ", sizeof(VampFeatureList) == " << sizeof(VampFeatureList) << endl;
cannam@168 843
cannam@12 844 for (Plugin::FeatureSet::const_iterator fi = features.begin();
cannam@12 845 fi != features.end(); ++fi) {
cannam@3 846
cannam@12 847 int n = fi->first;
cannam@12 848
Chris@523 849 // cerr << "PluginAdapterBase::Impl::convertFeatures: n = " << n << endl;
cannam@7 850
cannam@12 851 if (n >= int(outputCount)) {
Chris@523 852 cerr << "WARNING: PluginAdapterBase::Impl::convertFeatures: Too many outputs from plugin (" << n+1 << ", only should be " << outputCount << ")" << endl;
cannam@7 853 continue;
cannam@7 854 }
cannam@7 855
cannam@12 856 if (n > lastN + 1) {
cannam@12 857 for (int i = lastN + 1; i < n; ++i) {
cannam@12 858 fs[i].featureCount = 0;
cannam@12 859 }
cannam@12 860 }
cannam@7 861
cannam@7 862 const Plugin::FeatureList &fl = fi->second;
cannam@7 863
cannam@12 864 size_t sz = fl.size();
cannam@12 865 if (sz > m_fsizes[plugin][n]) resizeFL(plugin, n, sz);
cannam@12 866 fs[n].featureCount = sz;
cannam@12 867
cannam@12 868 for (size_t j = 0; j < sz; ++j) {
cannam@7 869
Chris@523 870 // cerr << "PluginAdapterBase::Impl::convertFeatures: j = " << j << endl;
cannam@7 871
cannam@168 872 VampFeature *feature = &fs[n].features[j].v1;
cannam@7 873
cannam@7 874 feature->hasTimestamp = fl[j].hasTimestamp;
cannam@7 875 feature->sec = fl[j].timestamp.sec;
cannam@7 876 feature->nsec = fl[j].timestamp.nsec;
cannam@7 877 feature->valueCount = fl[j].values.size();
cannam@7 878
cannam@168 879 VampFeatureV2 *v2 = &fs[n].features[j + sz].v2;
cannam@167 880
cannam@167 881 v2->hasDuration = fl[j].hasDuration;
cannam@167 882 v2->durationSec = fl[j].duration.sec;
cannam@167 883 v2->durationNsec = fl[j].duration.nsec;
cannam@167 884
cannam@12 885 if (feature->label) free(feature->label);
cannam@12 886
cannam@12 887 if (fl[j].label.empty()) {
cannam@12 888 feature->label = 0;
cannam@12 889 } else {
cannam@12 890 feature->label = strdup(fl[j].label.c_str());
cannam@7 891 }
cannam@7 892
cannam@12 893 if (feature->valueCount > m_fvsizes[plugin][n][j]) {
cannam@12 894 resizeFV(plugin, n, j, feature->valueCount);
cannam@12 895 }
cannam@7 896
cannam@7 897 for (unsigned int k = 0; k < feature->valueCount; ++k) {
Chris@523 898 // cerr << "PluginAdapterBase::Impl::convertFeatures: k = " << k << endl;
cannam@7 899 feature->values[k] = fl[j].values[k];
cannam@3 900 }
cannam@3 901 }
cannam@12 902
cannam@12 903 lastN = n;
cannam@3 904 }
cannam@3 905
cannam@12 906 if (lastN == -1) return 0;
cannam@12 907
cannam@12 908 if (int(outputCount) > lastN + 1) {
cannam@12 909 for (int i = lastN + 1; i < int(outputCount); ++i) {
cannam@12 910 fs[i].featureCount = 0;
cannam@12 911 }
cannam@12 912 }
cannam@3 913
Chris@523 914 // cerr << "PluginAdapter(v2)::convertFeatures: NOTE: have " << outputCount << " outputs" << endl;
cannam@168 915 // for (int i = 0; i < outputCount; ++i) {
Chris@523 916 // cerr << "PluginAdapter(v2)::convertFeatures: NOTE: output " << i << " has " << fs[i].featureCount << " features" << endl;
cannam@168 917 // }
cannam@168 918
cannam@168 919
cannam@3 920 return fs;
cannam@3 921 }
cannam@3 922
cannam@12 923 void
cannam@76 924 PluginAdapterBase::Impl::resizeFS(Plugin *plugin, int n)
cannam@12 925 {
Chris@523 926 // called with m_mutex held
Chris@523 927
Chris@467 928 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 929 cerr << "PluginAdapterBase::Impl::resizeFS(" << plugin << ", " << n << ")" << endl;
Chris@467 930 #endif
cannam@12 931
cannam@12 932 int i = m_fsizes[plugin].size();
cannam@12 933 if (i >= n) return;
cannam@12 934
Chris@467 935 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 936 cerr << "resizing from " << i << endl;
Chris@467 937 #endif
cannam@12 938
cannam@12 939 m_fs[plugin] = (VampFeatureList *)realloc
cannam@12 940 (m_fs[plugin], n * sizeof(VampFeatureList));
cannam@12 941
cannam@12 942 while (i < n) {
cannam@12 943 m_fs[plugin][i].featureCount = 0;
cannam@12 944 m_fs[plugin][i].features = 0;
cannam@12 945 m_fsizes[plugin].push_back(0);
Chris@523 946 m_fvsizes[plugin].push_back(vector<size_t>());
cannam@12 947 i++;
cannam@12 948 }
cannam@12 949 }
cannam@12 950
cannam@12 951 void
cannam@76 952 PluginAdapterBase::Impl::resizeFL(Plugin *plugin, int n, size_t sz)
cannam@12 953 {
Chris@523 954 // called with m_mutex held
Chris@523 955
Chris@467 956 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 957 cerr << "PluginAdapterBase::Impl::resizeFL(" << plugin << ", " << n << ", "
Chris@523 958 << sz << ")" << endl;
Chris@467 959 #endif
Chris@467 960
cannam@12 961 size_t i = m_fsizes[plugin][n];
cannam@12 962 if (i >= sz) return;
cannam@12 963
Chris@467 964 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 965 cerr << "resizing from " << i << endl;
Chris@467 966 #endif
cannam@12 967
cannam@168 968 m_fs[plugin][n].features = (VampFeatureUnion *)realloc
cannam@168 969 (m_fs[plugin][n].features, 2 * sz * sizeof(VampFeatureUnion));
cannam@167 970
cannam@12 971 while (m_fsizes[plugin][n] < sz) {
cannam@168 972 m_fs[plugin][n].features[m_fsizes[plugin][n]].v1.hasTimestamp = 0;
cannam@168 973 m_fs[plugin][n].features[m_fsizes[plugin][n]].v1.valueCount = 0;
cannam@168 974 m_fs[plugin][n].features[m_fsizes[plugin][n]].v1.values = 0;
cannam@168 975 m_fs[plugin][n].features[m_fsizes[plugin][n]].v1.label = 0;
cannam@189 976 m_fs[plugin][n].features[m_fsizes[plugin][n] + sz].v2.hasDuration = 0;
cannam@12 977 m_fvsizes[plugin][n].push_back(0);
cannam@12 978 m_fsizes[plugin][n]++;
cannam@12 979 }
cannam@12 980 }
cannam@12 981
cannam@12 982 void
cannam@76 983 PluginAdapterBase::Impl::resizeFV(Plugin *plugin, int n, int j, size_t sz)
cannam@12 984 {
Chris@523 985 // called with m_mutex held
Chris@523 986
Chris@467 987 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 988 cerr << "PluginAdapterBase::Impl::resizeFV(" << plugin << ", " << n << ", "
Chris@523 989 << j << ", " << sz << ")" << endl;
Chris@467 990 #endif
Chris@467 991
cannam@12 992 size_t i = m_fvsizes[plugin][n][j];
cannam@12 993 if (i >= sz) return;
cannam@12 994
Chris@467 995 #ifdef DEBUG_PLUGIN_ADAPTER
Chris@523 996 cerr << "resizing from " << i << endl;
Chris@467 997 #endif
Chris@467 998
cannam@168 999 m_fs[plugin][n].features[j].v1.values = (float *)realloc
cannam@168 1000 (m_fs[plugin][n].features[j].v1.values, sz * sizeof(float));
cannam@12 1001
cannam@12 1002 m_fvsizes[plugin][n][j] = sz;
cannam@12 1003 }
cannam@12 1004
cannam@76 1005 PluginAdapterBase::Impl::AdapterMap *
cannam@76 1006 PluginAdapterBase::Impl::m_adapterMap = 0;
cannam@3 1007
cannam@3 1008 }
cannam@3 1009
cannam@233 1010 _VAMP_SDK_PLUGSPACE_END(PluginAdapter.cpp)
cannam@230 1011