changeset 1464:91bb68146dfc

Add getPluginLibraryPath throughout, in order to provide diagnostic about which plugins were loaded from where
author Chris Cannam
date Fri, 11 May 2018 14:11:04 +0100
parents 2b2b58ae8b59
children cee1be4fb8c1
files plugin/DSSIPluginFactory.cpp plugin/FeatureExtractionPluginFactory.h plugin/LADSPAPluginFactory.cpp plugin/LADSPAPluginFactory.h plugin/NativeVampPluginFactory.cpp plugin/NativeVampPluginFactory.h plugin/PiperVampPluginFactory.cpp plugin/PiperVampPluginFactory.h plugin/RealTimePluginFactory.h
diffstat 9 files changed, 87 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/plugin/DSSIPluginFactory.cpp	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/DSSIPluginFactory.cpp	Fri May 11 14:11:04 2018 +0100
@@ -418,6 +418,8 @@
 
         m_identifiers.push_back(identifier);
 
+        m_libraries[identifier] = soname;
+
         m_rtDescriptors[identifier] = rtd;
 
         ++index;
--- a/plugin/FeatureExtractionPluginFactory.h	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/FeatureExtractionPluginFactory.h	Fri May 11 14:11:04 2018 +0100
@@ -34,17 +34,13 @@
     /**
      * Return all installed plugin identifiers.
      */
-    virtual std::vector<QString> getPluginIdentifiers(QString &errorMessage) {
-        return instance()->getPluginIdentifiers(errorMessage);
-    }
-
+    virtual std::vector<QString> getPluginIdentifiers(QString &errorMsg) = 0;
+    
     /**
      * Return static data for the given plugin.
      */
-    virtual piper_vamp::PluginStaticData getPluginStaticData(QString identifier) {
-        return instance()->getPluginStaticData(identifier);
-    }
-
+    virtual piper_vamp::PluginStaticData getPluginStaticData(QString ident) = 0;
+    
     /**
      * Instantiate (load) and return pointer to the plugin with the
      * given identifier, at the given sample rate. We don't set
@@ -52,16 +48,20 @@
      * via initialize() on the plugin itself after loading.
      */
     virtual Vamp::Plugin *instantiatePlugin(QString identifier,
-                                            sv_samplerate_t inputSampleRate) {
-        return instance()->instantiatePlugin(identifier, inputSampleRate);
-    }
-
+                                            sv_samplerate_t inputSampleRate) = 0;
+    
     /**
      * Get category metadata about a plugin (without instantiating it).
      */
-    virtual QString getPluginCategory(QString identifier) {
-        return instance()->getPluginCategory(identifier);
-    }
+    virtual QString getPluginCategory(QString identifier) = 0;
+
+    /**
+     * Get the full file path (including both directory and filename)
+     * of the library file that provides a given plugin
+     * identifier. Note getPluginIdentifiers() must have been called
+     * before this has access to the necessary information.
+     */
+    virtual QString getPluginLibraryPath(QString identifier) = 0;
 };
 
 #endif
--- a/plugin/LADSPAPluginFactory.cpp	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/LADSPAPluginFactory.cpp	Fri May 11 14:11:04 2018 +0100
@@ -69,6 +69,12 @@
     return m_identifiers;
 }
 
+QString
+LADSPAPluginFactory::getPluginLibraryPath(QString identifier)
+{
+    return m_libraries[identifier];
+}
+
 void
 LADSPAPluginFactory::enumeratePlugins(std::vector<QString> &list)
 {
@@ -794,6 +800,8 @@
 
         m_identifiers.push_back(identifier);
 
+        m_libraries[identifier] = soname;
+
         m_rtDescriptors[identifier] = rtd;
 
         ++index;
--- a/plugin/LADSPAPluginFactory.h	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/LADSPAPluginFactory.h	Fri May 11 14:11:04 2018 +0100
@@ -55,6 +55,8 @@
 
     virtual QString getPluginCategory(QString identifier);
 
+    virtual QString getPluginLibraryPath(QString identifier);
+    
     float getPortMinimum(const LADSPA_Descriptor *, int port);
     float getPortMaximum(const LADSPA_Descriptor *, int port);
     float getPortDefault(const LADSPA_Descriptor *, int port);
@@ -86,6 +88,7 @@
     void unloadUnusedLibraries();
 
     std::vector<QString> m_identifiers;
+    std::map<QString, QString> m_libraries; // identifier -> full file path
     std::map<QString, RealTimePluginDescriptor *> m_rtDescriptors;
 
     std::map<QString, QString> m_taxonomy;
--- a/plugin/NativeVampPluginFactory.cpp	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/NativeVampPluginFactory.cpp	Fri May 11 14:11:04 2018 +0100
@@ -95,8 +95,8 @@
                  QDir::Files | QDir::Readable);
 
         for (unsigned int i = 0; i < dir.count(); ++i) {
-            QString soname = dir.filePath(dir[i]);
-            candidates.push_back({ soname, "" });
+            QString libpath = dir.filePath(dir[i]);
+            candidates.push_back({ libpath, "" });
         }
     }
 
@@ -121,14 +121,14 @@
         
     for (auto candidate : candidates) {
 
-        QString soname = candidate.libraryPath;
+        QString libpath = candidate.libraryPath;
 
-        SVDEBUG << "INFO: Considering candidate Vamp plugin library " << soname << endl;
+        SVDEBUG << "INFO: Considering candidate Vamp plugin library " << libpath << endl;
         
-        void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL);
+        void *libraryHandle = DLOPEN(libpath, RTLD_LAZY | RTLD_LOCAL);
             
         if (!libraryHandle) {
-            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to load library " << soname << ": " << DLERROR() << endl;
+            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to load library " << libpath << ": " << DLERROR() << endl;
             continue;
         }
 
@@ -136,9 +136,9 @@
             DLSYM(libraryHandle, "vampGetPluginDescriptor");
 
         if (!fn) {
-            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: No descriptor function in " << soname << endl;
+            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: No descriptor function in " << libpath << endl;
             if (DLCLOSE(libraryHandle) != 0) {
-                SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to unload library " << soname << endl;
+                SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to unload library " << libpath << endl;
             }
             continue;
         }
@@ -157,12 +157,12 @@
 
             if (known.find(descriptor->identifier) != known.end()) {
                 SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Plugin library "
-                     << soname
-                     << " returns the same plugin identifier \""
-                     << descriptor->identifier << "\" at indices "
-                     << known[descriptor->identifier] << " and "
-                     << index << endl;
-                    SVDEBUG << "NativeVampPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << endl;
+                        << libpath
+                        << " returns the same plugin identifier \""
+                        << descriptor->identifier << "\" at indices "
+                        << known[descriptor->identifier] << " and "
+                        << index << endl;
+                SVDEBUG << "NativeVampPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << endl;
                 ok = false;
                 break;
             } else {
@@ -179,8 +179,9 @@
             while ((descriptor = fn(VAMP_API_VERSION, index))) {
 
                 QString id = PluginIdentifier::createIdentifier
-                    ("vamp", soname, descriptor->identifier);
+                    ("vamp", libpath, descriptor->identifier);
                 m_identifiers.push_back(id);
+                m_libraries[id] = libpath;
 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
                 cerr << "NativeVampPluginFactory::getPluginIdentifiers: Found plugin id " << id << " at index " << index << endl;
 #endif
@@ -189,7 +190,7 @@
         }
             
         if (DLCLOSE(libraryHandle) != 0) {
-            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to unload library " << soname << endl;
+            SVDEBUG << "WARNING: NativeVampPluginFactory::getPluginIdentifiers: Failed to unload library " << libpath << endl;
         }
     }
 
@@ -392,6 +393,12 @@
     return m_taxonomy[identifier];
 }
 
+QString
+NativeVampPluginFactory::getPluginLibraryPath(QString identifier)
+{
+    return m_libraries[identifier];
+}
+
 void
 NativeVampPluginFactory::generateTaxonomy()
 {
--- a/plugin/NativeVampPluginFactory.h	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/NativeVampPluginFactory.h	Fri May 11 14:11:04 2018 +0100
@@ -44,17 +44,17 @@
                                             sv_samplerate_t inputSampleRate)
         override;
 
-    /**
-     * Get category metadata about a plugin (without instantiating it).
-     */
     virtual QString getPluginCategory(QString identifier) override;
 
+    virtual QString getPluginLibraryPath(QString identifier) override;
+
 protected:
     QMutex m_mutex;
     std::vector<QString> m_pluginPath;
     std::vector<QString> m_identifiers;
     std::map<QString, QString> m_taxonomy; // identifier -> category string
     std::map<QString, piper_vamp::PluginStaticData> m_pluginData; // identifier -> data (created opportunistically)
+    std::map<QString, QString> m_libraries; // identifier -> full file path
 
     friend class PluginDeletionNotifyAdapter;
     void pluginDeleted(Vamp::Plugin *);
--- a/plugin/PiperVampPluginFactory.cpp	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/PiperVampPluginFactory.cpp	Fri May 11 14:11:04 2018 +0100
@@ -160,6 +160,27 @@
     }
 }
 
+QString
+PiperVampPluginFactory::getPluginLibraryPath(QString identifier)
+{
+    // What we want to return here is the file path of the library in
+    // which the plugin was actually found -- we want to be paranoid
+    // about that and not just query
+    // Vamp::HostExt::PluginLoader::getLibraryPathForPlugin to return
+    // what the SDK thinks the likely location would be (in case our
+    // search order turns out to have been different)
+
+    QStringList bits = identifier.split(':');
+    if (bits.size() > 1) {
+        QString soname = bits[bits.size() - 2];
+        auto i = m_libraries.find(soname);
+        if (i != m_libraries.end()) {
+            return i->second;
+        }
+    }
+    return QString();
+}
+
 void
 PiperVampPluginFactory::populate(QString &errorMessage)
 {
@@ -196,6 +217,7 @@
             string soname = QFileInfo(c.libraryPath).baseName().toStdString();
             SVDEBUG << "INFO: For tag \"" << tag << "\" giving library " << soname << endl;
             from.push_back(soname);
+            m_libraries[QString::fromStdString(soname)] = c.libraryPath;
         }
     }
 
--- a/plugin/PiperVampPluginFactory.h	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/PiperVampPluginFactory.h	Fri May 11 14:11:04 2018 +0100
@@ -49,10 +49,13 @@
 
     virtual QString getPluginCategory(QString identifier) override;
 
+    virtual QString getPluginLibraryPath(QString identifier) override;
+
 protected:
     QMutex m_mutex;
     QList<HelperExecPath::HelperExec> m_servers; // executable file paths
     std::map<QString, QString> m_origins; // plugin identifier -> server path
+    std::map<QString, QString> m_libraries; // soname -> full file path
     std::map<QString, piper_vamp::PluginStaticData> m_pluginData; // identifier -> data
     std::map<QString, QString> m_taxonomy; // identifier -> category string
 
--- a/plugin/RealTimePluginFactory.h	Thu May 10 10:12:13 2018 +0100
+++ b/plugin/RealTimePluginFactory.h	Fri May 11 14:11:04 2018 +0100
@@ -97,6 +97,14 @@
      */
     virtual QString getPluginCategory(QString identifier) = 0;
 
+    /**
+     * Get the full file path (including both directory and filename)
+     * of the library file that provides a given plugin
+     * identifier. Note getPluginIdentifiers() must have been called
+     * before this has access to the necessary information.
+     */
+    virtual QString getPluginLibraryPath(QString identifier) = 0;
+    
 protected:
     RealTimePluginFactory() { }