mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 16:30:16 +02:00
Add a filter functor to the plugin manager and use it in AudioMixer
This commit is contained in:
parent
3776472550
commit
74748b15fd
3 changed files with 37 additions and 10 deletions
|
@ -68,6 +68,13 @@ AudioMixer::AudioMixer(ReceivedMessage& message) :
|
||||||
// hash the available codecs (on the mixer)
|
// hash the available codecs (on the mixer)
|
||||||
_availableCodecs.clear(); // Make sure struct is clean
|
_availableCodecs.clear(); // Make sure struct is clean
|
||||||
auto pluginManager = DependencyManager::set<PluginManager>();
|
auto pluginManager = DependencyManager::set<PluginManager>();
|
||||||
|
// Only load codec plugins; for now assume codec plugins have 'codec' in their name.
|
||||||
|
auto codecPluginFilter = [](const QJsonObject& metaData) {
|
||||||
|
QJsonValue nameValue = metaData["MetaData"]["name"];
|
||||||
|
return nameValue.toString().contains("codec", Qt::CaseInsensitive);
|
||||||
|
};
|
||||||
|
pluginManager->setPluginFilter(codecPluginFilter);
|
||||||
|
|
||||||
auto codecPlugins = pluginManager->getCodecPlugins();
|
auto codecPlugins = pluginManager->getCodecPlugins();
|
||||||
for_each(codecPlugins.cbegin(), codecPlugins.cend(),
|
for_each(codecPlugins.cbegin(), codecPlugins.cend(),
|
||||||
[&](const CodecPluginPointer& codec) {
|
[&](const CodecPluginPointer& codec) {
|
||||||
|
|
|
@ -14,6 +14,11 @@
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QPluginLoader>
|
#include <QtCore/QPluginLoader>
|
||||||
|
|
||||||
|
//#define HIFI_PLUGINMANAGER_DEBUG
|
||||||
|
#if defined(HIFI_PLUGINMANAGER_DEBUG)
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
#include <UserActivityLogger.h>
|
#include <UserActivityLogger.h>
|
||||||
|
|
||||||
|
@ -79,10 +84,7 @@ bool isDisabled(QJsonObject metaData) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
using Loader = QSharedPointer<QPluginLoader>;
|
auto PluginManager::getLoadedPlugins() const -> const LoaderList& {
|
||||||
using LoaderList = QList<Loader>;
|
|
||||||
|
|
||||||
const LoaderList& getLoadedPlugins() {
|
|
||||||
static std::once_flag once;
|
static std::once_flag once;
|
||||||
static LoaderList loadedPlugins;
|
static LoaderList loadedPlugins;
|
||||||
std::call_once(once, [&] {
|
std::call_once(once, [&] {
|
||||||
|
@ -106,15 +108,25 @@ const LoaderList& getLoadedPlugins() {
|
||||||
for (auto plugin : candidates) {
|
for (auto plugin : candidates) {
|
||||||
qCDebug(plugins) << "Attempting plugin" << qPrintable(plugin);
|
qCDebug(plugins) << "Attempting plugin" << qPrintable(plugin);
|
||||||
QSharedPointer<QPluginLoader> loader(new QPluginLoader(pluginPath + plugin));
|
QSharedPointer<QPluginLoader> loader(new QPluginLoader(pluginPath + plugin));
|
||||||
|
const QJsonObject pluginMetaData = loader->metaData();
|
||||||
if (isDisabled(loader->metaData())) {
|
#if defined(HIFI_PLUGINMANAGER_DEBUG)
|
||||||
|
QJsonDocument metaDataDoc(pluginMetaData);
|
||||||
|
qCInfo(plugins) << "Metadata for " << qPrintable(plugin) << ": " << QString(metaDataDoc.toJson());
|
||||||
|
#endif
|
||||||
|
if (isDisabled(pluginMetaData)) {
|
||||||
qCWarning(plugins) << "Plugin" << qPrintable(plugin) << "is disabled";
|
qCWarning(plugins) << "Plugin" << qPrintable(plugin) << "is disabled";
|
||||||
// Skip this one, it's disabled
|
// Skip this one, it's disabled
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (getPluginInterfaceVersionFromMetaData(loader->metaData()) != HIFI_PLUGIN_INTERFACE_VERSION) {
|
|
||||||
|
if (!_pluginFilter(pluginMetaData)) {
|
||||||
|
qCWarning(plugins) << "Plugin" << qPrintable(plugin) << "doesn't pass provided filter";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getPluginInterfaceVersionFromMetaData(pluginMetaData) != HIFI_PLUGIN_INTERFACE_VERSION) {
|
||||||
qCWarning(plugins) << "Plugin" << qPrintable(plugin) << "interface version doesn't match, not loading:"
|
qCWarning(plugins) << "Plugin" << qPrintable(plugin) << "interface version doesn't match, not loading:"
|
||||||
<< getPluginInterfaceVersionFromMetaData(loader->metaData())
|
<< getPluginInterfaceVersionFromMetaData(pluginMetaData)
|
||||||
<< "doesn't match" << HIFI_PLUGIN_INTERFACE_VERSION;
|
<< "doesn't match" << HIFI_PLUGIN_INTERFACE_VERSION;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
|
|
||||||
#include "Forward.h"
|
#include "Forward.h"
|
||||||
|
|
||||||
|
class QPluginLoader;
|
||||||
class PluginManager;
|
|
||||||
using PluginManagerPointer = QSharedPointer<PluginManager>;
|
using PluginManagerPointer = QSharedPointer<PluginManager>;
|
||||||
|
|
||||||
class PluginManager : public QObject, public Dependency {
|
class PluginManager : public QObject, public Dependency {
|
||||||
|
@ -47,6 +46,9 @@ public:
|
||||||
void setInputPluginSettingsPersister(const InputPluginSettingsPersister& persister);
|
void setInputPluginSettingsPersister(const InputPluginSettingsPersister& persister);
|
||||||
QStringList getRunningInputDeviceNames() const;
|
QStringList getRunningInputDeviceNames() const;
|
||||||
|
|
||||||
|
using PluginFilter = std::function<bool(const QJsonObject&)>;
|
||||||
|
void setPluginFilter(PluginFilter pluginFilter) { _pluginFilter = pluginFilter; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void inputDeviceRunningChanged(const QString& pluginName, bool isRunning, const QStringList& runningDevices);
|
void inputDeviceRunningChanged(const QString& pluginName, bool isRunning, const QStringList& runningDevices);
|
||||||
|
|
||||||
|
@ -60,6 +62,12 @@ private:
|
||||||
PluginContainer* _container { nullptr };
|
PluginContainer* _container { nullptr };
|
||||||
DisplayPluginList _displayPlugins;
|
DisplayPluginList _displayPlugins;
|
||||||
InputPluginList _inputPlugins;
|
InputPluginList _inputPlugins;
|
||||||
|
PluginFilter _pluginFilter { [](const QJsonObject&) { return true; } };
|
||||||
|
|
||||||
|
using Loader = QSharedPointer<QPluginLoader>;
|
||||||
|
using LoaderList = QList<Loader>;
|
||||||
|
|
||||||
|
const LoaderList& getLoadedPlugins() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: we should define this value in CMake, and then use CMake
|
// TODO: we should define this value in CMake, and then use CMake
|
||||||
|
|
Loading…
Reference in a new issue