Gstreamer glib event loop for macos and windows

- This ensures that gstreamer bus operations work
on macOS and windows, such as enumerating devices.
This commit is contained in:
Joe Donofry 2022-01-02 21:15:10 +00:00
parent 1c83ce1e79
commit 9033235e9d
4 changed files with 39 additions and 8 deletions

View file

@ -34,6 +34,11 @@
#include "emoji/MacHelper.h"
#endif
#if defined(GSTREAMER_AVAILABLE) && (defined(Q_OS_MAC) || defined(Q_OS_WINDOWS))
#include <QAbstractEventDispatcher>
#include <gst/gst.h>
#endif
#ifdef QML_DEBUGGING
#include <QQmlDebuggingEnabler>
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;