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

Commit

Permalink
feat(audio): add (repair) support for group audio calls
Browse files Browse the repository at this point in the history
  • Loading branch information
antis81 authored and sudden6 committed Apr 24, 2016
1 parent e5c7b3a commit 356543c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
14 changes: 0 additions & 14 deletions src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,6 @@ void Audio::playMono16Sound(const QByteArray& data)
playMono16Timer.start(durationMs + 50);
}

/**
@brief May be called from any thread, will always queue a call to playGroupAudio.
The first and last argument are ignored, but allow direct compatibility with toxcore.
*/
void Audio::playGroupAudioQueued(void*,int group, int peer, const int16_t* data,
unsigned samples, uint8_t channels, unsigned sample_rate, void* core)
{
QMetaObject::invokeMethod(&Audio::getInstance(), "playGroupAudio", Qt::BlockingQueuedConnection,
Q_ARG(int,group), Q_ARG(int,peer), Q_ARG(const int16_t*,data),
Q_ARG(unsigned,samples), Q_ARG(uint8_t,channels), Q_ARG(unsigned,sample_rate));
emit static_cast<Core*>(core)->groupPeerAudioPlaying(group, peer);
}

void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate)
{
assert(channels == 1 || channels == 2);
Expand Down
3 changes: 0 additions & 3 deletions src/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ class Audio : public QObject
void playAudioBuffer(ALuint alSource, const int16_t *data, int samples,
unsigned channels, int sampleRate);

static void playGroupAudioQueued(void *, int group, int peer, const int16_t* data,
unsigned samples, uint8_t channels, unsigned sample_rate, void*);

signals:
void groupAudioPlayed(int group, int peer, unsigned short volume);
/// When there are input subscribers, we regularly emit captured audio frames with this signal
Expand Down
6 changes: 4 additions & 2 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,8 @@ int Core::joinGroupchat(int32_t friendnumber, uint8_t type, const uint8_t* frien
{
qDebug() << QString("Trying to join AV groupchat invite sent by friend %1").arg(friendnumber);
return toxav_join_av_groupchat(tox, friendnumber, friend_group_public_key, length,
&Audio::playGroupAudioQueued, const_cast<Core*>(this));
CoreAV::groupCallCallback,
const_cast<Core*>(this));
}
else
{
Expand Down Expand Up @@ -1042,7 +1043,8 @@ int Core::createGroup(uint8_t type)
}
else if (type == TOX_GROUPCHAT_TYPE_AV)
{
int group = toxav_add_av_groupchat(tox, &Audio::playGroupAudioQueued, this);
int group = toxav_add_av_groupchat(tox, CoreAV::groupCallCallback,
this);
emit emptyGroupCreated(group);
return group;
}
Expand Down
43 changes: 43 additions & 0 deletions src/core/coreav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,49 @@ void CoreAV::volMuteToggle(uint32_t callId)
calls[callId].muteVol = !calls[callId].muteVol;
}

/**
@brief Called from Tox API when group call receives audio data.
@param[in] tox the Tox object
@param[in] group the group number
@param[in] peer the peer number
@param[in] data the audio data to playback
@param[in] samples the audio samples
@param[in] channels the audio channels
@param[in] sample_rate the audio sample rate
@param[in] core the qTox Core class
*/
void CoreAV::groupCallCallback(void* tox, int group, int peer,
const int16_t* data, unsigned samples,
uint8_t channels, unsigned sample_rate,
void* core)
{
Q_UNUSED(tox);

Core* c = static_cast<Core*>(core);
CoreAV* cav = c->getAv();

if (!cav->groupCalls.contains(group)) {
qWarning() << "Audio for invalid group id" << group
<< "will not be played back.";
return;
}

ToxGroupCall& call = cav->groupCalls[group];

emit c->groupPeerAudioPlaying(group, peer);

if (call.muteVol)
return;

Audio& audio = Audio::getInstance();
if (!call.alSource)
audio.subscribeOutput(call.alSource);

audio.playAudioBuffer(call.alSource, data, samples, channels,
sample_rate);
}

VideoSource *CoreAV::getVideoSourceFromCall(int friendNum)
{
if (!calls.contains(friendNum))
Expand Down
5 changes: 5 additions & 0 deletions src/core/coreav.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class CoreAV : public QObject
void micMuteToggle(uint32_t friendNum);
void volMuteToggle(uint32_t friendNum);

static void groupCallCallback(void* tox, int group, int peer,
const int16_t* data, unsigned samples,
uint8_t channels, unsigned sample_rate,
void* core);

public slots:
bool startCall(uint32_t friendNum, bool video=false);
bool answerCall(uint32_t friendNum);
Expand Down

0 comments on commit 356543c

Please sign in to comment.