Mercurial > hg > svcore
comparison plugin/FeatureExtractionPluginFactory.cpp @ 690:1424aa29ae95
Seems to be a bad idea to use plain DEBUG symbol on OS/X (system wants it)
author | Chris Cannam |
---|---|
date | Tue, 14 Jun 2011 15:26:52 +0100 |
parents | 06f13a3b9e9e |
children | e802e550a1f2 |
comparison
equal
deleted
inserted
replaced
689:573d45e9487b | 690:1424aa29ae95 |
---|---|
56 FeatureExtractionPluginFactory * | 56 FeatureExtractionPluginFactory * |
57 FeatureExtractionPluginFactory::instance(QString pluginType) | 57 FeatureExtractionPluginFactory::instance(QString pluginType) |
58 { | 58 { |
59 if (pluginType == "vamp") { | 59 if (pluginType == "vamp") { |
60 if (!_nativeInstance) { | 60 if (!_nativeInstance) { |
61 // DEBUG << "FeatureExtractionPluginFactory::instance(" << pluginType// << "): creating new FeatureExtractionPluginFactory" << endl; | 61 // SVDEBUG << "FeatureExtractionPluginFactory::instance(" << pluginType// << "): creating new FeatureExtractionPluginFactory" << endl; |
62 _nativeInstance = new FeatureExtractionPluginFactory(); | 62 _nativeInstance = new FeatureExtractionPluginFactory(); |
63 } | 63 } |
64 return _nativeInstance; | 64 return _nativeInstance; |
65 } | 65 } |
66 | 66 |
115 std::vector<QString> path = getPluginPath(); | 115 std::vector<QString> path = getPluginPath(); |
116 | 116 |
117 for (std::vector<QString>::iterator i = path.begin(); i != path.end(); ++i) { | 117 for (std::vector<QString>::iterator i = path.begin(); i != path.end(); ++i) { |
118 | 118 |
119 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 119 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
120 DEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: scanning directory " << i-<< endl; | 120 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: scanning directory " << i-<< endl; |
121 #endif | 121 #endif |
122 | 122 |
123 QDir pluginDir(*i, PLUGIN_GLOB, | 123 QDir pluginDir(*i, PLUGIN_GLOB, |
124 QDir::Name | QDir::IgnoreCase, | 124 QDir::Name | QDir::IgnoreCase, |
125 QDir::Files | QDir::Readable); | 125 QDir::Files | QDir::Readable); |
127 for (unsigned int j = 0; j < pluginDir.count(); ++j) { | 127 for (unsigned int j = 0; j < pluginDir.count(); ++j) { |
128 | 128 |
129 QString soname = pluginDir.filePath(pluginDir[j]); | 129 QString soname = pluginDir.filePath(pluginDir[j]); |
130 | 130 |
131 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 131 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
132 DEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: trying potential library " << soname << endl; | 132 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: trying potential library " << soname << endl; |
133 #endif | 133 #endif |
134 | 134 |
135 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL); | 135 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL); |
136 | 136 |
137 if (!libraryHandle) { | 137 if (!libraryHandle) { |
138 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname << ": " << DLERROR() << std::endl; | 138 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname << ": " << DLERROR() << std::endl; |
139 continue; | 139 continue; |
140 } | 140 } |
141 | 141 |
142 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 142 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
143 DEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: It's a library all right, checking for descriptor" << endl; | 143 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: It's a library all right, checking for descriptor" << endl; |
144 #endif | 144 #endif |
145 | 145 |
146 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) | 146 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) |
147 DLSYM(libraryHandle, "vampGetPluginDescriptor"); | 147 DLSYM(libraryHandle, "vampGetPluginDescriptor"); |
148 | 148 |
153 } | 153 } |
154 continue; | 154 continue; |
155 } | 155 } |
156 | 156 |
157 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 157 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
158 DEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Vamp descriptor found" << endl; | 158 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Vamp descriptor found" << endl; |
159 #endif | 159 #endif |
160 | 160 |
161 const VampPluginDescriptor *descriptor = 0; | 161 const VampPluginDescriptor *descriptor = 0; |
162 int index = 0; | 162 int index = 0; |
163 | 163 |
171 << soname.toStdString() | 171 << soname.toStdString() |
172 << " returns the same plugin identifier \"" | 172 << " returns the same plugin identifier \"" |
173 << descriptor->identifier << "\" at indices " | 173 << descriptor->identifier << "\" at indices " |
174 << known[descriptor->identifier] << " and " | 174 << known[descriptor->identifier] << " and " |
175 << index << std::endl; | 175 << index << std::endl; |
176 DEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << endl; | 176 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << endl; |
177 ok = false; | 177 ok = false; |
178 break; | 178 break; |
179 } else { | 179 } else { |
180 known[descriptor->identifier] = index; | 180 known[descriptor->identifier] = index; |
181 } | 181 } |
191 | 191 |
192 QString id = PluginIdentifier::createIdentifier | 192 QString id = PluginIdentifier::createIdentifier |
193 ("vamp", soname, descriptor->identifier); | 193 ("vamp", soname, descriptor->identifier); |
194 rv.push_back(id); | 194 rv.push_back(id); |
195 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 195 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
196 DEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id << " at index " << index << endl; | 196 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id << " at index " << index << endl; |
197 #endif | 197 #endif |
198 ++index; | 198 ++index; |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
214 FeatureExtractionPluginFactory::findPluginFile(QString soname, QString inDir) | 214 FeatureExtractionPluginFactory::findPluginFile(QString soname, QString inDir) |
215 { | 215 { |
216 QString file = ""; | 216 QString file = ""; |
217 | 217 |
218 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 218 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
219 DEBUG << "FeatureExtractionPluginFactory::findPluginFile(\"" | 219 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile(\"" |
220 << soname << "\", \"" << inDir << "\")" | 220 << soname << "\", \"" << inDir << "\")" |
221 << endl; | 221 << endl; |
222 #endif | 222 #endif |
223 | 223 |
224 if (inDir != "") { | 224 if (inDir != "") { |
231 file = dir.filePath(QFileInfo(soname).fileName()); | 231 file = dir.filePath(QFileInfo(soname).fileName()); |
232 | 232 |
233 if (QFileInfo(file).exists() && QFileInfo(file).isFile()) { | 233 if (QFileInfo(file).exists() && QFileInfo(file).isFile()) { |
234 | 234 |
235 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 235 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
236 DEBUG << "FeatureExtractionPluginFactory::findPluginFile: " | 236 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile: " |
237 << "found trivially at " << file << endl; | 237 << "found trivially at " << file << endl; |
238 #endif | 238 #endif |
239 | 239 |
240 return file; | 240 return file; |
241 } | 241 } |
243 for (unsigned int j = 0; j < dir.count(); ++j) { | 243 for (unsigned int j = 0; j < dir.count(); ++j) { |
244 file = dir.filePath(dir[j]); | 244 file = dir.filePath(dir[j]); |
245 if (QFileInfo(file).baseName() == QFileInfo(soname).baseName()) { | 245 if (QFileInfo(file).baseName() == QFileInfo(soname).baseName()) { |
246 | 246 |
247 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 247 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
248 DEBUG << "FeatureExtractionPluginFactory::findPluginFile: " | 248 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile: " |
249 << "found \"" << soname << "\" at " << file << endl; | 249 << "found \"" << soname << "\" at " << file << endl; |
250 #endif | 250 #endif |
251 | 251 |
252 return file; | 252 return file; |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 256 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
257 DEBUG << "FeatureExtractionPluginFactory::findPluginFile (with dir): " | 257 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile (with dir): " |
258 << "not found" << endl; | 258 << "not found" << endl; |
259 #endif | 259 #endif |
260 | 260 |
261 return ""; | 261 return ""; |
262 | 262 |
264 | 264 |
265 QFileInfo fi(soname); | 265 QFileInfo fi(soname); |
266 | 266 |
267 if (fi.isAbsolute() && fi.exists() && fi.isFile()) { | 267 if (fi.isAbsolute() && fi.exists() && fi.isFile()) { |
268 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 268 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
269 DEBUG << "FeatureExtractionPluginFactory::findPluginFile: " | 269 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile: " |
270 << "found trivially at " << soname << endl; | 270 << "found trivially at " << soname << endl; |
271 #endif | 271 #endif |
272 return soname; | 272 return soname; |
273 } | 273 } |
274 | 274 |
285 if (file != "") return file; | 285 if (file != "") return file; |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 289 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
290 DEBUG << "FeatureExtractionPluginFactory::findPluginFile: " | 290 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile: " |
291 << "not found" << endl; | 291 << "not found" << endl; |
292 #endif | 292 #endif |
293 | 293 |
294 return ""; | 294 return ""; |
295 } | 295 } |
308 int index = 0; | 308 int index = 0; |
309 | 309 |
310 QString type, soname, label; | 310 QString type, soname, label; |
311 PluginIdentifier::parseIdentifier(identifier, type, soname, label); | 311 PluginIdentifier::parseIdentifier(identifier, type, soname, label); |
312 if (type != "vamp") { | 312 if (type != "vamp") { |
313 DEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type << endl; | 313 SVDEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type << endl; |
314 return 0; | 314 return 0; |
315 } | 315 } |
316 | 316 |
317 QString found = findPluginFile(soname); | 317 QString found = findPluginFile(soname); |
318 | 318 |
320 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find library file " << soname << std::endl; | 320 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find library file " << soname << std::endl; |
321 return 0; | 321 return 0; |
322 } else if (found != soname) { | 322 } else if (found != soname) { |
323 | 323 |
324 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE | 324 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE |
325 DEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Given library name was " << soname << ", found at " << found << endl; | 325 SVDEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Given library name was " << soname << ", found at " << found << endl; |
326 std::cerr << soname << " -> " << found << std::endl; | 326 std::cerr << soname << " -> " << found << std::endl; |
327 #endif | 327 #endif |
328 | 328 |
329 } | 329 } |
330 | 330 |
339 | 339 |
340 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) | 340 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) |
341 DLSYM(libraryHandle, "vampGetPluginDescriptor"); | 341 DLSYM(libraryHandle, "vampGetPluginDescriptor"); |
342 | 342 |
343 if (!fn) { | 343 if (!fn) { |
344 DEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: No descriptor function in " << soname << endl; | 344 SVDEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: No descriptor function in " << soname << endl; |
345 goto done; | 345 goto done; |
346 } | 346 } |
347 | 347 |
348 while ((descriptor = fn(VAMP_API_VERSION, index))) { | 348 while ((descriptor = fn(VAMP_API_VERSION, index))) { |
349 if (label == descriptor->identifier) break; | 349 if (label == descriptor->identifier) break; |
360 if (plugin) { | 360 if (plugin) { |
361 m_handleMap[plugin] = libraryHandle; | 361 m_handleMap[plugin] = libraryHandle; |
362 rv = new PluginDeletionNotifyAdapter(plugin, this); | 362 rv = new PluginDeletionNotifyAdapter(plugin, this); |
363 } | 363 } |
364 | 364 |
365 // DEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Constructed Vamp plugin, rv is " << rv << endl; | 365 // SVDEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Constructed Vamp plugin, rv is " << rv << endl; |
366 | 366 |
367 //!!! need to dlclose() when plugins from a given library are unloaded | 367 //!!! need to dlclose() when plugins from a given library are unloaded |
368 | 368 |
369 done: | 369 done: |
370 if (!rv) { | 370 if (!rv) { |
371 if (DLCLOSE(libraryHandle) != 0) { | 371 if (DLCLOSE(libraryHandle) != 0) { |
372 std::cerr << "WARNING: FeatureExtractionPluginFactory::instantiatePlugin: Failed to unload library " << soname << std::endl; | 372 std::cerr << "WARNING: FeatureExtractionPluginFactory::instantiatePlugin: Failed to unload library " << soname << std::endl; |
373 } | 373 } |
374 } | 374 } |
375 | 375 |
376 // DEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Instantiated plugin " << label << " from library " << soname << ": descriptor " << descriptor << ", rv "<< rv << ", label " << rv->getName() << ", outputs " << rv->getOutputDescriptors().size() << endl; | 376 // SVDEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Instantiated plugin " << label << " from library " << soname << ": descriptor " << descriptor << ", rv "<< rv << ", label " << rv->getName() << ", outputs " << rv->getOutputDescriptors().size() << endl; |
377 | 377 |
378 return rv; | 378 return rv; |
379 } | 379 } |
380 | 380 |
381 void | 381 void |
382 FeatureExtractionPluginFactory::pluginDeleted(Vamp::Plugin *plugin) | 382 FeatureExtractionPluginFactory::pluginDeleted(Vamp::Plugin *plugin) |
383 { | 383 { |
384 void *handle = m_handleMap[plugin]; | 384 void *handle = m_handleMap[plugin]; |
385 if (handle) { | 385 if (handle) { |
386 // DEBUG << "unloading library " << handle << " for plugin " << plugin << endl; | 386 // SVDEBUG << "unloading library " << handle << " for plugin " << plugin << endl; |
387 DLCLOSE(handle); | 387 DLCLOSE(handle); |
388 } | 388 } |
389 m_handleMap.erase(plugin); | 389 m_handleMap.erase(plugin); |
390 } | 390 } |
391 | 391 |
413 | 413 |
414 for (size_t i = 0; i < path.size(); ++i) { | 414 for (size_t i = 0; i < path.size(); ++i) { |
415 | 415 |
416 QDir dir(path[i], "*.cat"); | 416 QDir dir(path[i], "*.cat"); |
417 | 417 |
418 // DEBUG << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << endl; | 418 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << endl; |
419 for (unsigned int j = 0; j < dir.count(); ++j) { | 419 for (unsigned int j = 0; j < dir.count(); ++j) { |
420 | 420 |
421 QFile file(path[i] + "/" + dir[j]); | 421 QFile file(path[i] + "/" + dir[j]); |
422 | 422 |
423 // DEBUG << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i]+ "/" + dir[j]) << endl; | 423 // SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i]+ "/" + dir[j]) << endl; |
424 | 424 |
425 if (file.open(QIODevice::ReadOnly)) { | 425 if (file.open(QIODevice::ReadOnly)) { |
426 // std::cerr << "...opened" << std::endl; | 426 // std::cerr << "...opened" << std::endl; |
427 QTextStream stream(&file); | 427 QTextStream stream(&file); |
428 QString line; | 428 QString line; |