From bf3921ce94251a3f56d5f83d1c03735d7fad3821 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Sun, 9 Feb 2020 23:47:14 +0100 Subject: [PATCH] fix(toxcall): handle Null sink correctly This was introduced in 82a4f1b41292eae981b9374824ff1499ca1cfcb4 --- src/core/toxcall.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/core/toxcall.cpp b/src/core/toxcall.cpp index b5ffdab59..4d3baf5fc 100644 --- a/src/core/toxcall.cpp +++ b/src/core/toxcall.cpp @@ -133,14 +133,15 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av, this->av->sendCallAudio(this->friendId, pcm, samples, chans, rate); }); - audioSrcInvalid = QObject::connect(audioSource.get(), &IAudioSource::invalidated, - [this]() { this->onAudioSourceInvalidated(); }); + connect(audioSource.get(), &IAudioSource::invalidated, this, &ToxFriendCall::onAudioSourceInvalidated); if (!audioInConn) { qDebug() << "Audio input connection not working"; } - audioSinkInvalid = sink->connectTo_invalidated(this, [this]() { this->onAudioSinkInvalidated(); }); + if (sink) { + audioSinkInvalid = sink->connectTo_invalidated(this, [this]() { this->onAudioSinkInvalidated(); }); + } // register video if (videoEnabled) { @@ -176,15 +177,17 @@ void ToxFriendCall::onAudioSourceInvalidated() }); audioSource = std::move(newSrc); - audioSrcInvalid = QObject::connect(audioSource.get(), &IAudioSource::invalidated, - [this]() { this->onAudioSourceInvalidated(); }); + connect(audioSource.get(), &IAudioSource::invalidated, this, &ToxFriendCall::onAudioSourceInvalidated); } void ToxFriendCall::onAudioSinkInvalidated() { auto newSink = audio.makeSink(); - audioSinkInvalid = newSink->connectTo_invalidated(this, [this]() { this->onAudioSinkInvalidated(); }); + if (newSink) { + audioSinkInvalid = newSink->connectTo_invalidated(this, [this]() { this->onAudioSinkInvalidated(); }); + } + sink = std::move(newSink); } @@ -276,7 +279,12 @@ void ToxGroupCall::removePeer(ToxPk peerId) void ToxGroupCall::addPeer(ToxPk peerId) { std::unique_ptr newSink = audio.makeSink(); - QMetaObject::Connection con = newSink->connectTo_invalidated(this, [this, peerId]() { this->onAudioSinkInvalidated(peerId); }); + + QMetaObject::Connection con; + + if (newSink) { + con = newSink->connectTo_invalidated(this, [this, peerId]() { this->onAudioSinkInvalidated(peerId); }); + } peers.emplace(peerId, std::move(newSink)); sinkInvalid.insert({peerId, con});