refactor(toxcall): move peer handling to ToxGroupCall

reviewable/pr5200/r2
sudden6 2018-07-01 10:16:21 +02:00
parent 811998b8df
commit 67f2605971
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
3 changed files with 51 additions and 14 deletions

View File

@ -506,12 +506,11 @@ void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const i
}
Audio& audio = Audio::getInstance();
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]);
if(!call.havePeer(peer)) {
call.addPeer(peer);
}
audio.playAudioBuffer(call.getPeers()[peer], data, samples, channels, sample_rate);
audio.playAudioBuffer(call.getAlSource(peer), data, samples, channels, sample_rate);
}
#else
void CoreAV::groupCallCallback(void* tox, int group, int peer, const int16_t* data,
@ -536,9 +535,8 @@ void CoreAV::groupCallCallback(void* tox, int group, int peer, const int16_t* da
}
Audio& audio = Audio::getInstance();
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]);
if(!call.havePeer(peer)) {
call.addPeer(peer);
}
audio.playAudioBuffer(call.getPeers()[peer], data, samples, channels, sample_rate);
@ -556,9 +554,7 @@ void CoreAV::invalidateGroupCallPeerSource(int group, int peer)
if (it == groupCalls.end()) {
return;
}
Audio& audio = Audio::getInstance();
audio.unsubscribeOutput(it->second.getPeers()[peer]);
it->second.getPeers()[peer] = 0;
it->second.removePeer(peer);
}
/**
@ -752,7 +748,7 @@ bool CoreAV::isCallOutputMuted(const Friend* f) const
void CoreAV::invalidateCallSources()
{
for (auto& kv : groupCalls) {
kv.second.getPeers().clear();
kv.second.clearPeers();
}
for (auto& kv : calls) {

View File

@ -287,10 +287,48 @@ ToxGroupCall& ToxGroupCall::operator=(ToxGroupCall&& other) noexcept
void ToxGroupCall::removePeer(int peerId)
{
auto& audio = Audio::getInstance();
const auto& sourceId = peers.find(peerId);
if(sourceId == peers.constEnd()) {
qDebug() << "Peer:" << peerId << "does not have a source, can't remove";
return;
}
audio.unsubscribeOutput(sourceId.value());
peers.remove(peerId);
}
QMap<int, quint32>& ToxGroupCall::getPeers()
void ToxGroupCall::addPeer(int peerId)
{
return peers;
auto& audio = Audio::getInstance();
uint sourceId = 0;
audio.subscribeOutput(sourceId);
peers.insert(peerId, sourceId);
}
bool ToxGroupCall::havePeer(int peerId)
{
const auto& sourceId = peers.find(peerId);
return sourceId != peers.constEnd();
}
void ToxGroupCall::clearPeers()
{
Audio& audio = Audio::getInstance();
for (quint32 v : peers) {
audio.unsubscribeOutput(v);
}
peers.clear();
}
quint32 ToxGroupCall::getAlSource(int peer)
{
if(!havePeer(peer)) {
qWarning() << "Getting alSource for non-existant peer";
return 0;
}
return peers[peer];
}

View File

@ -97,8 +97,11 @@ public:
ToxGroupCall& operator=(ToxGroupCall&& other) noexcept;
void removePeer(int peerId);
void addPeer(int peerId);
bool havePeer(int peerId);
void clearPeers();
QMap<int, quint32>& getPeers();
quint32 getAlSource(int peer);
private:
QMap<int, quint32> peers;