Fix crash on exit

This commit is contained in:
trilene 2020-10-27 17:26:46 -04:00
parent d9ca5309ac
commit b1300aff46
7 changed files with 30 additions and 38 deletions

View File

@ -12,7 +12,6 @@
#include "Logging.h" #include "Logging.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "UserSettingsPage.h"
#include "WebRTCSession.h" #include "WebRTCSession.h"
#include "dialogs/AcceptCall.h" #include "dialogs/AcceptCall.h"
@ -30,18 +29,15 @@ std::vector<std::string>
getTurnURIs(const mtx::responses::TurnServer &turnServer); getTurnURIs(const mtx::responses::TurnServer &turnServer);
} }
CallManager::CallManager(QSharedPointer<UserSettings> userSettings) CallManager::CallManager()
: QObject() : QObject()
, session_(WebRTCSession::instance()) , session_(WebRTCSession::instance())
, turnServerTimer_(this) , turnServerTimer_(this)
, settings_(userSettings)
{ {
qRegisterMetaType<std::vector<mtx::events::msg::CallCandidates::Candidate>>(); qRegisterMetaType<std::vector<mtx::events::msg::CallCandidates::Candidate>>();
qRegisterMetaType<mtx::events::msg::CallCandidates::Candidate>(); qRegisterMetaType<mtx::events::msg::CallCandidates::Candidate>();
qRegisterMetaType<mtx::responses::TurnServer>(); qRegisterMetaType<mtx::responses::TurnServer>();
session_.setSettings(userSettings);
connect( connect(
&session_, &session_,
&WebRTCSession::offerCreated, &WebRTCSession::offerCreated,
@ -265,7 +261,6 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
caller.display_name, caller.display_name,
QString::fromStdString(roomInfo.name), QString::fromStdString(roomInfo.name),
QString::fromStdString(roomInfo.avatar_url), QString::fromStdString(roomInfo.avatar_url),
settings_,
isVideo, isVideo,
MainWindow::instance()); MainWindow::instance());
connect(dialog, &dialogs::AcceptCall::accept, this, [this, callInviteEvent, isVideo]() { connect(dialog, &dialogs::AcceptCall::accept, this, [this, callInviteEvent, isVideo]() {

View File

@ -5,7 +5,6 @@
#include <QMediaPlayer> #include <QMediaPlayer>
#include <QObject> #include <QObject>
#include <QSharedPointer>
#include <QString> #include <QString>
#include <QTimer> #include <QTimer>
@ -16,7 +15,6 @@ namespace mtx::responses {
struct TurnServer; struct TurnServer;
} }
class UserSettings;
class WebRTCSession; class WebRTCSession;
class CallManager : public QObject class CallManager : public QObject
@ -24,7 +22,7 @@ class CallManager : public QObject
Q_OBJECT Q_OBJECT
public: public:
CallManager(QSharedPointer<UserSettings>); CallManager();
void sendInvite(const QString &roomid, bool isVideo); void sendInvite(const QString &roomid, bool isVideo);
void hangUp( void hangUp(
@ -59,7 +57,6 @@ private:
std::vector<mtx::events::msg::CallCandidates::Candidate> remoteICECandidates_; std::vector<mtx::events::msg::CallCandidates::Candidate> remoteICECandidates_;
std::vector<std::string> turnURIs_; std::vector<std::string> turnURIs_;
QTimer turnServerTimer_; QTimer turnServerTimer_;
QSharedPointer<UserSettings> settings_;
QMediaPlayer player_; QMediaPlayer player_;
template<typename T> template<typename T>

View File

@ -69,7 +69,6 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
, isConnected_(true) , isConnected_(true)
, userSettings_{userSettings} , userSettings_{userSettings}
, notificationsManager(this) , notificationsManager(this)
, callManager_(userSettings)
{ {
setObjectName("chatPage"); setObjectName("chatPage");

View File

@ -9,6 +9,7 @@
#include <string_view> #include <string_view>
#include <utility> #include <utility>
#include "ChatPage.h"
#include "Logging.h" #include "Logging.h"
#include "UserSettingsPage.h" #include "UserSettingsPage.h"
#include "WebRTCSession.h" #include "WebRTCSession.h"
@ -847,7 +848,7 @@ WebRTCSession::startPipeline(int opusPayloadType, int vp8PayloadType)
webrtc_ = gst_bin_get_by_name(GST_BIN(pipe_), "webrtcbin"); webrtc_ = gst_bin_get_by_name(GST_BIN(pipe_), "webrtcbin");
if (settings_->useStunServer()) { if (ChatPage::instance()->userSettings()->useStunServer()) {
nhlog::ui()->info("WebRTC: setting STUN server: {}", STUN_SERVER); nhlog::ui()->info("WebRTC: setting STUN server: {}", STUN_SERVER);
g_object_set(webrtc_, "stun-server", STUN_SERVER, nullptr); g_object_set(webrtc_, "stun-server", STUN_SERVER, nullptr);
} }
@ -902,15 +903,17 @@ WebRTCSession::startPipeline(int opusPayloadType, int vp8PayloadType)
bool bool
WebRTCSession::createPipeline(int opusPayloadType, int vp8PayloadType) WebRTCSession::createPipeline(int opusPayloadType, int vp8PayloadType)
{ {
auto it = std::find_if(audioSources_.cbegin(), audioSources_.cend(), [this](const auto &s) { std::string microphoneSetting =
return s.name == settings_->microphone().toStdString(); ChatPage::instance()->userSettings()->microphone().toStdString();
}); auto it =
std::find_if(audioSources_.cbegin(),
audioSources_.cend(),
[&microphoneSetting](const auto &s) { return s.name == microphoneSetting; });
if (it == audioSources_.cend()) { if (it == audioSources_.cend()) {
nhlog::ui()->error("WebRTC: unknown microphone: {}", nhlog::ui()->error("WebRTC: unknown microphone: {}", microphoneSetting);
settings_->microphone().toStdString());
return false; return false;
} }
nhlog::ui()->debug("WebRTC: microphone: {}", it->name); nhlog::ui()->debug("WebRTC: microphone: {}", microphoneSetting);
GstElement *source = gst_device_create_element(it->device, nullptr); GstElement *source = gst_device_create_element(it->device, nullptr);
GstElement *volume = gst_element_factory_make("volume", "srclevel"); GstElement *volume = gst_element_factory_make("volume", "srclevel");
@ -977,21 +980,24 @@ WebRTCSession::addVideoPipeline(int vp8PayloadType)
if (videoSources_.empty()) if (videoSources_.empty())
return !isOffering_; return !isOffering_;
auto it = std::find_if(videoSources_.cbegin(), videoSources_.cend(), [this](const auto &s) { std::string cameraSetting = ChatPage::instance()->userSettings()->camera().toStdString();
return s.name == settings_->camera().toStdString(); auto it = std::find_if(videoSources_.cbegin(),
}); videoSources_.cend(),
[&cameraSetting](const auto &s) { return s.name == cameraSetting; });
if (it == videoSources_.cend()) { if (it == videoSources_.cend()) {
nhlog::ui()->error("WebRTC: unknown camera: {}", settings_->camera().toStdString()); nhlog::ui()->error("WebRTC: unknown camera: {}", cameraSetting);
return false; return false;
} }
std::string resSetting = settings_->cameraResolution().toStdString(); std::string resSetting =
ChatPage::instance()->userSettings()->cameraResolution().toStdString();
const std::string &res = resSetting.empty() ? it->caps.front().resolution : resSetting; const std::string &res = resSetting.empty() ? it->caps.front().resolution : resSetting;
std::string frSetting = settings_->cameraFrameRate().toStdString(); std::string frSetting =
ChatPage::instance()->userSettings()->cameraFrameRate().toStdString();
const std::string &fr = frSetting.empty() ? it->caps.front().frameRates.front() : frSetting; const std::string &fr = frSetting.empty() ? it->caps.front().frameRates.front() : frSetting;
auto resolution = tokenise(res, 'x'); auto resolution = tokenise(res, 'x');
auto frameRate = tokenise(fr, '/'); auto frameRate = tokenise(fr, '/');
nhlog::ui()->debug("WebRTC: camera: {}", it->name); nhlog::ui()->debug("WebRTC: camera: {}", cameraSetting);
nhlog::ui()->debug("WebRTC: camera resolution: {}x{}", resolution.first, resolution.second); nhlog::ui()->debug("WebRTC: camera resolution: {}x{}", resolution.first, resolution.second);
nhlog::ui()->debug("WebRTC: camera frame rate: {}/{}", frameRate.first, frameRate.second); nhlog::ui()->debug("WebRTC: camera frame rate: {}/{}", frameRate.first, frameRate.second);

View File

@ -4,13 +4,11 @@
#include <vector> #include <vector>
#include <QObject> #include <QObject>
#include <QSharedPointer>
#include "mtx/events/voip.hpp" #include "mtx/events/voip.hpp"
typedef struct _GstElement GstElement; typedef struct _GstElement GstElement;
class QQuickItem; class QQuickItem;
class UserSettings;
namespace webrtc { namespace webrtc {
Q_NAMESPACE Q_NAMESPACE
@ -57,7 +55,6 @@ public:
bool toggleMicMute(); bool toggleMicMute();
void end(); void end();
void setSettings(QSharedPointer<UserSettings> settings) { settings_ = settings; }
void setTurnServers(const std::vector<std::string> &uris) { turnServers_ = uris; } void setTurnServers(const std::vector<std::string> &uris) { turnServers_ = uris; }
void refreshDevices(); void refreshDevices();
@ -95,7 +92,6 @@ private:
GstElement *pipe_ = nullptr; GstElement *pipe_ = nullptr;
GstElement *webrtc_ = nullptr; GstElement *webrtc_ = nullptr;
unsigned int busWatchId_ = 0; unsigned int busWatchId_ = 0;
QSharedPointer<UserSettings> settings_;
std::vector<std::string> turnServers_; std::vector<std::string> turnServers_;
bool init(std::string *errorMessage = nullptr); bool init(std::string *errorMessage = nullptr);

View File

@ -18,7 +18,6 @@ AcceptCall::AcceptCall(const QString &caller,
const QString &displayName, const QString &displayName,
const QString &roomName, const QString &roomName,
const QString &avatarUrl, const QString &avatarUrl,
QSharedPointer<UserSettings> settings,
bool isVideo, bool isVideo,
QWidget *parent) QWidget *parent)
: QWidget(parent) : QWidget(parent)
@ -35,8 +34,10 @@ AcceptCall::AcceptCall(const QString &caller,
emit close(); emit close();
return; return;
} }
session->refreshDevices(); session->refreshDevices();
microphones_ = session->getDeviceNames(false, settings->microphone().toStdString()); microphones_ = session->getDeviceNames(
false, ChatPage::instance()->userSettings()->microphone().toStdString());
if (microphones_.empty()) { if (microphones_.empty()) {
emit ChatPage::instance()->showNotification( emit ChatPage::instance()->showNotification(
tr("Incoming call: No microphone found.")); tr("Incoming call: No microphone found."));
@ -44,7 +45,8 @@ AcceptCall::AcceptCall(const QString &caller,
return; return;
} }
if (isVideo) if (isVideo)
cameras_ = session->getDeviceNames(true, settings->camera().toStdString()); cameras_ = session->getDeviceNames(
true, ChatPage::instance()->userSettings()->camera().toStdString());
setAutoFillBackground(true); setAutoFillBackground(true);
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
@ -131,11 +133,11 @@ AcceptCall::AcceptCall(const QString &caller,
if (cameraCombo_) if (cameraCombo_)
layout->addWidget(cameraCombo_); layout->addWidget(cameraCombo_);
connect(acceptBtn_, &QPushButton::clicked, this, [this, settings, session]() { connect(acceptBtn_, &QPushButton::clicked, this, [this]() {
settings->setMicrophone( ChatPage::instance()->userSettings()->setMicrophone(
QString::fromStdString(microphones_[microphoneCombo_->currentIndex()])); QString::fromStdString(microphones_[microphoneCombo_->currentIndex()]));
if (cameraCombo_) { if (cameraCombo_) {
settings->setCamera( ChatPage::instance()->userSettings()->setCamera(
QString::fromStdString(cameras_[cameraCombo_->currentIndex()])); QString::fromStdString(cameras_[cameraCombo_->currentIndex()]));
} }
emit accept(); emit accept();

View File

@ -3,13 +3,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <QSharedPointer>
#include <QWidget> #include <QWidget>
class QComboBox; class QComboBox;
class QPushButton; class QPushButton;
class QString; class QString;
class UserSettings;
namespace dialogs { namespace dialogs {
@ -22,7 +20,6 @@ public:
const QString &displayName, const QString &displayName,
const QString &roomName, const QString &roomName,
const QString &avatarUrl, const QString &avatarUrl,
QSharedPointer<UserSettings> settings,
bool isVideo, bool isVideo,
QWidget *parent = nullptr); QWidget *parent = nullptr);