mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge branch 'av_groupchats'
This commit is contained in:
commit
45c96c6aea
29
src/core.cpp
29
src/core.cpp
|
@ -484,11 +484,12 @@ void Core::onGroupInvite(Tox*, int friendnumber, uint8_t type, const uint8_t *da
|
|||
if (type == TOX_GROUPCHAT_TYPE_TEXT)
|
||||
{
|
||||
qDebug() << QString("Core: Text group invite by %1").arg(friendnumber);
|
||||
emit static_cast<Core*>(core)->groupInviteReceived(friendnumber, data,length);
|
||||
emit static_cast<Core*>(core)->groupInviteReceived(friendnumber,type,data,length);
|
||||
}
|
||||
else if (type == TOX_GROUPCHAT_TYPE_AV)
|
||||
{
|
||||
qDebug() << QString("Core: AV group invite by %1, not implemented").arg(friendnumber);
|
||||
qDebug() << QString("Core: AV group invite by %1").arg(friendnumber);
|
||||
emit static_cast<Core*>(core)->groupInviteReceived(friendnumber,type,data,length);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1480,10 +1481,23 @@ QList<QString> Core::getGroupPeerNames(int groupId) const
|
|||
return names;
|
||||
}
|
||||
|
||||
int Core::joinGroupchat(int32_t friendnumber, const uint8_t* friend_group_public_key,uint16_t length) const
|
||||
int Core::joinGroupchat(int32_t friendnumber, uint8_t type, const uint8_t* friend_group_public_key,uint16_t length) const
|
||||
{
|
||||
qDebug() << QString("Trying to join groupchat invite by friend %1").arg(friendnumber);
|
||||
if (type == TOX_GROUPCHAT_TYPE_TEXT)
|
||||
{
|
||||
qDebug() << QString("Trying to join text groupchat invite sent by friend %1").arg(friendnumber);
|
||||
return tox_join_groupchat(tox, friendnumber, friend_group_public_key,length);
|
||||
}
|
||||
else if (type == TOX_GROUPCHAT_TYPE_AV)
|
||||
{
|
||||
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, playGroupAudio, const_cast<Core*>(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Core::joinGroupchat: Unknown groupchat type "<<type;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void Core::quitGroupChat(int groupId) const
|
||||
|
@ -1614,9 +1628,14 @@ void Core::groupInviteFriend(int friendId, int groupId)
|
|||
tox_invite_friend(tox, friendId, groupId);
|
||||
}
|
||||
|
||||
void Core::createGroup()
|
||||
void Core::createGroup(uint8_t type)
|
||||
{
|
||||
if (type == TOX_GROUPCHAT_TYPE_TEXT)
|
||||
emit emptyGroupCreated(tox_add_groupchat(tox));
|
||||
else if (type == TOX_GROUPCHAT_TYPE_AV)
|
||||
emit emptyGroupCreated(toxav_add_av_groupchat(tox, playGroupAudio, this));
|
||||
else
|
||||
qWarning() << "Core::createGroup: Unknown type "<<type;
|
||||
}
|
||||
|
||||
bool Core::hasFriendWithAddress(const QString &addr) const
|
||||
|
|
13
src/core.h
13
src/core.h
|
@ -21,6 +21,8 @@
|
|||
#include <QObject>
|
||||
#include <QMutex>
|
||||
|
||||
#include <tox/tox.h>
|
||||
|
||||
#include "corestructs.h"
|
||||
#include "coreav.h"
|
||||
#include "coredefines.h"
|
||||
|
@ -56,7 +58,7 @@ public:
|
|||
QString getFriendUsername(int friendNumber) const; ///< Get the username of a friend
|
||||
bool hasFriendWithAddress(const QString &addr) const; ///< Check if we have a friend by address
|
||||
bool hasFriendWithPublicKey(const QString &pubkey) const; ///< Check if we have a friend by public key
|
||||
int joinGroupchat(int32_t friendNumber, const uint8_t* pubkey,uint16_t length) const; ///< Accept a groupchat invite
|
||||
int joinGroupchat(int32_t friendNumber, uint8_t type, const uint8_t* pubkey,uint16_t length) const; ///< Accept a groupchat invite
|
||||
void quitGroupChat(int groupId) const; ///< Quit a groupchat
|
||||
|
||||
void saveConfiguration();
|
||||
|
@ -83,7 +85,7 @@ public slots:
|
|||
void acceptFriendRequest(const QString& userId);
|
||||
void requestFriendship(const QString& friendAddress, const QString& message);
|
||||
void groupInviteFriend(int friendId, int groupId);
|
||||
void createGroup();
|
||||
void createGroup(uint8_t type = TOX_GROUPCHAT_TYPE_AV);
|
||||
|
||||
void removeFriend(int friendId);
|
||||
void removeGroup(int groupId);
|
||||
|
@ -143,7 +145,7 @@ signals:
|
|||
void friendLastSeenChanged(int friendId, const QDateTime& dateTime);
|
||||
|
||||
void emptyGroupCreated(int groupnumber);
|
||||
void groupInviteReceived(int friendnumber, const uint8_t *group_public_key,uint16_t length);
|
||||
void groupInviteReceived(int friendnumber, uint8_t type, const uint8_t *group_public_key,uint16_t length);
|
||||
void groupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction);
|
||||
void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
|
||||
|
||||
|
@ -231,11 +233,14 @@ private:
|
|||
static void onAvPeerTimeout(void* toxav, int32_t call_index, void* core);
|
||||
static void onAvMediaChange(void *toxav, int32_t call_index, void* core);
|
||||
|
||||
static void playGroupAudio(Tox* tox, int groupnumber, int friendgroupnumber, const int16_t* out_audio,
|
||||
unsigned out_audio_samples, uint8_t decoder_channels, unsigned audio_sample_rate, void* userdata);
|
||||
|
||||
static void prepareCall(int friendId, int callId, ToxAv *toxav, bool videoEnabled);
|
||||
static void cleanupCall(int callId);
|
||||
static void playCallAudio(ToxAv *toxav, int32_t callId, int16_t *data, int samples, void *user_data); // Callback
|
||||
static void sendCallAudio(int callId, ToxAv* toxav);
|
||||
static void playAudioBuffer(int callId, int16_t *data, int samples, unsigned channels, int sampleRate);
|
||||
static void playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate);
|
||||
static void playCallVideo(ToxAv* toxav, int32_t callId, vpx_image_t* img, void *user_data);
|
||||
void sendCallVideo(int callId);
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ void Core::playCallAudio(ToxAv* toxav, int32_t callId, int16_t *data, int sample
|
|||
|
||||
ToxAvCSettings dest;
|
||||
if(toxav_get_peer_csettings(toxav, callId, 0, &dest) == 0)
|
||||
playAudioBuffer(callId, data, samples, dest.audio_channels, dest.audio_sample_rate);
|
||||
playAudioBuffer(calls[callId].alSource, data, samples, dest.audio_channels, dest.audio_sample_rate);
|
||||
}
|
||||
|
||||
void Core::sendCallAudio(int callId, ToxAv* toxav)
|
||||
|
@ -538,7 +538,7 @@ void Core::onAvStart(void* _toxav, int32_t call_index, void* core)
|
|||
}
|
||||
|
||||
// This function's logic was shamelessly stolen from uTox
|
||||
void Core::playAudioBuffer(int callId, int16_t *data, int samples, unsigned channels, int sampleRate)
|
||||
void Core::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate)
|
||||
{
|
||||
if(!channels || channels > 2)
|
||||
{
|
||||
|
@ -548,14 +548,14 @@ void Core::playAudioBuffer(int callId, int16_t *data, int samples, unsigned chan
|
|||
|
||||
ALuint bufid;
|
||||
ALint processed, queued;
|
||||
alGetSourcei(calls[callId].alSource, AL_BUFFERS_PROCESSED, &processed);
|
||||
alGetSourcei(calls[callId].alSource, AL_BUFFERS_QUEUED, &queued);
|
||||
alSourcei(calls[callId].alSource, AL_LOOPING, AL_FALSE);
|
||||
alGetSourcei(alSource, AL_BUFFERS_PROCESSED, &processed);
|
||||
alGetSourcei(alSource, AL_BUFFERS_QUEUED, &queued);
|
||||
alSourcei(alSource, AL_LOOPING, AL_FALSE);
|
||||
|
||||
if(processed)
|
||||
{
|
||||
ALuint bufids[processed];
|
||||
alSourceUnqueueBuffers(calls[callId].alSource, processed, bufids);
|
||||
alSourceUnqueueBuffers(alSource, processed, bufids);
|
||||
alDeleteBuffers(processed - 1, bufids + 1);
|
||||
bufid = bufids[0];
|
||||
}
|
||||
|
@ -571,14 +571,14 @@ void Core::playAudioBuffer(int callId, int16_t *data, int samples, unsigned chan
|
|||
|
||||
alBufferData(bufid, (channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, data,
|
||||
samples * 2 * channels, sampleRate);
|
||||
alSourceQueueBuffers(calls[callId].alSource, 1, &bufid);
|
||||
alSourceQueueBuffers(alSource, 1, &bufid);
|
||||
|
||||
ALint state;
|
||||
alGetSourcei(calls[callId].alSource, AL_SOURCE_STATE, &state);
|
||||
alGetSourcei(alSource, AL_SOURCE_STATE, &state);
|
||||
if(state != AL_PLAYING)
|
||||
{
|
||||
alSourcePlay(calls[callId].alSource);
|
||||
qDebug() << "Core: Starting audio source of call " << callId;
|
||||
alSourcePlay(alSource);
|
||||
qDebug() << "Core: Starting audio source " << (int)alSource;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -587,3 +587,10 @@ VideoSource *Core::getVideoSourceFromCall(int callNumber)
|
|||
return &calls[callNumber].videoSource;
|
||||
}
|
||||
|
||||
void Core::playGroupAudio(Tox* tox, int groupnumber, int friendgroupnumber, const int16_t* out_audio,
|
||||
unsigned out_audio_samples, uint8_t decoder_channels, unsigned audio_sample_rate, void* userdata)
|
||||
{
|
||||
/// TODO: FIXME: Don't play groupchat audio on the main source!
|
||||
/// We'll need some sort of call[] array but for groupchats, when that's done use this source
|
||||
playAudioBuffer(alMainSource, out_audio, out_audio_samples, decoder_channels, audio_sample_rate);
|
||||
}
|
||||
|
|
|
@ -870,12 +870,20 @@ void Widget::copyFriendIdToClipboard(int friendId)
|
|||
}
|
||||
}
|
||||
|
||||
void Widget::onGroupInviteReceived(int32_t friendId, const uint8_t* publicKey,uint16_t length)
|
||||
void Widget::onGroupInviteReceived(int32_t friendId, uint8_t type, const uint8_t* publicKey,uint16_t length)
|
||||
{
|
||||
int groupId = core->joinGroupchat(friendId, publicKey,length);
|
||||
if (groupId == -1)
|
||||
if (type == TOX_GROUPCHAT_TYPE_TEXT || type == TOX_GROUPCHAT_TYPE_AV)
|
||||
{
|
||||
qWarning() << "Widget::onGroupInviteReceived: Unable to accept invitation";
|
||||
int groupId = core->joinGroupchat(friendId, type, publicKey,length);
|
||||
if (groupId < 0)
|
||||
{
|
||||
qWarning() << "Widget::onGroupInviteReceived: Unable to accept group invite";
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Widget::onGroupInviteReceived: Unknown groupchat type:"<<type;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ private slots:
|
|||
void onFriendRequestReceived(const QString& userId, const QString& message);
|
||||
void onReceiptRecieved(int friendId, int receipt);
|
||||
void onEmptyGroupCreated(int groupId);
|
||||
void onGroupInviteReceived(int32_t friendId, const uint8_t *publicKey,uint16_t length);
|
||||
void onGroupInviteReceived(int32_t friendId, uint8_t type, const uint8_t *publicKey,uint16_t length);
|
||||
void onGroupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction);
|
||||
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
|
||||
void removeFriend(int friendId);
|
||||
|
|
Loading…
Reference in New Issue
Block a user