From 9033235e9da36bfdb10a83f96c713190f0505ca8 Mon Sep 17 00:00:00 2001 From: Joe Donofry Date: Sun, 2 Jan 2022 21:15:10 +0000 Subject: [PATCH] Gstreamer glib event loop for macos and windows - This ensures that gstreamer bus operations work on macOS and windows, such as enumerating devices. --- CMakeLists.txt | 2 +- src/main.cpp | 32 ++++++++++++++++++++++++++++++++ src/voip/CallDevices.cpp | 7 +++---- src/voip/CallManager.cpp | 6 +++--- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a98bc1c..90f906c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -504,7 +504,7 @@ endif() if (VOIP) include(FindPkgConfig) pkg_check_modules(GSTREAMER REQUIRED IMPORTED_TARGET gstreamer-sdp-1.0>=1.18 gstreamer-webrtc-1.0>=1.18) - if (SCREENSHARE_X11) + if (SCREENSHARE_X11 AND NOT WIN32 AND NOT APPLE) pkg_check_modules(XCB REQUIRED IMPORTED_TARGET xcb xcb-ewmh) endif() endif() 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; diff --git a/src/voip/CallDevices.cpp b/src/voip/CallDevices.cpp index 353fc4a5..b0c90d84 100644 --- a/src/voip/CallDevices.cpp +++ b/src/voip/CallDevices.cpp @@ -8,7 +8,6 @@ #include #include "CallDevices.h" -#include "ChatPage.h" #include "Logging.h" #include "UserSettingsPage.h" @@ -70,7 +69,7 @@ addFrameRate(std::vector &rates, const FrameRate &rate) void setDefaultDevice(bool isVideo) { - auto settings = ChatPage::instance()->userSettings(); + auto settings = UserSettings::instance(); if (isVideo && settings->camera().isEmpty()) { const VideoSource &camera = videoSources_.front(); settings->setCamera(QString::fromStdString(camera.name)); @@ -320,7 +319,7 @@ CallDevices::frameRates(const std::string &cameraName, const std::string &resolu GstDevice * CallDevices::audioDevice() const { - std::string name = ChatPage::instance()->userSettings()->microphone().toStdString(); + std::string name = UserSettings::instance()->microphone().toStdString(); if (auto it = std::find_if(audioSources_.cbegin(), audioSources_.cend(), [&name](const auto &s) { return s.name == name; }); @@ -336,7 +335,7 @@ CallDevices::audioDevice() const GstDevice * CallDevices::videoDevice(std::pair &resolution, std::pair &frameRate) const { - auto settings = ChatPage::instance()->userSettings(); + auto settings = UserSettings::instance(); std::string name = settings->camera().toStdString(); if (auto s = getVideoSource(name); s) { nhlog::ui()->debug("WebRTC: camera: {}", name); diff --git a/src/voip/CallManager.cpp b/src/voip/CallManager.cpp index f184b622..54d86620 100644 --- a/src/voip/CallManager.cpp +++ b/src/voip/CallManager.cpp @@ -292,7 +292,7 @@ CallManager::handleEvent(const RoomEvent &callInviteEvent) return; } - const QString &ringtone = ChatPage::instance()->userSettings()->ringtone(); + const QString &ringtone = UserSettings::instance()->ringtone(); if (ringtone != QLatin1String("Mute")) playRingtone(ringtone == QLatin1String("Default") ? QUrl(QStringLiteral("qrc:/media/media/ring.ogg")) @@ -431,8 +431,8 @@ QStringList CallManager::devices(bool isVideo) const { QStringList ret; - const QString &defaultDevice = isVideo ? ChatPage::instance()->userSettings()->camera() - : ChatPage::instance()->userSettings()->microphone(); + const QString &defaultDevice = + isVideo ? UserSettings::instance()->camera() : UserSettings::instance()->microphone(); std::vector devices = CallDevices::instance().names(isVideo, defaultDevice.toStdString()); ret.reserve(devices.size());