diff options
author | Val Doroshchuk <valentyn.doroshchuk@qt.io> | 2019-01-07 14:14:50 +0100 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2019-01-14 08:28:23 +0000 |
commit | 509dedc662a46e37a5024ce357978b8cf70b4988 (patch) | |
tree | 6450fa9db89c6f6b8049fce40a1295870a73edb6 /src/multimedia | |
parent | fbb8b1ee626955fce61af7fc21f64ebed2c8cb5c (diff) |
Introduce QT_MULTIMEDIA_PREFERRED_PLUGINS env var
Added comma-separated env var to define preferred backend plugins in
descending order if multiple backends are available.
Also short names of plugins could be used, e.g. "gst" instead of
"gstreamermediaplayer", "av" instead of "avfoundationmediaplayer" etc.
[ChangleLog] Added QT_MULTIMEDIA_PREFERRED_PLUGINS to
specify preferred plugins if multiple backends are available.
Change-Id: Iae1a24f2a36d7d133c5771626e68e89f8273b1bf
Task-number: QTBUG-56400
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r-- | src/multimedia/qmediapluginloader.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/multimedia/qmediapluginloader.cpp b/src/multimedia/qmediapluginloader.cpp index d0a058ac9..78ba3207f 100644 --- a/src/multimedia/qmediapluginloader.cpp +++ b/src/multimedia/qmediapluginloader.cpp @@ -82,6 +82,7 @@ QList<QObject*> QMediaPluginLoader::instances(QString const &key) if (!m_metadata.contains(key)) return QList<QObject*>(); + QList<QString> keys; QList<QObject *> objects; const auto list = m_metadata.value(key); for (const QJsonObject &jsonobj : list) { @@ -91,10 +92,39 @@ QList<QObject*> QMediaPluginLoader::instances(QString const &key) QObject *object = m_factoryLoader->instance(idx); if (!objects.contains(object)) { + QJsonArray arr = jsonobj.value(QStringLiteral("Keys")).toArray(); + keys.append(!arr.isEmpty() ? arr.at(0).toString() : QStringLiteral("")); objects.append(object); } } + static const bool showDebug = qEnvironmentVariableIntValue("QT_DEBUG_PLUGINS"); + static const QStringList preferredPlugins = + qEnvironmentVariable("QT_MULTIMEDIA_PREFERRED_PLUGINS").split(QLatin1Char(','), QString::SkipEmptyParts); + for (int i = preferredPlugins.size() - 1; i >= 0; --i) { + auto name = preferredPlugins[i]; + bool found = false; + for (int j = 0; j < keys.size(); ++j) { + if (!keys[j].startsWith(name)) + continue; + + auto obj = objects[j]; + objects.removeAt(j); + objects.prepend(obj); + auto k = keys[j]; + keys.removeAt(j); + keys.prepend(k); + found = true; + break; + } + + if (showDebug && !found) + qWarning() << "QMediaPluginLoader: pattern" << name << "did not match any loaded plugin"; + } + + if (showDebug) + qDebug() << "QMediaPluginLoader: loaded plugins for key" << key << ":" << keys; + return objects; } |