1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2024-12-16 10:38:53 +01:00

Create GLib main event loop on non-glib systems

This commit is contained in:
Jonas Kvinge 2021-04-14 00:16:07 +02:00
parent 10aaaebc38
commit 74b7738a9d
2 changed files with 36 additions and 1 deletions

View File

@ -19,10 +19,15 @@
#include "config.h" #include "config.h"
#include <cstring>
#include <glib.h>
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/pbutils/pbutils.h> #include <gst/pbutils/pbutils.h>
#include <QtGlobal>
#include <QObject> #include <QObject>
#include <QMetaObject>
#include <QCoreApplication> #include <QCoreApplication>
#include <QStandardPaths> #include <QStandardPaths>
#include <QtConcurrent> #include <QtConcurrent>
@ -30,6 +35,7 @@
#include <QString> #include <QString>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QAbstractEventDispatcher>
#include "core/logging.h" #include "core/logging.h"
#include "core/utilities.h" #include "core/utilities.h"
@ -40,15 +46,38 @@
#include "gststartup.h" #include "gststartup.h"
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;
}
GstStartup::GstStartup(QObject *parent) : QObject(parent) { GstStartup::GstStartup(QObject *parent) : QObject(parent) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
initializing_ = QtConcurrent::run(&GstStartup::InitializeGStreamer, this); initializing_ = QtConcurrent::run(&GstStartup::InitializeGStreamer, this);
#else #else
initializing_ = QtConcurrent::run(this, &GstStartup::InitializeGStreamer); initializing_ = QtConcurrent::run(this, &GstStartup::InitializeGStreamer);
#endif #endif
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);
}
} }
GstStartup::~GstStartup() {} GstStartup::~GstStartup() {
if (kGThread) g_thread_unref(kGThread);
}
void GstStartup::InitializeGStreamer() { void GstStartup::InitializeGStreamer() {

View File

@ -22,8 +22,10 @@
#include "config.h" #include "config.h"
#include <glib.h>
#include <gst/gst.h> #include <gst/gst.h>
#include <QtGlobal>
#include <QObject> #include <QObject>
#include <QFuture> #include <QFuture>
@ -37,8 +39,12 @@ class GstStartup : public QObject {
void EnsureInitialized() { initializing_.waitForFinished(); } void EnsureInitialized() { initializing_.waitForFinished(); }
private: private:
static GThread *kGThread;
static gpointer GLibMainLoopThreadFunc(gpointer);
void InitializeGStreamer(); void InitializeGStreamer();
void SetEnvironment(); void SetEnvironment();
QFuture<void> initializing_; QFuture<void> initializing_;
}; };