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

Commit

Permalink
fix(call): fix bugs introduced from ToxCall refactor
Browse files Browse the repository at this point in the history
-inverted call active booleans
-audio subscription leak on move assignment
-NullVideoBitrate check
-return peers list by reference so that adding audio source in GroupCallCallback is persisted
-fix output muting for friend calls
  • Loading branch information
anthonybilinski committed Nov 2, 2017
1 parent 4af90a7 commit 1394dd1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/core/coreav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ bool CoreAV::answerCall(uint32_t friendNum, bool video)

const uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0;
if (toxav_answer(toxav, friendNum, Settings::getInstance().getAudioBitrate(), videoBitrate, &err)) {
calls[friendNum].setActive(false);
calls[friendNum].setActive(true);
return true;
} else {
qWarning() << "Failed to answer call with error" << err;
Expand Down Expand Up @@ -344,7 +344,7 @@ bool CoreAV::sendCallAudio(uint32_t callId, const int16_t* pcm, size_t samples,

ToxFriendCall& call = calls[callId];

if (call.getMuteMic() || call.isActive()
if (call.getMuteMic() || !call.isActive()
|| !(call.getState() & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A)) {
return true;
}
Expand Down Expand Up @@ -379,15 +379,15 @@ void CoreAV::sendCallVideo(uint32_t callId, std::shared_ptr<VideoFrame> vframe)

ToxFriendCall& call = calls[callId];

if (!call.getVideoEnabled() || call.isActive()
if (!call.getVideoEnabled() || !call.isActive()
|| !(call.getState() & TOXAV_FRIEND_CALL_STATE_ACCEPTING_V)) {
return;
}

if (call.getVideoEnabled()) {
if (call.getNullVideoBitrate()) {
qDebug() << "Restarting video stream to friend" << callId;
toxav_bit_rate_set(toxav, callId, -1, VIDEO_DEFAULT_BITRATE, nullptr);
call.setVideoEnabled(false);
call.setNullVideoBitrate(false);
}

ToxYUVFrame frame = vframe->toToxYUVFrame();
Expand Down Expand Up @@ -436,7 +436,7 @@ void CoreAV::toggleMuteCallOutput(const Friend* f)
{
if (f && (calls.find(f->getId()) != calls.end())) {
ToxCall& call = calls[f->getId()];
call.setMuteVol(call.getMuteVol());
call.setMuteVol(!call.getMuteVol());
}
}

Expand Down Expand Up @@ -473,8 +473,10 @@ void CoreAV::groupCallCallback(void* tox, int group, int peer, const int16_t* da
}

Audio& audio = Audio::getInstance();
if (!call.getPeers()[peer])
if (!call.getPeers()[peer]) {
// FIXME: 0 is a valid sourceId, we shouldn't necessarily re-subscribe just because we have 0
audio.subscribeOutput(call.getPeers()[peer]);
}

audio.playAudioBuffer(call.getPeers()[peer], data, samples, channels, sample_rate);
}
Expand Down Expand Up @@ -517,7 +519,7 @@ void CoreAV::joinGroupCall(int groupId)
qDebug() << QString("Joining group call %1").arg(groupId);

groupCalls[groupId] = ToxGroupCall{groupId, *this};
groupCalls[groupId].setActive(false);
groupCalls[groupId].setActive(true);
}

/**
Expand All @@ -541,7 +543,7 @@ bool CoreAV::sendGroupCallAudio(int groupId, const int16_t* pcm, size_t samples,

ToxGroupCall& call = groupCalls[groupId];

if (call.isActive() || call.getMuteMic()) {
if (!call.isActive() || call.getMuteMic()) {
return true;
}

Expand Down Expand Up @@ -772,7 +774,7 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi
// If our state was null, we started the call and were still ringing
if (!call.getState() && state) {
call.stopTimeout();
call.setActive(false);
call.setActive(true);
emit self->avStart(friendNum, call.getVideoEnabled());
} else if ((call.getState() & TOXAV_FRIEND_CALL_STATE_SENDING_V)
&& !(state & TOXAV_FRIEND_CALL_STATE_SENDING_V)) {
Expand Down
9 changes: 8 additions & 1 deletion src/core/toxcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ ToxCall::~ToxCall()

ToxCall& ToxCall::operator=(ToxCall&& other) noexcept
{
if (valid) {
// if we're already valid, we need to cleanup our resources since we're going to inherit the resources
// that are being moved in
QObject::disconnect(audioInConn);
Audio::getInstance().unsubscribeInput();
}

audioInConn = other.audioInConn;
other.audioInConn = QMetaObject::Connection();
active = other.active;
Expand Down Expand Up @@ -312,7 +319,7 @@ void ToxGroupCall::removePeer(int peerId)
peers.remove(peerId);
}

QMap<int, quint32> ToxGroupCall::getPeers() const
QMap<int, quint32>& ToxGroupCall::getPeers()
{
return peers;
}
2 changes: 1 addition & 1 deletion src/core/toxcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ToxGroupCall : public ToxCall

void removePeer(int peerId);

QMap<int, quint32> getPeers() const;
QMap<int, quint32>& getPeers();

private:
QMap<int, quint32> peers;
Expand Down

0 comments on commit 1394dd1

Please sign in to comment.