Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(toxcall): handle Null sink correctly
Browse files Browse the repository at this point in the history
This was introduced in 82a4f1b

(cherry picked from commit bf3921c)
  • Loading branch information
sudden6 authored and anthonybilinski committed Mar 20, 2020
1 parent 19e1728 commit f02943c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/core/toxcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,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) {
Expand Down Expand Up @@ -175,15 +176,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);
}

Expand Down Expand Up @@ -269,7 +272,12 @@ void ToxGroupCall::removePeer(ToxPk peerId)
void ToxGroupCall::addPeer(ToxPk peerId)
{
std::unique_ptr<IAudioSink> 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});
Expand Down

0 comments on commit f02943c

Please sign in to comment.