From 1471e9b8e2c4fa6aa6bb4315032ebcf3962df01b Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 11 May 2021 21:36:05 +0400 Subject: [PATCH] Destroy group call instances async. --- .../calls/group/calls_group_call.cpp | 34 +++++++++++-------- .../calls/group/calls_group_call.h | 2 ++ .../calls/group/calls_group_large_video.cpp | 3 ++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index 1eaad5e983..6ad83a6b4f 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -446,8 +446,8 @@ GroupCall::GroupCall( } GroupCall::~GroupCall() { - destroyController(); destroyScreencast(); + destroyController(); } bool GroupCall::isSharingScreen() const { @@ -732,8 +732,8 @@ void GroupCall::setState(State state) { || state == State::Failed) { // Destroy controller before destroying Call Panel, // so that the panel hide animation is smooth. - destroyController(); destroyScreencast(); + destroyController(); } switch (state) { case State::HangingUp: @@ -1005,7 +1005,7 @@ void GroupCall::rejoin(not_null as) { setJoinAs(as); - const auto weak = base::make_weak(this); + const auto weak = base::make_weak(&_instanceGuard); _instance->emitJoinPayload([=](tgcalls::GroupJoinPayload payload) { crl::on_main(weak, [=, payload = std::move(payload)]{ const auto ssrc = payload.audioSsrc; @@ -1080,7 +1080,7 @@ void GroupCall::rejoinPresentation() { setScreenInstanceMode(InstanceMode::None); 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) { crl::on_main(weak, [=, payload = std::move(payload)]{ if (!_screenInstance) { @@ -1770,7 +1770,7 @@ void GroupCall::ensureControllerCreated() { } 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(); _videoCall = true; tgcalls::GroupInstanceDescriptor descriptor = { @@ -1806,12 +1806,12 @@ void GroupCall::ensureControllerCreated() { setIncomingVideoEndpoints(endpoints); }); }, - .requestBroadcastPart = [=]( + .requestBroadcastPart = [=, call = base::make_weak(this)]( int64_t time, int64_t period, std::function done) { auto result = std::make_shared( - weak, + call, time, period, std::move(done)); @@ -1821,12 +1821,12 @@ void GroupCall::ensureControllerCreated() { return result; }, .videoContentType = tgcalls::VideoContentType::Generic, - .requestMediaChannelDescriptions = [=]( + .requestMediaChannelDescriptions = [=, call = base::make_weak(this)]( const std::vector &ssrcs, std::function &&)> done) { auto result = std::make_shared( - weak, + call, ssrcs, std::move(done)); crl::on_main(weak, [=]() mutable { @@ -1886,7 +1886,7 @@ void GroupCall::ensureScreencastCreated() { } //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::GroupInstanceDescriptor descriptor = { .threads = tgcalls::StaticThreads::getThreads(), @@ -2721,16 +2721,22 @@ MTPInputGroupCall GroupCall::inputCall() const { void GroupCall::destroyController() { if (_instance) { DEBUG_LOG(("Call Info: Destroying call controller..")); - _instance.reset(); - DEBUG_LOG(("Call Info: Call controller destroyed.")); + invalidate_weak_ptrs(&_instanceGuard); + crl::async([instance = base::take(_instance)]() mutable { + instance = nullptr; + DEBUG_LOG(("Call Info: Call controller destroyed.")); + }); } } void GroupCall::destroyScreencast() { if (_screenInstance) { DEBUG_LOG(("Call Info: Destroying call screen controller..")); - _screenInstance.reset(); - DEBUG_LOG(("Call Info: Call screen controller destroyed.")); + invalidate_weak_ptrs(&_screenInstanceGuard); + crl::async([instance = base::take(_screenInstance)]() mutable { + instance = nullptr; + DEBUG_LOG(("Call Info: Call screen controller destroyed.")); + }); } } diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index 49feff1604..f78e170988 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -520,6 +520,7 @@ private: bool _instanceTransitioning = false; InstanceMode _instanceMode = InstanceMode::None; std::unique_ptr _instance; + base::has_weak_ptr _instanceGuard; std::shared_ptr _cameraCapture; std::unique_ptr _cameraOutgoing; @@ -527,6 +528,7 @@ private: = InstanceState::Disconnected; InstanceMode _screenInstanceMode = InstanceMode::None; std::unique_ptr _screenInstance; + base::has_weak_ptr _screenInstanceGuard; std::shared_ptr _screenCapture; std::unique_ptr _screenOutgoing; QString _screenDeviceId; diff --git a/Telegram/SourceFiles/calls/group/calls_group_large_video.cpp b/Telegram/SourceFiles/calls/group/calls_group_large_video.cpp index 92ee09a504..ffb2ebdf1a 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_large_video.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_large_video.cpp @@ -116,6 +116,9 @@ void LargeVideo::setup( ) | rpl::map([=](bool shown, LargeVideoTrack track) { if (!shown) { _controlsAnimation.stop(); + if (!_topControls) { + _controlsShown = _mouseInside = false; + } _controlsShownRatio = _controlsShown.current() ? 1. : 0.; } return shown ? track : LargeVideoTrack();