mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(groups): don't invalidate all audio sources when peer list changes
Fix #5508
This commit is contained in:
parent
093962e3ec
commit
8422c09f6a
|
@ -557,10 +557,6 @@ void Core::onGroupMessage(Tox*, uint32_t groupId, uint32_t peerId, Tox_Message_T
|
|||
void Core::onGroupPeerListChange(Tox*, uint32_t groupId, void* vCore)
|
||||
{
|
||||
const auto core = static_cast<Core*>(vCore);
|
||||
if (core->getGroupAvEnabled(groupId)) {
|
||||
CoreAV::invalidateGroupCallSources(groupId);
|
||||
}
|
||||
|
||||
qDebug() << QString("Group %1 peerlist changed").arg(groupId);
|
||||
emit core->groupPeerlistChanged(groupId);
|
||||
}
|
||||
|
|
|
@ -501,11 +501,11 @@ void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const i
|
|||
}
|
||||
|
||||
Audio& audio = Audio::getInstance();
|
||||
if(!call.havePeer(peer)) {
|
||||
call.addPeer(peer);
|
||||
if(!call.havePeer(peerPk)) {
|
||||
call.addPeer(peerPk);
|
||||
}
|
||||
|
||||
audio.playAudioBuffer(call.getAlSource(peer), data, samples, channels, sample_rate);
|
||||
audio.playAudioBuffer(call.getAlSource(peerPk), data, samples, channels, sample_rate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -513,23 +513,13 @@ void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const i
|
|||
* @param group Group Index
|
||||
* @param peer Peer Index
|
||||
*/
|
||||
void CoreAV::invalidateGroupCallPeerSource(int group, int peer)
|
||||
void CoreAV::invalidateGroupCallPeerSource(int group, ToxPk peerPk)
|
||||
{
|
||||
auto it = groupCalls.find(group);
|
||||
if (it == groupCalls.end()) {
|
||||
return;
|
||||
}
|
||||
it->second.removePeer(peer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called from core to make sure the sources for that group are invalidated when
|
||||
* the peer list changes.
|
||||
* @param group Group Index
|
||||
*/
|
||||
void CoreAV::invalidateGroupCallSources(int group)
|
||||
{
|
||||
groupCalls.erase(group);
|
||||
it->second.removePeer(peerPk);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,8 +79,7 @@ public:
|
|||
static void groupCallCallback(void* tox, uint32_t group, uint32_t peer, const int16_t* data,
|
||||
unsigned samples, uint8_t channels, uint32_t sample_rate,
|
||||
void* core);
|
||||
static void invalidateGroupCallPeerSource(int group, int peer);
|
||||
static void invalidateGroupCallSources(int group);
|
||||
void invalidateGroupCallPeerSource(int group, ToxPk peerPk);
|
||||
|
||||
public slots:
|
||||
bool startCall(uint32_t friendNum, bool video);
|
||||
|
|
|
@ -298,12 +298,12 @@ ToxGroupCall& ToxGroupCall::operator=(ToxGroupCall&& other) noexcept
|
|||
return *this;
|
||||
}
|
||||
|
||||
void ToxGroupCall::removePeer(int peerId)
|
||||
void ToxGroupCall::removePeer(ToxPk 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";
|
||||
qDebug() << "Peer does not have a source, can't remove";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,7 @@ void ToxGroupCall::removePeer(int peerId)
|
|||
peers.remove(peerId);
|
||||
}
|
||||
|
||||
void ToxGroupCall::addPeer(int peerId)
|
||||
void ToxGroupCall::addPeer(ToxPk peerId)
|
||||
{
|
||||
auto& audio = Audio::getInstance();
|
||||
uint sourceId = 0;
|
||||
|
@ -319,7 +319,7 @@ void ToxGroupCall::addPeer(int peerId)
|
|||
peers.insert(peerId, sourceId);
|
||||
}
|
||||
|
||||
bool ToxGroupCall::havePeer(int peerId)
|
||||
bool ToxGroupCall::havePeer(ToxPk peerId)
|
||||
{
|
||||
const auto& sourceId = peers.find(peerId);
|
||||
return sourceId != peers.constEnd();
|
||||
|
@ -336,7 +336,7 @@ void ToxGroupCall::clearPeers()
|
|||
peers.clear();
|
||||
}
|
||||
|
||||
quint32 ToxGroupCall::getAlSource(int peer)
|
||||
quint32 ToxGroupCall::getAlSource(ToxPk peer)
|
||||
{
|
||||
if(!havePeer(peer)) {
|
||||
qWarning() << "Getting alSource for non-existant peer";
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
#ifndef TOXCALL_H
|
||||
#define TOXCALL_H
|
||||
|
||||
#include <memory>
|
||||
#include <src/core/toxpk.h>
|
||||
#include <tox/toxav.h>
|
||||
|
||||
#include <QMap>
|
||||
#include <QMetaObject>
|
||||
#include <QtGlobal>
|
||||
#include <cstdint>
|
||||
|
||||
#include <tox/toxav.h>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
class QTimer;
|
||||
class AudioFilterer;
|
||||
|
@ -96,15 +98,15 @@ public:
|
|||
|
||||
ToxGroupCall& operator=(ToxGroupCall&& other) noexcept;
|
||||
|
||||
void removePeer(int peerId);
|
||||
void addPeer(int peerId);
|
||||
bool havePeer(int peerId);
|
||||
void removePeer(ToxPk peerId);
|
||||
void addPeer(ToxPk peerId);
|
||||
bool havePeer(ToxPk peerId);
|
||||
void clearPeers();
|
||||
|
||||
quint32 getAlSource(int peer);
|
||||
quint32 getAlSource(ToxPk peer);
|
||||
|
||||
private:
|
||||
QMap<int, quint32> peers;
|
||||
QMap<ToxPk, quint32> peers;
|
||||
|
||||
// If you add something here, don't forget to override the ctors and move operators!
|
||||
};
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/core/coreav.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/widget/form/groupchatform.h"
|
||||
#include "src/widget/groupwidget.h"
|
||||
|
@ -99,6 +100,7 @@ void Group::regeneratePeerList()
|
|||
const Core* core = Core::getInstance();
|
||||
|
||||
QStringList peers = core->getGroupPeerNames(groupId);
|
||||
const auto oldPeers = toxpks.keys();
|
||||
toxpks.clear();
|
||||
const int nPeers = peers.size();
|
||||
for (int i = 0; i < nPeers; ++i) {
|
||||
|
@ -118,7 +120,9 @@ void Group::regeneratePeerList()
|
|||
toxpks[pk] = peers[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (avGroupchat) {
|
||||
stopAudioOfDepartedPeers(oldPeers, toxpks);
|
||||
}
|
||||
emit userListChanged(groupId, toxpks);
|
||||
}
|
||||
|
||||
|
@ -197,3 +201,13 @@ QString Group::getSelfName() const
|
|||
{
|
||||
return selfName;
|
||||
}
|
||||
|
||||
void Group::stopAudioOfDepartedPeers(const QList<ToxPk>& oldPks, const QMap<ToxPk, QString>& newPks)
|
||||
{
|
||||
Core* core = Core::getInstance();
|
||||
for(const auto& pk: oldPks) {
|
||||
if(!newPks.contains(pk)) {
|
||||
core->getAv()->invalidateGroupCallPeerSource(groupId, pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,9 @@ signals:
|
|||
void titleChanged(uint32_t groupId, const QString& author, const QString& title);
|
||||
void userListChanged(uint32_t groupId, const QMap<ToxPk, QString>& toxpks);
|
||||
|
||||
private:
|
||||
void stopAudioOfDepartedPeers(const QList<ToxPk>& oldPks, const QMap<ToxPk, QString>& newPks);
|
||||
|
||||
private:
|
||||
QString selfName;
|
||||
QString title;
|
||||
|
|
Loading…
Reference in New Issue
Block a user