Mercurial > hg > svcore
changeset 1223:c2207877689d piper
Avoid instantiating all plugins (in piper client) on startup, using plugin static data instead. Problem of where to get the units field from is still pending.
author | Chris Cannam |
---|---|
date | Thu, 20 Oct 2016 14:06:58 +0100 |
parents | 771a17925576 |
children | ab050519c4ba |
files | plugin/FeatureExtractionPluginFactory.cpp plugin/FeatureExtractionPluginFactory.h transform/TransformFactory.cpp |
diffstat | 3 files changed, 57 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/plugin/FeatureExtractionPluginFactory.cpp Thu Oct 20 11:19:34 2016 +0100 +++ b/plugin/FeatureExtractionPluginFactory.cpp Thu Oct 20 14:06:58 2016 +0100 @@ -31,6 +31,9 @@ #include "base/Profiler.h" +#include "vamp-client/ProcessQtTransport.h" +#include "vamp-client/CapnpRRClient.h" + using namespace std; //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1 @@ -60,9 +63,7 @@ } FeatureExtractionPluginFactory::FeatureExtractionPluginFactory() : - m_serverName("piper-cpp/bin/piper-vamp-server"), - m_transport(m_serverName), - m_client(&m_transport) + m_serverName("piper-cpp/bin/piper-vamp-server") //!!! { } @@ -128,16 +129,37 @@ } } +piper_vamp::PluginStaticData +FeatureExtractionPluginFactory::getPluginStaticData(QString identifier) +{ + QString type, soname, label; + PluginIdentifier::parseIdentifier(identifier, type, soname, label); + std::string pluginKey = (soname + ":" + label).toStdString(); + + for (const auto &d: m_pluginData) { + if (d.pluginKey == pluginKey) { + return d; + } + } + return {}; +} + QString FeatureExtractionPluginFactory::getPluginCategory(QString identifier) { - return m_taxonomy[identifier]; + if (m_taxonomy.find(identifier) != m_taxonomy.end()) { + return m_taxonomy[identifier]; + } else { + return {}; + } } void FeatureExtractionPluginFactory::populate() { - piper_vamp::ListResponse lr = m_client.listPluginData(); + piper_vamp::client::ProcessQtTransport transport(m_serverName); + piper_vamp::client::CapnpRRClient client(&transport); + piper_vamp::ListResponse lr = client.listPluginData(); m_pluginData = lr.available; for (const auto &pd: m_pluginData) { @@ -149,6 +171,7 @@ for (const auto &cs: pd.category) { catlist.push_back(QString::fromStdString(cs)); } + m_taxonomy[identifier] = catlist.join(" > "); } }
--- a/plugin/FeatureExtractionPluginFactory.h Thu Oct 20 11:19:34 2016 +0100 +++ b/plugin/FeatureExtractionPluginFactory.h Thu Oct 20 14:06:58 2016 +0100 @@ -26,8 +26,7 @@ #include "base/Debug.h" #include "base/BaseTypes.h" -#include "vamp-client/ProcessQtTransport.h" -#include "vamp-client/CapnpRRClient.h" +#include "vamp-support/PluginStaticData.h" class FeatureExtractionPluginFactory { @@ -41,6 +40,8 @@ virtual std::vector<QString> getPluginIdentifiers(); + virtual piper_vamp::PluginStaticData getPluginStaticData(QString identifier); + // We don't set blockSize or channels on this -- they're // negotiated and handled via initialize() on the plugin virtual Vamp::Plugin *instantiatePlugin(QString identifier, @@ -53,10 +54,6 @@ protected: std::string m_serverName; - - piper_vamp::client::ProcessQtTransport m_transport; - piper_vamp::client::CapnpRRClient m_client; - QMutex m_mutex; std::vector<piper_vamp::PluginStaticData> m_pluginData; std::map<QString, QString> m_taxonomy;
--- a/transform/TransformFactory.cpp Thu Oct 20 11:19:34 2016 +0100 +++ b/transform/TransformFactory.cpp Thu Oct 20 14:06:58 2016 +0100 @@ -418,64 +418,62 @@ continue; } - Vamp::Plugin *plugin = - factory->instantiatePlugin(pluginId, 44100); + piper_vamp::PluginStaticData psd = factory->getPluginStaticData(pluginId); - if (!plugin) { - cerr << "WARNING: TransformFactory::populateTransforms: Failed to instantiate plugin " << pluginId << endl; - continue; - } - - QString pluginName = plugin->getName().c_str(); + if (psd.pluginKey == "") { + cerr << "WARNING: TransformFactory::populateTransforms: No plugin static data available for instance " << pluginId << endl; + continue; + } + + QString pluginName = QString::fromStdString(psd.basic.name); QString category = factory->getPluginCategory(pluginId); + + const auto &basicOutputs = psd.basicOutputInfo; - Vamp::Plugin::OutputList outputs = - plugin->getOutputDescriptors(); + for (const auto &o: basicOutputs) { - for (int j = 0; j < (int)outputs.size(); ++j) { + QString outputName = QString::fromStdString(o.name); QString transformId = QString("%1:%2") - .arg(pluginId).arg(outputs[j].identifier.c_str()); + .arg(pluginId).arg(QString::fromStdString(o.identifier)); QString userName; QString friendlyName; - QString units = outputs[j].unit.c_str(); - QString description = plugin->getDescription().c_str(); - QString maker = plugin->getMaker().c_str(); +//!!! return to this QString units = outputs[j].unit.c_str(); + QString description = QString::fromStdString(psd.basic.description); + QString maker = QString::fromStdString(psd.maker); if (maker == "") maker = tr("<unknown maker>"); QString longDescription = description; if (longDescription == "") { - if (outputs.size() == 1) { + if (basicOutputs.size() == 1) { longDescription = tr("Extract features using \"%1\" plugin (from %2)") .arg(pluginName).arg(maker); } else { longDescription = tr("Extract features using \"%1\" output of \"%2\" plugin (from %3)") - .arg(outputs[j].name.c_str()).arg(pluginName).arg(maker); + .arg(outputName).arg(pluginName).arg(maker); } } else { - if (outputs.size() == 1) { + if (basicOutputs.size() == 1) { longDescription = tr("%1 using \"%2\" plugin (from %3)") .arg(longDescription).arg(pluginName).arg(maker); } else { longDescription = tr("%1 using \"%2\" output of \"%3\" plugin (from %4)") - .arg(longDescription).arg(outputs[j].name.c_str()).arg(pluginName).arg(maker); + .arg(longDescription).arg(outputName).arg(pluginName).arg(maker); } } - if (outputs.size() == 1) { + if (basicOutputs.size() == 1) { userName = pluginName; friendlyName = pluginName; } else { - userName = QString("%1: %2") - .arg(pluginName) - .arg(outputs[j].name.c_str()); - friendlyName = outputs[j].name.c_str(); + userName = QString("%1: %2").arg(pluginName).arg(outputName); + friendlyName = outputName; } - bool configurable = (!plugin->getPrograms().empty() || - !plugin->getParameterDescriptors().empty()); + bool configurable = (!psd.programs.empty() || + !psd.parameters.empty()); #ifdef DEBUG_TRANSFORM_FACTORY cerr << "Feature extraction plugin transform: " << transformId << " friendly name: " << friendlyName << endl; @@ -490,11 +488,10 @@ description, longDescription, maker, - units, +//!!! units, + "", configurable); } - - delete plugin; } }