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

@ -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()

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;

View File

@ -8,7 +8,6 @@
#include <string_view>
#include "CallDevices.h"
#include "ChatPage.h"
#include "Logging.h"
#include "UserSettingsPage.h"
@ -70,7 +69,7 @@ addFrameRate(std::vector<std::string> &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<int, int> &resolution, std::pair<int, int> &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);

View File

@ -292,7 +292,7 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &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<std::string> devices =
CallDevices::instance().names(isVideo, defaultDevice.toStdString());
ret.reserve(devices.size());