Move GstStartup

This commit is contained in:
Jonas Kvinge
2024-11-09 23:26:33 +01:00
parent b75410abc6
commit 975d0dff25
12 changed files with 56 additions and 100 deletions

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2018-2024, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,15 +25,11 @@
#include <gst/gst.h>
#include <gst/pbutils/pbutils.h>
#include <QObject>
#include <QMetaObject>
#include <QCoreApplication>
#include <QStandardPaths>
#include <QtConcurrentRun>
#include <QString>
#include <QDir>
#include <QFile>
#include <QAbstractEventDispatcher>
#include "core/logging.h"
#include "utilities/envutils.h"
@@ -46,38 +42,9 @@
using namespace Qt::Literals::StringLiterals;
GThread *GstStartup::kGThread = nullptr;
namespace GstStartup {
gpointer GstStartup::GLibMainLoopThreadFunc(gpointer data) {
Q_UNUSED(data)
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) {
initializing_ = QtConcurrent::run(&GstStartup::InitializeGStreamer);
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() {
if (kGThread) g_thread_unref(kGThread);
}
void GstStartup::InitializeGStreamer() {
void Initialize() {
SetEnvironment();
@@ -110,7 +77,7 @@ void GstStartup::InitializeGStreamer() {
}
void GstStartup::SetEnvironment() {
void SetEnvironment() {
#ifdef USE_BUNDLE
@@ -177,7 +144,6 @@ void GstStartup::SetEnvironment() {
#endif // USE_BUNDLE
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
QString gst_registry_filename = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QStringLiteral("/gst-registry-%1-bin").arg(QCoreApplication::applicationVersion());
qLog(Debug) << "Setting GStreamer registry file to" << gst_registry_filename;
@@ -185,3 +151,5 @@ void GstStartup::SetEnvironment() {
#endif
}
} // namespace GstStartup