mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(toxcall): move peer handling to ToxGroupCall
This commit is contained in:
parent
811998b8df
commit
67f2605971
|
@ -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) {
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user