Update tgcalls.

This commit is contained in:
John Preston 2021-03-08 11:57:00 +04:00
parent cfd16c6f67
commit f41abe0a28
5 changed files with 140 additions and 27 deletions

View File

@ -29,16 +29,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "webrtc/webrtc_media_devices.h"
#include "webrtc/webrtc_create_adm.h"
#include <tgcalls/group/GroupInstanceImpl.h>
#include <tgcalls/group/GroupInstanceCustomImpl.h>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
namespace tgcalls {
class GroupInstanceImpl;
} // namespace tgcalls
namespace Calls {
namespace {
@ -304,6 +300,8 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) {
}
}, _lifetime);
addParticipantsToInstance();
SubscribeToMigration(_peer, _lifetime, [=](not_null<ChannelData*> group) {
_peer = group;
});
@ -636,7 +634,12 @@ void GroupCall::handleUpdate(const MTPGroupCall &call) {
.relPort = readString(object, "relPort"),
});
}
_instance->setJoinResponsePayload(payload);
_instance->setConnectionMode(
tgcalls::GroupConnectionMode::GroupConnectionModeRtc);
_instance->setJoinResponsePayload(payload, {});
_instancePayloadsDone = true;
addParticipantsToInstance();
});
}
}, [&](const MTPDgroupCallDiscarded &data) {
@ -647,6 +650,45 @@ void GroupCall::handleUpdate(const MTPGroupCall &call) {
});
}
void GroupCall::addParticipantsToInstance() {
const auto real = _peer->groupCall();
if (!real || (real->id() != _id) || !_instancePayloadsDone) {
return;
}
for (const auto &participant : real->participants()) {
prepareParticipantForAdding(participant);
}
addPreparedParticipants();
}
void GroupCall::prepareParticipantForAdding(
const Data::GroupCallParticipant &participant) {
_preparedParticipants.push_back(tgcalls::GroupParticipantDescription());
auto &added = _preparedParticipants.back();
added.audioSsrc = participant.ssrc;
_unresolvedSsrcs.remove(added.audioSsrc);
}
void GroupCall::addPreparedParticipants() {
_addPreparedParticipantsScheduled = false;
if (!_preparedParticipants.empty()) {
_instance->addParticipants(base::take(_preparedParticipants));
}
if (const auto real = _peer->groupCall(); real && real->id() == _id) {
if (!_unresolvedSsrcs.empty()) {
real->resolveParticipants(base::take(_unresolvedSsrcs));
}
}
}
void GroupCall::addPreparedParticipantsDelayed() {
if (_addPreparedParticipantsScheduled) {
return;
}
_addPreparedParticipantsScheduled = true;
crl::on_main(this, [=] { addPreparedParticipants(); });
}
void GroupCall::handleUpdate(const MTPDupdateGroupCallParticipants &data) {
const auto state = _state.current();
if (state != State::Joined && state != State::Connecting) {
@ -751,6 +793,12 @@ void GroupCall::createAndStartController() {
.initialOutputDeviceId = _audioOutputId.toStdString(),
.createAudioDeviceModule = Webrtc::AudioDeviceModuleCreator(
settings.callAudioBackend()),
.participantDescriptionsRequired = [=](
const std::vector<uint32_t> &ssrcs) {
crl::on_main(weak, [=] {
requestParticipantsInformation(ssrcs);
});
},
};
if (Logs::DebugEnabled()) {
auto callLogFolder = cWorkingDir() + qsl("DebugLogs");
@ -768,7 +816,8 @@ void GroupCall::createAndStartController() {
}
LOG(("Call Info: Creating group instance"));
_instance = std::make_unique<tgcalls::GroupInstanceImpl>(
_instancePayloadsDone = false;
_instance = std::make_unique<tgcalls::GroupInstanceCustomImpl>(
std::move(descriptor));
updateInstanceMuteState();
@ -777,6 +826,34 @@ void GroupCall::createAndStartController() {
//raw->setAudioOutputDuckingEnabled(settings.callAudioDuckingEnabled());
}
void GroupCall::requestParticipantsInformation(
const std::vector<uint32_t> &ssrcs) {
const auto real = _peer->groupCall();
if (!real || real->id() != _id || !_instancePayloadsDone) {
for (const auto ssrc : ssrcs) {
_unresolvedSsrcs.emplace(ssrc);
}
return;
}
const auto &existing = real->participants();
for (const auto ssrc : ssrcs) {
const auto participantPeer = real->participantPeerBySsrc(ssrc);
if (!participantPeer) {
_unresolvedSsrcs.emplace(ssrc);
continue;
}
const auto i = ranges::find(
existing,
not_null{ participantPeer },
&Data::GroupCall::Participant::peer);
Assert(i != end(existing));
prepareParticipantForAdding(*i);
}
addPreparedParticipants();
}
void GroupCall::updateInstanceMuteState() {
Expects(_instance != nullptr);

View File

@ -16,8 +16,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class History;
namespace tgcalls {
class GroupInstanceImpl;
class GroupInstanceCustomImpl;
struct GroupLevelsUpdate;
struct GroupParticipantDescription;
} // namespace tgcalls
namespace base {
@ -31,6 +32,7 @@ class MediaDevices;
namespace Data {
struct LastSpokeTimes;
struct GroupCallParticipant;
} // namespace Data
namespace Calls {
@ -207,6 +209,13 @@ private:
void stopConnectingSound();
void playConnectingSoundOnce();
void requestParticipantsInformation(const std::vector<uint32_t> &ssrcs);
void addParticipantsToInstance();
void prepareParticipantForAdding(
const Data::GroupCallParticipant &participant);
void addPreparedParticipants();
void addPreparedParticipantsDelayed();
void editParticipant(
not_null<PeerData*> participantPeer,
bool mute,
@ -224,6 +233,10 @@ private:
MTP::Sender _api;
rpl::variable<State> _state = State::Creating;
bool _instanceConnected = false;
bool _instancePayloadsDone = false;
base::flat_set<uint32> _unresolvedSsrcs;
std::vector<tgcalls::GroupParticipantDescription> _preparedParticipants;
bool _addPreparedParticipantsScheduled = false;
not_null<PeerData*> _joinAs;
std::vector<not_null<PeerData*>> _possibleJoinAs;
@ -239,7 +252,7 @@ private:
mtpRequestId _createRequestId = 0;
mtpRequestId _updateMuteRequestId = 0;
std::unique_ptr<tgcalls::GroupInstanceImpl> _instance;
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _instance;
rpl::event_stream<LevelUpdate> _levelUpdates;
base::flat_map<uint32, Data::LastSpokeTimes> _lastSpoke;
rpl::event_stream<Group::RejoinEvent> _rejoinEvents;

View File

@ -378,6 +378,16 @@ void GroupCall::applyLastSpoke(
}
}
void GroupCall::resolveParticipants(const base::flat_set<uint32> &ssrcs) {
if (ssrcs.empty()) {
return;
}
for (const auto ssrc : ssrcs) {
_unknownSpokenSsrcs.emplace(ssrc, LastSpokeTimes());
}
requestUnknownParticipants();
}
void GroupCall::applyActiveUpdate(
PeerId participantPeerId,
LastSpokeTimes when,
@ -531,7 +541,9 @@ void GroupCall::requestUnknownParticipants() {
_unknownParticipantPeersRequestId = 0;
const auto now = crl::now();
for (const auto [ssrc, when] : ssrcs) {
if (when.voice || when.anything) {
applyLastSpoke(ssrc, when, now);
}
_unknownSpokenSsrcs.remove(ssrc);
}
for (const auto [id, when] : participantPeerIds) {

View File

@ -20,6 +20,21 @@ struct LastSpokeTimes {
crl::time voice = 0;
};
struct GroupCallParticipant {
not_null<PeerData*> peer;
TimeId date = 0;
TimeId lastActive = 0;
uint32 ssrc = 0;
int volume = 0;
bool applyVolumeFromMin = true;
bool sounding = false;
bool speaking = false;
bool muted = false;
bool mutedByMe = false;
bool canSelfUnmute = false;
bool onlyMinLoaded = false;
};
class GroupCall final {
public:
GroupCall(not_null<PeerData*> peer, uint64 id, uint64 accessHash);
@ -40,20 +55,7 @@ public:
void setPeer(not_null<PeerData*> peer);
struct Participant {
not_null<PeerData*> peer;
TimeId date = 0;
TimeId lastActive = 0;
uint32 ssrc = 0;
int volume = 0;
bool applyVolumeFromMin = true;
bool sounding = false;
bool speaking = false;
bool muted = false;
bool mutedByMe = false;
bool canSelfUnmute = false;
bool onlyMinLoaded = false;
};
using Participant = GroupCallParticipant;
struct ParticipantUpdate {
std::optional<Participant> was;
std::optional<Participant> now;
@ -65,6 +67,7 @@ public:
-> const std::vector<Participant> &;
void requestParticipants();
[[nodiscard]] bool participantsLoaded() const;
[[nodiscard]] PeerData *participantPeerBySsrc(uint32 ssrc) const;
[[nodiscard]] rpl::producer<> participantsSliceAdded();
[[nodiscard]] rpl::producer<ParticipantUpdate> participantUpdated() const;
@ -79,6 +82,8 @@ public:
LastSpokeTimes when,
PeerData *participantPeerLoaded);
void resolveParticipants(const base::flat_set<uint32> &ssrcs);
[[nodiscard]] int fullCount() const;
[[nodiscard]] rpl::producer<int> fullCountValue() const;
@ -105,7 +110,6 @@ private:
void requestUnknownParticipants();
void changePeerEmptyCallFlag();
void checkFinishSpeakingByActive();
[[nodiscard]] PeerData *participantPeerBySsrc(uint32 ssrc) const;
const uint64 _id = 0;
const uint64 _accessHash = 0;

View File

@ -47,6 +47,8 @@ PRIVATE
Message.h
NetworkManager.cpp
NetworkManager.h
StaticThreads.cpp
StaticThreads.h
ThreadLocalObject.h
VideoCaptureInterface.cpp
VideoCaptureInterface.h
@ -54,8 +56,12 @@ PRIVATE
VideoCaptureInterfaceImpl.h
VideoCapturerInterface.h
group/GroupInstanceImpl.cpp
group/GroupInstanceImpl.h
group/GroupInstanceCustomImpl.cpp
group/GroupInstanceCustomImpl.h
group/GroupNetworkManager.cpp
group/GroupNetworkManager.h
group/StreamingPart.cpp
group/StreamingPart.h
platform/PlatformInterface.h
@ -119,6 +125,7 @@ PRIVATE
target_link_libraries(lib_tgcalls
PRIVATE
desktop-app::external_webrtc
desktop-app::external_opus
)
target_compile_definitions(lib_tgcalls