mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(audio): add (repair) support for group audio calls
This commit is contained in:
parent
e5c7b3a4f6
commit
356543ca3b
|
@ -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);
|
||||
|
|
|
@ -86,9 +86,6 @@ public:
|
|||
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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -74,6 +74,11 @@ public:
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user