Destroy group call instances async.

This commit is contained in:
John Preston 2021-05-11 21:36:05 +04:00
parent 4c23d51be5
commit 1471e9b8e2
3 changed files with 25 additions and 14 deletions

View File

@ -446,8 +446,8 @@ GroupCall::GroupCall(
} }
GroupCall::~GroupCall() { GroupCall::~GroupCall() {
destroyController();
destroyScreencast(); destroyScreencast();
destroyController();
} }
bool GroupCall::isSharingScreen() const { bool GroupCall::isSharingScreen() const {
@ -732,8 +732,8 @@ void GroupCall::setState(State state) {
|| state == State::Failed) { || state == State::Failed) {
// Destroy controller before destroying Call Panel, // Destroy controller before destroying Call Panel,
// so that the panel hide animation is smooth. // so that the panel hide animation is smooth.
destroyController();
destroyScreencast(); destroyScreencast();
destroyController();
} }
switch (state) { switch (state) {
case State::HangingUp: case State::HangingUp:
@ -1005,7 +1005,7 @@ void GroupCall::rejoin(not_null<PeerData*> as) {
setJoinAs(as); setJoinAs(as);
const auto weak = base::make_weak(this); const auto weak = base::make_weak(&_instanceGuard);
_instance->emitJoinPayload([=](tgcalls::GroupJoinPayload payload) { _instance->emitJoinPayload([=](tgcalls::GroupJoinPayload payload) {
crl::on_main(weak, [=, payload = std::move(payload)]{ crl::on_main(weak, [=, payload = std::move(payload)]{
const auto ssrc = payload.audioSsrc; const auto ssrc = payload.audioSsrc;
@ -1080,7 +1080,7 @@ void GroupCall::rejoinPresentation() {
setScreenInstanceMode(InstanceMode::None); setScreenInstanceMode(InstanceMode::None);
LOG(("Call Info: Requesting join payload.")); LOG(("Call Info: Requesting join payload."));
const auto weak = base::make_weak(this); const auto weak = base::make_weak(&_screenInstanceGuard);
_screenInstance->emitJoinPayload([=](tgcalls::GroupJoinPayload payload) { _screenInstance->emitJoinPayload([=](tgcalls::GroupJoinPayload payload) {
crl::on_main(weak, [=, payload = std::move(payload)]{ crl::on_main(weak, [=, payload = std::move(payload)]{
if (!_screenInstance) { if (!_screenInstance) {
@ -1770,7 +1770,7 @@ void GroupCall::ensureControllerCreated() {
} }
const auto &settings = Core::App().settings(); const auto &settings = Core::App().settings();
const auto weak = base::make_weak(this); const auto weak = base::make_weak(&_instanceGuard);
const auto myLevel = std::make_shared<tgcalls::GroupLevelValue>(); const auto myLevel = std::make_shared<tgcalls::GroupLevelValue>();
_videoCall = true; _videoCall = true;
tgcalls::GroupInstanceDescriptor descriptor = { tgcalls::GroupInstanceDescriptor descriptor = {
@ -1806,12 +1806,12 @@ void GroupCall::ensureControllerCreated() {
setIncomingVideoEndpoints(endpoints); setIncomingVideoEndpoints(endpoints);
}); });
}, },
.requestBroadcastPart = [=]( .requestBroadcastPart = [=, call = base::make_weak(this)](
int64_t time, int64_t time,
int64_t period, int64_t period,
std::function<void(tgcalls::BroadcastPart &&)> done) { std::function<void(tgcalls::BroadcastPart &&)> done) {
auto result = std::make_shared<LoadPartTask>( auto result = std::make_shared<LoadPartTask>(
weak, call,
time, time,
period, period,
std::move(done)); std::move(done));
@ -1821,12 +1821,12 @@ void GroupCall::ensureControllerCreated() {
return result; return result;
}, },
.videoContentType = tgcalls::VideoContentType::Generic, .videoContentType = tgcalls::VideoContentType::Generic,
.requestMediaChannelDescriptions = [=]( .requestMediaChannelDescriptions = [=, call = base::make_weak(this)](
const std::vector<uint32_t> &ssrcs, const std::vector<uint32_t> &ssrcs,
std::function<void( std::function<void(
std::vector<tgcalls::MediaChannelDescription> &&)> done) { std::vector<tgcalls::MediaChannelDescription> &&)> done) {
auto result = std::make_shared<MediaChannelDescriptionsTask>( auto result = std::make_shared<MediaChannelDescriptionsTask>(
weak, call,
ssrcs, ssrcs,
std::move(done)); std::move(done));
crl::on_main(weak, [=]() mutable { crl::on_main(weak, [=]() mutable {
@ -1886,7 +1886,7 @@ void GroupCall::ensureScreencastCreated() {
} }
//const auto &settings = Core::App().settings(); //const auto &settings = Core::App().settings();
const auto weak = base::make_weak(this); const auto weak = base::make_weak(&_screenInstanceGuard);
//const auto myLevel = std::make_shared<tgcalls::GroupLevelValue>(); //const auto myLevel = std::make_shared<tgcalls::GroupLevelValue>();
tgcalls::GroupInstanceDescriptor descriptor = { tgcalls::GroupInstanceDescriptor descriptor = {
.threads = tgcalls::StaticThreads::getThreads(), .threads = tgcalls::StaticThreads::getThreads(),
@ -2721,16 +2721,22 @@ MTPInputGroupCall GroupCall::inputCall() const {
void GroupCall::destroyController() { void GroupCall::destroyController() {
if (_instance) { if (_instance) {
DEBUG_LOG(("Call Info: Destroying call controller..")); DEBUG_LOG(("Call Info: Destroying call controller.."));
_instance.reset(); invalidate_weak_ptrs(&_instanceGuard);
DEBUG_LOG(("Call Info: Call controller destroyed.")); crl::async([instance = base::take(_instance)]() mutable {
instance = nullptr;
DEBUG_LOG(("Call Info: Call controller destroyed."));
});
} }
} }
void GroupCall::destroyScreencast() { void GroupCall::destroyScreencast() {
if (_screenInstance) { if (_screenInstance) {
DEBUG_LOG(("Call Info: Destroying call screen controller..")); DEBUG_LOG(("Call Info: Destroying call screen controller.."));
_screenInstance.reset(); invalidate_weak_ptrs(&_screenInstanceGuard);
DEBUG_LOG(("Call Info: Call screen controller destroyed.")); crl::async([instance = base::take(_screenInstance)]() mutable {
instance = nullptr;
DEBUG_LOG(("Call Info: Call screen controller destroyed."));
});
} }
} }

View File

@ -520,6 +520,7 @@ private:
bool _instanceTransitioning = false; bool _instanceTransitioning = false;
InstanceMode _instanceMode = InstanceMode::None; InstanceMode _instanceMode = InstanceMode::None;
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _instance; std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _instance;
base::has_weak_ptr _instanceGuard;
std::shared_ptr<tgcalls::VideoCaptureInterface> _cameraCapture; std::shared_ptr<tgcalls::VideoCaptureInterface> _cameraCapture;
std::unique_ptr<Webrtc::VideoTrack> _cameraOutgoing; std::unique_ptr<Webrtc::VideoTrack> _cameraOutgoing;
@ -527,6 +528,7 @@ private:
= InstanceState::Disconnected; = InstanceState::Disconnected;
InstanceMode _screenInstanceMode = InstanceMode::None; InstanceMode _screenInstanceMode = InstanceMode::None;
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _screenInstance; std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _screenInstance;
base::has_weak_ptr _screenInstanceGuard;
std::shared_ptr<tgcalls::VideoCaptureInterface> _screenCapture; std::shared_ptr<tgcalls::VideoCaptureInterface> _screenCapture;
std::unique_ptr<Webrtc::VideoTrack> _screenOutgoing; std::unique_ptr<Webrtc::VideoTrack> _screenOutgoing;
QString _screenDeviceId; QString _screenDeviceId;

View File

@ -116,6 +116,9 @@ void LargeVideo::setup(
) | rpl::map([=](bool shown, LargeVideoTrack track) { ) | rpl::map([=](bool shown, LargeVideoTrack track) {
if (!shown) { if (!shown) {
_controlsAnimation.stop(); _controlsAnimation.stop();
if (!_topControls) {
_controlsShown = _mouseInside = false;
}
_controlsShownRatio = _controlsShown.current() ? 1. : 0.; _controlsShownRatio = _controlsShown.current() ? 1. : 0.;
} }
return shown ? track : LargeVideoTrack(); return shown ? track : LargeVideoTrack();