2019-04-20 15:25:31 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2019-04-20 15:25:31 +02:00
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2021-04-14 00:16:07 +02:00
|
|
|
#include <cstring>
|
|
|
|
#include <glib.h>
|
|
|
|
|
2019-04-20 15:25:31 +02:00
|
|
|
#include <gst/gst.h>
|
2019-09-07 23:34:13 +02:00
|
|
|
#include <gst/pbutils/pbutils.h>
|
2019-04-20 15:25:31 +02:00
|
|
|
|
2021-04-14 00:16:07 +02:00
|
|
|
#include <QtGlobal>
|
2019-04-20 15:25:31 +02:00
|
|
|
#include <QObject>
|
2021-04-14 00:16:07 +02:00
|
|
|
#include <QMetaObject>
|
2019-04-20 15:25:31 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QStandardPaths>
|
2020-07-18 16:28:39 +02:00
|
|
|
#include <QtConcurrent>
|
2019-04-20 15:25:31 +02:00
|
|
|
#include <QFuture>
|
|
|
|
#include <QString>
|
2019-04-20 17:36:42 +02:00
|
|
|
#include <QDir>
|
2020-04-27 15:54:37 +02:00
|
|
|
#include <QFile>
|
2021-04-14 00:16:07 +02:00
|
|
|
#include <QAbstractEventDispatcher>
|
2019-04-20 15:25:31 +02:00
|
|
|
|
2020-10-03 20:05:30 +02:00
|
|
|
#include "core/logging.h"
|
2019-04-20 15:25:31 +02:00
|
|
|
#include "core/utilities.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_MOODBAR
|
|
|
|
# include "ext/gstmoodbar/gstmoodbarplugin.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gststartup.h"
|
|
|
|
|
2021-04-14 00:16:07 +02:00
|
|
|
GThread *GstStartup::kGThread = nullptr;
|
|
|
|
|
|
|
|
gpointer GstStartup::GLibMainLoopThreadFunc(gpointer) {
|
|
|
|
|
|
|
|
qLog(Info) << "Creating GLib main event loop.";
|
|
|
|
|
|
|
|
GMainLoop *gloop = g_main_loop_new(nullptr, false);
|
|
|
|
g_main_loop_run(gloop);
|
|
|
|
g_main_loop_unref(gloop);
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-20 15:25:31 +02:00
|
|
|
GstStartup::GstStartup(QObject *parent) : QObject(parent) {
|
2021-04-14 00:16:07 +02:00
|
|
|
|
2021-06-22 13:41:38 +02:00
|
|
|
initializing_ = QtConcurrent::run(&GstStartup::InitializeGStreamer);
|
2021-04-14 00:16:07 +02:00
|
|
|
|
|
|
|
const QMetaObject *mo = QAbstractEventDispatcher::instance(qApp->thread())->metaObject();
|
|
|
|
if (mo && strcmp(mo->className(), "QEventDispatcherGlib") != 0 && strcmp(mo->superClass()->className(), "QEventDispatcherGlib") != 0) {
|
|
|
|
kGThread = g_thread_new(nullptr, GstStartup::GLibMainLoopThreadFunc, nullptr);
|
|
|
|
}
|
|
|
|
|
2019-04-20 15:25:31 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 00:16:07 +02:00
|
|
|
GstStartup::~GstStartup() {
|
|
|
|
if (kGThread) g_thread_unref(kGThread);
|
|
|
|
}
|
2019-04-20 15:25:31 +02:00
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
void GstStartup::InitializeGStreamer() {
|
2019-04-20 15:25:31 +02:00
|
|
|
|
|
|
|
SetEnvironment();
|
|
|
|
|
|
|
|
gst_init(nullptr, nullptr);
|
2019-09-07 23:34:13 +02:00
|
|
|
gst_pb_utils_init();
|
2019-04-20 15:25:31 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_MOODBAR
|
|
|
|
gstfastspectrum_register_static();
|
|
|
|
#endif
|
|
|
|
|
2020-12-13 21:56:25 +01:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
// Use directsoundsink by default because of buggy wasapi plugin.
|
|
|
|
GstRegistry *reg = gst_registry_get();
|
|
|
|
if (reg) {
|
|
|
|
GstPluginFeature *directsoundsink = gst_registry_lookup_feature(reg, "directsoundsink");
|
|
|
|
GstPluginFeature *wasapisink = gst_registry_lookup_feature(reg, "wasapisink");
|
|
|
|
if (directsoundsink && wasapisink) {
|
|
|
|
gst_plugin_feature_set_rank(directsoundsink, GST_RANK_PRIMARY);
|
|
|
|
gst_plugin_feature_set_rank(wasapisink, GST_RANK_SECONDARY);
|
|
|
|
}
|
|
|
|
if (directsoundsink) gst_object_unref(directsoundsink);
|
|
|
|
if (wasapisink) gst_object_unref(wasapisink);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-04-20 15:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GstStartup::SetEnvironment() {
|
|
|
|
|
2020-10-03 20:05:30 +02:00
|
|
|
QString bundle_path = QCoreApplication::applicationDirPath();
|
|
|
|
|
|
|
|
#ifdef USE_BUNDLE_DIR
|
|
|
|
QString bundle_dir = USE_BUNDLE_DIR;
|
|
|
|
if (!bundle_dir.isEmpty()) {
|
|
|
|
bundle_path.append("/" + bundle_dir);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QString gio_module_path;
|
|
|
|
QString gst_plugin_scanner;
|
|
|
|
QString gst_plugin_path;
|
|
|
|
QString gst_registry_filename;
|
2019-04-20 15:25:31 +02:00
|
|
|
|
|
|
|
#ifdef USE_BUNDLE
|
2020-04-27 15:54:37 +02:00
|
|
|
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
|
2020-10-03 20:05:30 +02:00
|
|
|
gio_module_path = bundle_path + "/gio-modules";
|
2020-04-27 15:54:37 +02:00
|
|
|
#endif
|
2019-08-27 22:29:48 +02:00
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
|
2020-10-03 20:05:30 +02:00
|
|
|
gst_plugin_scanner = bundle_path + "/gst-plugin-scanner";
|
|
|
|
gst_plugin_path = bundle_path + "/gstreamer";
|
2020-04-27 15:54:37 +02:00
|
|
|
#endif
|
|
|
|
#if defined(Q_OS_WIN32)
|
2020-10-03 20:05:30 +02:00
|
|
|
//gst_plugin_scanner = bundle_path + "/gst-plugin-scanner.exe";
|
|
|
|
gst_plugin_path = bundle_path + "/gstreamer-plugins";
|
2019-04-20 15:25:31 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
|
2020-10-03 20:05:30 +02:00
|
|
|
gst_registry_filename = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QString("/gst-registry-%1-bin").arg(QCoreApplication::applicationVersion());
|
2019-04-20 15:25:31 +02:00
|
|
|
#endif
|
|
|
|
|
2020-10-03 20:05:30 +02:00
|
|
|
if (!gio_module_path.isEmpty()) {
|
|
|
|
if (QDir(gio_module_path).exists()) {
|
|
|
|
qLog(Debug) << "Setting GIO module path to" << gio_module_path;
|
|
|
|
Utilities::SetEnv("GIO_EXTRA_MODULES", gio_module_path);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qLog(Debug) << "GIO module path does not exist:" << gio_module_path;
|
|
|
|
}
|
2020-04-27 15:54:37 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 20:05:30 +02:00
|
|
|
if (!gst_plugin_scanner.isEmpty()) {
|
|
|
|
if (QFile(gst_plugin_scanner).exists()) {
|
2020-10-03 20:08:33 +02:00
|
|
|
qLog(Debug) << "Setting GStreamer plugin scanner to" << gst_plugin_scanner;
|
2020-10-03 20:05:30 +02:00
|
|
|
Utilities::SetEnv("GST_PLUGIN_SCANNER", gst_plugin_scanner);
|
|
|
|
}
|
|
|
|
else {
|
2020-10-03 20:08:33 +02:00
|
|
|
qLog(Debug) << "GStreamer plugin scanner does not exist:" << gst_plugin_scanner;
|
2020-10-03 20:05:30 +02:00
|
|
|
}
|
2019-04-20 15:25:31 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 20:05:30 +02:00
|
|
|
if (!gst_plugin_path.isEmpty()) {
|
|
|
|
if (QDir(gst_plugin_path).exists()) {
|
2020-10-03 20:08:33 +02:00
|
|
|
qLog(Debug) << "Setting GStreamer plugin path to" << gst_plugin_path;
|
2020-10-03 20:05:30 +02:00
|
|
|
Utilities::SetEnv("GST_PLUGIN_PATH", gst_plugin_path);
|
|
|
|
// Never load plugins from anywhere else.
|
|
|
|
Utilities::SetEnv("GST_PLUGIN_SYSTEM_PATH", gst_plugin_path);
|
2020-04-27 15:54:37 +02:00
|
|
|
}
|
2020-10-03 20:05:30 +02:00
|
|
|
else {
|
2020-10-03 20:08:33 +02:00
|
|
|
qLog(Debug) << "GStreamer plugin path does not exist:" << gst_plugin_path;
|
2020-10-03 20:05:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_registry_filename.isEmpty()) {
|
2020-10-03 20:08:33 +02:00
|
|
|
qLog(Debug) << "Setting GStreamer registry file to" << gst_registry_filename;
|
2020-10-03 20:05:30 +02:00
|
|
|
Utilities::SetEnv("GST_REGISTRY", gst_registry_filename);
|
2019-04-20 15:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Utilities::SetEnv("PULSE_PROP_media.role", "music");
|
|
|
|
|
|
|
|
}
|