From 46d57c6864fccf8124232efefe7cc4e884cd3509 Mon Sep 17 00:00:00 2001 From: Mick Sayson Date: Tue, 11 Feb 2020 20:45:56 -0800 Subject: [PATCH] feat(groups): Allow being in group call if only member In other applications chatrooms allow you to idle in a call and have people hop in and out as desired. If a user is the only one presently online in a group but knows someone will be joining shortly they should be able to join the call ahead of time. --- src/core/coreav.cpp | 8 ++++---- src/core/coreav.h | 2 +- src/core/toxcall.cpp | 15 +++++++++++---- src/core/toxcall.h | 5 +++-- src/widget/form/groupchatform.cpp | 25 +++++++++++++------------ src/widget/form/groupchatform.h | 1 + 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index 9ed897231..c84d7fca0 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -535,17 +535,17 @@ VideoSource* CoreAV::getVideoSourceFromCall(int friendNum) const * @note Call from the GUI thread. * @param groupId Id of group to join */ -void CoreAV::joinGroupCall(int groupId) +void CoreAV::joinGroupCall(const Group& group) { QWriteLocker locker{&callsLock}; - qDebug() << QString("Joining group call %1").arg(groupId); + qDebug() << QString("Joining group call %1").arg(group.getId()); // Audio backend must be set before starting a call assert(audio != nullptr); - ToxGroupCallPtr groupcall = ToxGroupCallPtr(new ToxGroupCall{groupId, *this, *audio}); + ToxGroupCallPtr groupcall = ToxGroupCallPtr(new ToxGroupCall{group, *this, *audio}); assert(groupcall != nullptr); - auto ret = groupCalls.emplace(groupId, std::move(groupcall)); + auto ret = groupCalls.emplace(group.getId(), std::move(groupcall)); if (ret.second == false) { qWarning() << "This group call already exists, not joining!"; return; diff --git a/src/core/coreav.h b/src/core/coreav.h index 73378ce72..3b312e47d 100644 --- a/src/core/coreav.h +++ b/src/core/coreav.h @@ -68,7 +68,7 @@ public: VideoSource* getVideoSourceFromCall(int callNumber) const; void sendNoVideo(); - void joinGroupCall(int groupNum); + void joinGroupCall(const Group& group); void leaveGroupCall(int groupNum); void muteCallInput(const Group* g, bool mute); void muteCallOutput(const Group* g, bool mute); diff --git a/src/core/toxcall.cpp b/src/core/toxcall.cpp index 0e87506ca..b5ffdab59 100644 --- a/src/core/toxcall.cpp +++ b/src/core/toxcall.cpp @@ -23,6 +23,7 @@ #include "src/persistence/settings.h" #include "src/video/camerasource.h" #include "src/video/corevideosource.h" +#include "src/model/group.h" #include #include @@ -205,15 +206,18 @@ void ToxFriendCall::playAudioBuffer(const int16_t* data, int samples, unsigned c } } -ToxGroupCall::ToxGroupCall(int GroupNum, CoreAV& av, IAudioControl& audio) +ToxGroupCall::ToxGroupCall(const Group& group, CoreAV& av, IAudioControl& audio) : ToxCall(false, av, audio) - , groupId{GroupNum} + , group{group} { // register audio audioInConn = QObject::connect(audioSource.get(), &IAudioSource::frameAvailable, [this](const int16_t* pcm, size_t samples, uint8_t chans, uint32_t rate) { - this->av->sendGroupCallAudio(this->groupId, pcm, samples, chans, rate); + if (this->group.getPeersCount() <= 1) + return; + + this->av->sendGroupCallAudio(this->group.getId(), pcm, samples, chans, rate); }); if (!audioInConn) { @@ -237,7 +241,10 @@ void ToxGroupCall::onAudioSourceInvalidated() audioInConn = QObject::connect(audioSource.get(), &IAudioSource::frameAvailable, [this](const int16_t* pcm, size_t samples, uint8_t chans, uint32_t rate) { - this->av->sendGroupCallAudio(this->groupId, pcm, samples, chans, rate); + if (this->group.getPeersCount() <= 1) + return; + + this->av->sendGroupCallAudio(this->group.getId(), pcm, samples, chans, rate); }); audioSource = std::move(newSrc); diff --git a/src/core/toxcall.h b/src/core/toxcall.h index 9d466c2d8..9af93ae59 100644 --- a/src/core/toxcall.h +++ b/src/core/toxcall.h @@ -37,6 +37,7 @@ class QTimer; class AudioFilterer; class CoreVideoSource; class CoreAV; +class Group; class ToxCall : public QObject { @@ -117,7 +118,7 @@ class ToxGroupCall : public ToxCall { public: ToxGroupCall() = delete; - ToxGroupCall(int GroupNum, CoreAV& av, IAudioControl& audio); + ToxGroupCall(const Group& group, CoreAV& av, IAudioControl& audio); ToxGroupCall(ToxGroupCall&& other) = delete; ~ToxGroupCall(); @@ -134,7 +135,7 @@ private: std::map> peers; std::map sinkInvalid; - int groupId; + const Group& group; void onAudioSourceInvalidated(); void onAudioSinkInvalidated(ToxPk peerId); diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index c525fb295..7b323d057 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -325,18 +325,14 @@ void GroupChatForm::onVolMuteToggle() void GroupChatForm::onCallClicked() { CoreAV* av = Core::getInstance()->getAv(); + if (!inCall) { - av->joinGroupCall(group->getId()); - audioInputFlag = true; - audioOutputFlag = true; - inCall = true; + joinGroupCall(); } else { leaveGroupCall(); } - const int peersCount = group->getPeersCount(); - const bool online = peersCount > 1; - headWidget->updateCallButtons(online, inCall); + headWidget->updateCallButtons(true, inCall); const bool inMute = av->isGroupCallInputMuted(group); headWidget->updateMuteMicButton(inCall, inMute); @@ -373,11 +369,7 @@ void GroupChatForm::keyReleaseEvent(QKeyEvent* ev) void GroupChatForm::updateUserCount(int numPeers) { nusersLabel->setText(tr("%n user(s) in chat", "Number of users in chat", numPeers)); - const bool online = numPeers > 1; - headWidget->updateCallButtons(online, inCall); - if (inCall && (!online || !group->isAvGroupchat())) { - leaveGroupCall(); - } + headWidget->updateCallButtons(true, inCall); } void GroupChatForm::retranslateUi() @@ -442,6 +434,15 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos) } } +void GroupChatForm::joinGroupCall() +{ + CoreAV* av = Core::getInstance()->getAv(); + av->joinGroupCall(*group); + audioInputFlag = true; + audioOutputFlag = true; + inCall = true; +} + void GroupChatForm::leaveGroupCall() { CoreAV* av = Core::getInstance()->getAv(); diff --git a/src/widget/form/groupchatform.h b/src/widget/form/groupchatform.h index ccb1bdeac..6329979b2 100644 --- a/src/widget/form/groupchatform.h +++ b/src/widget/form/groupchatform.h @@ -67,6 +67,7 @@ private: void retranslateUi(); void updateUserCount(int numPeers); void updateUserNames(); + void joinGroupCall(); void leaveGroupCall(); private: