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

Commit

Permalink
fix(audio): alternate audio fix implementation from #4139
Browse files Browse the repository at this point in the history
  • Loading branch information
agrecascino authored and Anthony Recascino committed Feb 7, 2017
1 parent 38cecdc commit 62ac480
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ void Core::onGroupMessage(Tox*, uint32_t groupId, uint32_t peerId, TOX_MESSAGE_T
void Core::onGroupNamelistChange(Tox*, uint32_t groupId, uint32_t peerId,
TOX_CONFERENCE_STATE_CHANGE change, void* core)
{
CoreAV* coreAv = static_cast<Core*>(core)->getAv();
if((change == TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT) && (coreAv->isGroupAvEnabled(groupId))) {
CoreAV::invalidateGroupCallPeerSource(groupId, peerId);
}
qDebug() << QString("Group namelist change %1:%2 %3").arg(groupId).arg(peerId).arg(change);
emit static_cast<Core*>(core)->groupNamelistChanged(groupId, peerId, change);
}
Expand Down
19 changes: 15 additions & 4 deletions src/core/coreav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,24 @@ void CoreAV::groupCallCallback(void* tox, int group, int peer,
return;

Audio& audio = Audio::getInstance();
if (!call.alSource)
audio.subscribeOutput(call.alSource);
if (!call.peers[peer])
audio.subscribeOutput(call.peers[peer]);

audio.playAudioBuffer(call.alSource, data, samples, channels,
audio.playAudioBuffer(call.peers[peer], data, samples, channels,
sample_rate);
}

/**
* @brief Called from core to make sure the source for that peer is invalidated when they leave.
* @param group Group Index
* @param peer Peer Index
*/
void CoreAV::invalidateGroupCallPeerSource(int group, int peer) {
Audio &audio = Audio::getInstance();
audio.unsubscribeOutput(groupCalls[group].peers[peer]);
groupCalls[group].peers[peer] = 0;
}

/**
* @brief Get a call's video source.
* @param friendNum Id of friend in call list.
Expand Down Expand Up @@ -662,7 +673,7 @@ void CoreAV::invalidateCallSources()
{
for (ToxGroupCall& call : groupCalls)
{
call.alSource = 0;
call.peers.clear();
}

for (ToxFriendCall& call : calls)
Expand Down
1 change: 1 addition & 0 deletions src/core/coreav.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CoreAV : public QObject
const int16_t* data, unsigned samples,
uint8_t channels, unsigned sample_rate,
void* core);
static void invalidateGroupCallPeerSource(int group, int peer);

public slots:
bool startCall(uint32_t friendNum, bool video=false);
Expand Down
13 changes: 13 additions & 0 deletions src/core/toxcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*
* @var TOXAV_FRIEND_CALL_STATE ToxFriendCall::state
* @brief State of the peer (not ours!)
*
* @var QMap ToxGroupCall::peers
* @brief Keeps sources for users in group calls.
*/

using namespace std;
Expand Down Expand Up @@ -192,6 +195,16 @@ ToxGroupCall::ToxGroupCall(ToxGroupCall&& other) noexcept
{
}

ToxGroupCall::~ToxGroupCall()
{
Audio& audio = Audio::getInstance();

for(quint32 v : peers)
{
audio.unsubscribeOutput(v);
}
}

ToxGroupCall &ToxGroupCall::operator=(ToxGroupCall &&other) noexcept
{
ToxCall::operator =(move(other));
Expand Down
4 changes: 4 additions & 0 deletions src/core/toxcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdint>
#include <QtGlobal>
#include <QMetaObject>
#include <QMap>

#include "src/core/indexedlist.h"

Expand Down Expand Up @@ -69,9 +70,12 @@ struct ToxGroupCall : public ToxCall
ToxGroupCall() = default;
ToxGroupCall(int GroupNum, CoreAV& av);
ToxGroupCall(ToxGroupCall&& other) noexcept;
~ToxGroupCall();

ToxGroupCall& operator=(ToxGroupCall&& other) noexcept;

QMap<int, quint32> peers;

// If you add something here, don't forget to override the ctors and move operators!
};

Expand Down

0 comments on commit 62ac480

Please sign in to comment.