From 9033235e9da36bfdb10a83f96c713190f0505ca8 Mon Sep 17 00:00:00 2001 From: Joe Donofry Date: Sun, 2 Jan 2022 21:15:10 +0000 Subject: Gstreamer glib event loop for macos and windows - This ensures that gstreamer bus operations work on macOS and windows, such as enumerating devices. --- src/main.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 4ecc18d2..2ae631cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,6 +34,11 @@ #include "emoji/MacHelper.h" #endif +#if defined(GSTREAMER_AVAILABLE) && (defined(Q_OS_MAC) || defined(Q_OS_WINDOWS)) +#include +#include +#endif + #ifdef QML_DEBUGGING #include QQmlDebuggingEnabler enabler; @@ -100,6 +105,23 @@ registerSignalHandlers() #endif +#if defined(GSTREAMER_AVAILABLE) && (defined(Q_OS_MAC) || defined(Q_OS_WINDOWS)) +GMainLoop *gloop = 0; +GThread *gthread = 0; + +extern "C" +{ + static gpointer glibMainLoopThreadFunc(gpointer) + { + gloop = g_main_loop_new(0, false); + g_main_loop_run(gloop); + g_main_loop_unref(gloop); + gloop = 0; + return 0; + } +} // extern "C" +#endif + QPoint screenCenter(int width, int height) { @@ -220,6 +242,16 @@ main(int argc, char *argv[]) registerSignalHandlers(); +#if defined(GSTREAMER_AVAILABLE) && (defined(Q_OS_MAC) || defined(Q_OS_WINDOWS)) + // If the version of Qt we're running in does not use GLib, we need to + // start a GMainLoop so that gstreamer can dispatch events. + const QMetaObject *mo = QAbstractEventDispatcher::instance(qApp->thread())->metaObject(); + if (gloop == 0 && strcmp(mo->className(), "QEventDispatcherGlib") != 0 && + strcmp(mo->superClass()->className(), "QEventDispatcherGlib") != 0) { + gthread = g_thread_new(0, glibMainLoopThreadFunc, 0); + } +#endif + if (parser.isSet(debugOption)) nhlog::enable_debug_log_from_commandline = true; -- cgit 1.5.1