# HG changeset patch # User Chris Cannam # Date 1478268961 0 # Node ID d45a16c232bd391e6493a160cd1afcabf252191a # Parent 58dd6a6fe4142917ff88fe913512906c14d581d0 Align Sonic Annotator with the new Piper-ified subrepos (bearing in mind we want neither Piper nor the plugin load checker in Sonic Annotator itself) diff -r 58dd6a6fe414 -r d45a16c232bd plugin/FeatureExtractionPluginFactory.cpp --- a/plugin/FeatureExtractionPluginFactory.cpp Thu Nov 03 15:38:17 2016 +0000 +++ b/plugin/FeatureExtractionPluginFactory.cpp Fri Nov 04 14:16:01 2016 +0000 @@ -20,6 +20,7 @@ #include #include "base/Preferences.h" +#include "base/Debug.h" FeatureExtractionPluginFactory * FeatureExtractionPluginFactory::instance() @@ -31,13 +32,21 @@ if (!instance) { +#ifdef HAVE_PIPER if (Preferences::getInstance()->getRunPluginsInProcess()) { - cerr << "creating native instance" << endl; + SVDEBUG << "FeatureExtractionPluginFactory: creating native instance" + << endl; instance = new NativeVampPluginFactory(); } else { - cerr << "creating piper instance" << endl; + SVDEBUG << "FeatureExtractionPluginFactory: creating Piper instance" + << endl; instance = new PiperVampPluginFactory(); } +#else + SVDEBUG << "FeatureExtractionPluginFactory: no Piper support enabled," + << " creating native instance" << endl; + instance = new NativeVampPluginFactory(); +#endif } return instance; diff -r 58dd6a6fe414 -r d45a16c232bd plugin/NativeVampPluginFactory.cpp --- a/plugin/NativeVampPluginFactory.cpp Thu Nov 03 15:38:17 2016 +0000 +++ b/plugin/NativeVampPluginFactory.cpp Fri Nov 04 14:16:01 2016 +0000 @@ -70,6 +70,40 @@ return m_pluginPath; } +static +QList +getCandidateLibraries() +{ +#ifdef HAVE_PLUGIN_CHECKER_HELPER + return PluginScan::getInstance()->getCandidateLibrariesFor + (PluginScan::VampPlugin); +#else + auto path = Vamp::PluginHostAdapter::getPluginPath(); + QList candidates; + for (string dirname: path) { + SVDEBUG << "NativeVampPluginFactory: scanning directory myself: " + << dirname << endl; +#if defined(_WIN32) +#define PLUGIN_GLOB "*.dll" +#elif defined(__APPLE__) +#define PLUGIN_GLOB "*.dylib *.so" +#else +#define PLUGIN_GLOB "*.so" +#endif + QDir dir(dirname.c_str(), PLUGIN_GLOB, + QDir::Name | QDir::IgnoreCase, + QDir::Files | QDir::Readable); + + for (unsigned int i = 0; i < dir.count(); ++i) { + QString soname = dir.filePath(dir[i]); + candidates.push_back({ soname, "" }); + } + } + + return candidates; +#endif +} + vector NativeVampPluginFactory::getPluginIdentifiers(QString &) { @@ -80,14 +114,17 @@ if (!m_identifiers.empty()) { return m_identifiers; } + + auto candidates = getCandidateLibraries(); - auto candidates = PluginScan::getInstance()->getCandidateLibrariesFor - (PluginScan::VampPlugin); - + SVDEBUG << "INFO: Have " << candidates.size() << " candidate Vamp plugin libraries" << endl; + for (auto candidate : candidates) { QString soname = candidate.libraryPath; + SVDEBUG << "INFO: Considering candidate Vamp plugin library " << soname << endl; + void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL); if (!libraryHandle) { diff -r 58dd6a6fe414 -r d45a16c232bd plugin/PiperVampPluginFactory.cpp --- a/plugin/PiperVampPluginFactory.cpp Thu Nov 03 15:38:17 2016 +0000 +++ b/plugin/PiperVampPluginFactory.cpp Fri Nov 04 14:16:01 2016 +0000 @@ -13,6 +13,8 @@ COPYING included with this distribution for more information. */ +#ifdef HAVE_PIPER + #include "PiperVampPluginFactory.h" #include "PluginIdentifier.h" @@ -167,6 +169,8 @@ auto candidateLibraries = scan->getCandidateLibrariesFor(PluginScan::VampPlugin); + SVDEBUG << "INFO: Have " << candidates.size() << " candidate Vamp plugin libraries" << endl; + vector from; for (const auto &c: candidateLibraries) { if (c.helperTag == tag) { @@ -242,3 +246,4 @@ } } +#endif diff -r 58dd6a6fe414 -r d45a16c232bd plugin/PiperVampPluginFactory.h --- a/plugin/PiperVampPluginFactory.h Thu Nov 03 15:38:17 2016 +0000 +++ b/plugin/PiperVampPluginFactory.h Fri Nov 04 14:16:01 2016 +0000 @@ -16,6 +16,8 @@ #ifndef SV_PIPER_VAMP_PLUGIN_FACTORY_H #define SV_PIPER_VAMP_PLUGIN_FACTORY_H +#ifdef HAVE_PIPER + #include "FeatureExtractionPluginFactory.h" #include @@ -60,3 +62,5 @@ }; #endif + +#endif diff -r 58dd6a6fe414 -r d45a16c232bd plugin/PluginScan.cpp --- a/plugin/PluginScan.cpp Thu Nov 03 15:38:17 2016 +0000 +++ b/plugin/PluginScan.cpp Fri Nov 04 14:16:01 2016 +0000 @@ -18,14 +18,21 @@ #include "base/Preferences.h" #include "base/HelperExecPath.h" +#ifdef HAVE_PLUGIN_CHECKER_HELPER #include "checker/knownplugins.h" +#else +class KnownPlugins {}; +#endif #include #include using std::string; -class PluginScan::Logger : public PluginCandidates::LogCallback +class PluginScan::Logger +#ifdef HAVE_PLUGIN_CHECKER_HELPER + : public PluginCandidates::LogCallback +#endif { protected: void log(std::string message) { @@ -55,6 +62,8 @@ void PluginScan::scan() { +#ifdef HAVE_PLUGIN_CHECKER_HELPER + QMutexLocker locker(&m_mutex); bool inProcess = Preferences::getInstance()->getRunPluginsInProcess(); @@ -96,6 +105,8 @@ << " (with helper path = " << p.executable << ")" << endl; } } + +#endif } bool @@ -118,6 +129,8 @@ QList PluginScan::getCandidateLibrariesFor(PluginType type) const { +#ifdef HAVE_PLUGIN_CHECKER_HELPER + QMutexLocker locker(&m_mutex); KnownPlugins::PluginType kpt; @@ -157,11 +170,17 @@ } return candidates; + +#else + return {}; +#endif } QString PluginScan::getStartupFailureReport() const { +#ifdef HAVE_PLUGIN_CHECKER_HELPER + QMutexLocker locker(&m_mutex); if (!m_succeeded) { @@ -191,5 +210,9 @@ + QObject::tr("

These plugins may be incompatible with the system, " "and will be ignored during this run of %1.

") .arg(QCoreApplication::applicationName()); + +#else + return ""; +#endif } diff -r 58dd6a6fe414 -r d45a16c232bd plugin/PluginScan.h --- a/plugin/PluginScan.h Thu Nov 03 15:38:17 2016 +0000 +++ b/plugin/PluginScan.h Fri Nov 04 14:16:01 2016 +0000 @@ -27,8 +27,21 @@ public: static PluginScan *getInstance(); + /** + * Carry out startup scan of available plugins. Do not call + * getCandidateLibrariesFor() unless this has been called and + * scanSucceeded() is returning true. + */ void scan(); + /** + * Return true if scan() completed successfully. If the scan + * failed, consider using the normal plugin path to load any + * available plugins (as if they had all been found to be + * loadable) rather than rejecting all of them -- i.e. consider + * falling back on the behaviour of code from before the scan + * logic was added. + */ bool scanSucceeded() const; enum PluginType { @@ -37,9 +50,19 @@ DSSIPlugin }; struct Candidate { - QString libraryPath; - QString helperTag; + QString libraryPath; // full path, not just soname + QString helperTag; // identifies the helper that found it + // (see HelperExecPath) }; + + /** + * Return the candidate plugin libraries of the given type that + * were found by helpers during the startup scan. + * + * This could return an empty list for two reasons: the scan + * succeeded but no libraries were found; or the scan failed. Call + * scanSucceeded() to distinguish between them. + */ QList getCandidateLibrariesFor(PluginType) const; QString getStartupFailureReport() const; diff -r 58dd6a6fe414 -r d45a16c232bd svcore.pro --- a/svcore.pro Thu Nov 03 15:38:17 2016 +0000 +++ b/svcore.pro Fri Nov 04 14:16:01 2016 +0000 @@ -29,6 +29,6 @@ include(files.pri) -HEADERS = $$(SVCORE_HEADERS) -SOURCES = $$(SVCORE_SOURCES) +HEADERS = $$SVCORE_HEADERS +SOURCES = $$SVCORE_SOURCES