From 29c0956d61dd0d4e621ccedd76e80cc35fc79bc4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 25 Aug 2021 00:54:53 +0300 Subject: [PATCH] Always try to play video in voice chats. --- Telegram/Resources/langs/lang.strings | 2 - .../calls/group/calls_group_call.cpp | 66 ++----- .../calls/group/calls_group_call.h | 8 - .../calls/group/calls_group_members.cpp | 179 +----------------- .../calls/group/calls_group_members.h | 2 - 5 files changed, 23 insertions(+), 234 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 74423bd21..8eb7c8e09 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2103,8 +2103,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_ptt_delay" = "Push to Talk release delay: {delay}"; "lng_group_call_share" = "Share Invite Link"; "lng_group_call_noise_suppression" = "Enable Noise Suppression"; -"lng_group_call_limit#one" = "Video is only available\nfor the first {count} member"; -"lng_group_call_limit#other" = "Video is only available\nfor the first {count} members"; "lng_group_call_over_limit#one" = "The voice chat is over {count} member.\nNew participants only have access to audio stream."; "lng_group_call_over_limit#other" = "The voice chat is over {count} members.\nNew participants only have access to audio stream."; "lng_group_call_video_paused" = "Video is paused"; diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index 7f8ea998c..73a7b0e0a 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -885,9 +885,6 @@ void GroupCall::setState(State state) { if (const auto call = _peer->groupCall(); call && call->id() == _id) { call->setInCall(); } - if (!videoIsWorking()) { - refreshHasNotShownVideo(); - } } if (false @@ -1100,9 +1097,6 @@ void GroupCall::markEndpointActive( bool paused) { if (!endpoint) { return; - } else if (active && !videoIsWorking()) { - refreshHasNotShownVideo(); - return; } const auto i = _activeVideoTracks.find(endpoint); const auto changed = active @@ -2618,22 +2612,6 @@ void GroupCall::updateRequestedVideoChannelsDelayed() { }); } -void GroupCall::refreshHasNotShownVideo() { - if (!_joinState.ssrc || hasNotShownVideo()) { - return; - } - const auto real = lookupReal(); - Assert(real != nullptr); - - const auto hasVideo = [&](const Data::GroupCallParticipant &data) { - return (data.peer != _joinAs) - && (!GetCameraEndpoint(data.videoParams).empty() - || !GetScreenEndpoint(data.videoParams).empty()); - }; - _hasNotShownVideo = _joinState.ssrc - && ranges::any_of(real->participants(), hasVideo); -} - void GroupCall::fillActiveVideoEndpoints() { const auto real = lookupReal(); Assert(real != nullptr); @@ -2641,9 +2619,7 @@ void GroupCall::fillActiveVideoEndpoints() { const auto me = real->participantByPeer(_joinAs); if (me && me->videoJoined) { _videoIsWorking = true; - _hasNotShownVideo = false; } else { - refreshHasNotShownVideo(); _videoIsWorking = false; toggleVideo(false); toggleScreenSharing(std::nullopt); @@ -2671,30 +2647,28 @@ void GroupCall::fillActiveVideoEndpoints() { } }; using Type = VideoEndpointType; - if (_videoIsWorking.current()) { - for (const auto &participant : real->participants()) { - const auto camera = GetCameraEndpoint(participant.videoParams); - if (camera != _cameraEndpoint - && camera != _screenEndpoint - && participant.peer != _joinAs) { - const auto paused = IsCameraPaused(participant.videoParams); - feedOne({ Type::Camera, participant.peer, camera }, paused); - } - const auto screen = GetScreenEndpoint(participant.videoParams); - if (screen != _cameraEndpoint - && screen != _screenEndpoint - && participant.peer != _joinAs) { - const auto paused = IsScreenPaused(participant.videoParams); - feedOne({ Type::Screen, participant.peer, screen }, paused); - } + for (const auto &participant : real->participants()) { + const auto camera = GetCameraEndpoint(participant.videoParams); + if (camera != _cameraEndpoint + && camera != _screenEndpoint + && participant.peer != _joinAs) { + const auto paused = IsCameraPaused(participant.videoParams); + feedOne({ Type::Camera, participant.peer, camera }, paused); + } + const auto screen = GetScreenEndpoint(participant.videoParams); + if (screen != _cameraEndpoint + && screen != _screenEndpoint + && participant.peer != _joinAs) { + const auto paused = IsScreenPaused(participant.videoParams); + feedOne({ Type::Screen, participant.peer, screen }, paused); } - feedOne( - { Type::Camera, _joinAs, cameraSharingEndpoint() }, - isCameraPaused()); - feedOne( - { Type::Screen, _joinAs, screenSharingEndpoint() }, - isScreenPaused()); } + feedOne( + { Type::Camera, _joinAs, cameraSharingEndpoint() }, + isCameraPaused()); + feedOne( + { Type::Screen, _joinAs, screenSharingEndpoint() }, + isScreenPaused()); if (large && !largeFound) { setVideoEndpointLarge({}); } diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index 4e8f59f71..6ef9ad600 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -362,12 +362,6 @@ public: [[nodiscard]] rpl::producer videoIsWorkingValue() const { return _videoIsWorking.value(); } - [[nodiscard]] bool hasNotShownVideo() const { - return _hasNotShownVideo.current(); - } - [[nodiscard]] rpl::producer hasNotShownVideoValue() const { - return _hasNotShownVideo.value(); - } void setCurrentAudioDevice(bool input, const QString &deviceId); [[nodiscard]] bool isSharingScreen() const; @@ -521,7 +515,6 @@ private: void updateRequestedVideoChannels(); void updateRequestedVideoChannelsDelayed(); void fillActiveVideoEndpoints(); - void refreshHasNotShownVideo(); void editParticipant( not_null participantPeer, @@ -580,7 +573,6 @@ private: rpl::variable _muted = MuteState::Muted; rpl::variable _canManage = false; rpl::variable _videoIsWorking = false; - rpl::variable _hasNotShownVideo = false; bool _initialMuteStateSent = false; bool _acceptFields = false; diff --git a/Telegram/SourceFiles/calls/group/calls_group_members.cpp b/Telegram/SourceFiles/calls/group/calls_group_members.cpp index dc870283a..94a4a86eb 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_members.cpp @@ -46,125 +46,6 @@ constexpr auto kUserpicBlurRadius = 8; using Row = MembersRow; -[[nodiscard]] int VideoParticipantsLimit(not_null session) { - return int(session->account().appConfig().get( - "groupcall_video_participants_max", - 30.)); -} - -void SetupVideoPlaceholder( - not_null widget, - not_null chat, - int limit) { - struct State { - QImage blurred; - QImage rounded; - InMemoryKey key = {}; - std::shared_ptr view; - qint64 blurredCacheKey = 0; - }; - const auto state = widget->lifetime().make_state(); - const auto refreshBlurred = [=] { - const auto key = chat->userpicUniqueKey(state->view); - if (state->key == key && !state->blurred.isNull()) { - return; - } - constexpr auto size = kUserpicSizeForBlur; - state->key = key; - state->blurred = QImage( - QSize(size, size), - QImage::Format_ARGB32_Premultiplied); - { - auto p = Painter(&state->blurred); - auto hq = PainterHighQualityEnabler(p); - chat->paintUserpicSquare(p, state->view, 0, 0, size); - } - state->blurred = Images::BlurLargeImage( - std::move(state->blurred), - kUserpicBlurRadius); - widget->update(); - }; - const auto refreshRounded = [=](QSize size) { - refreshBlurred(); - const auto key = state->blurred.cacheKey(); - if (state->rounded.size() == size && state->blurredCacheKey == key) { - return; - } - state->blurredCacheKey = key; - state->rounded = Images::prepare( - state->blurred, - size.width(), - size.width(), // Square - Images::Option::Smooth, - size.width(), - size.height()); - { - auto p = QPainter(&state->rounded); - p.fillRect( - 0, - 0, - size.width(), - size.height(), - QColor(0, 0, 0, Viewport::kShadowMaxAlpha)); - } - state->rounded = Images::prepare( - std::move(state->rounded), - size.width(), - size.height(), - (Images::Option::RoundedLarge | Images::Option::RoundedAll), - size.width(), - size.height()); - }; - chat->loadUserpic(); - refreshBlurred(); - - widget->paintRequest( - ) | rpl::start_with_next([=] { - const auto size = QSize( - widget->width(), - widget->height() - st::groupCallVideoSmallSkip); - refreshRounded(size * cIntRetinaFactor()); - - auto p = QPainter(widget); - const auto inner = QRect(QPoint(), size); - p.drawImage(inner, state->rounded); - st::groupCallPaused.paint( - p, - (size.width() - st::groupCallPaused.width()) / 2, - st::groupCallVideoPlaceholderIconTop, - size.width()); - - const auto skip = st::groupCallVideoLargeSkip; - p.setPen(st::groupCallVideoTextFg); - const auto text = QRect( - skip, - st::groupCallVideoPlaceholderTextTop, - (size.width() - 2 * skip), - size.height() - st::groupCallVideoPlaceholderTextTop); - p.setFont(st::semiboldFont); - p.drawText( - text, - tr::lng_group_call_limit(tr::now, lt_count, int(limit)), - style::al_top); - }, widget->lifetime()); -} - -void SetupVideoAboutLimit( - not_null widget, - not_null session, - int limit) { - const auto label = Ui::CreateChild( - widget.get(), - tr::lng_group_call_over_limit(lt_count, rpl::single(limit * 1.)), - st::groupCallVideoLimitLabel); - widget->widthValue( - ) | rpl::start_with_next([=](int width) { - label->resizeToWidth(width); - label->moveToLeft(0, st::normalFont->height / 3); - widget->resize(width, label->height() + st::normalFont->height); - }, label->lifetime()); -} - } // namespace class Members::Controller final @@ -1658,8 +1539,6 @@ Members::Members( , _layout(_scroll->setOwnedWidget( object_ptr(_scroll.data()))) , _videoWrap(_layout->add(object_ptr(_layout.get()))) -, _videoPlaceholder(std::make_unique(_videoWrap.get())) -, _videoAboutLimit(std::make_unique(_videoWrap.get())) , _viewport( std::make_unique( _videoWrap.get(), @@ -1897,61 +1776,9 @@ void Members::trackViewportGeometry() { _scroll->scrollTopValue( ) | rpl::skip(1) | rpl::start_with_next(move, _viewport->lifetime()); - const auto videoLimit = VideoParticipantsLimit(&_call->peer()->session()); - rpl::combine( - _layout->widthValue(), - _call->hasNotShownVideoValue() - ) | rpl::start_with_next([=](int width, bool has) { - const auto height = has ? st::groupCallVideoPlaceholderHeight : 0; - _videoPlaceholder->setGeometry(0, 0, width, height); - }, _videoPlaceholder->lifetime()); - - SetupVideoPlaceholder(_videoPlaceholder.get(), _call->peer(), videoLimit); - - _layout->widthValue( - ) | rpl::start_with_next([=](int width) { - _videoAboutLimit->resizeToWidth(width); - }, _videoAboutLimit->lifetime()); - - using namespace rpl::mappers; - auto aboutLimitRelevant = fullCountValue( - ) | rpl::map( - _1 > videoLimit - ) | rpl::distinct_until_changed(); - auto aboutLimitShown = rpl::combine( - std::move(aboutLimitRelevant), - _call->canManageValue(), - _1 && _2); - - SetupVideoAboutLimit( - _videoAboutLimit.get(), - &_call->peer()->session(), - videoLimit); - - rpl::combine( - _videoPlaceholder->heightValue(), - _viewport->fullHeightValue(), - _videoAboutLimit->heightValue(), - std::move(aboutLimitShown) - ) | rpl::start_with_next([=]( - int placeholder, - int viewport, - int aboutLimit, - bool aboutLimitShown) { - if (placeholder > 0 || viewport <= 0 || !aboutLimitShown) { - aboutLimitShown = false; - } - - // This call may update _videoAboutLimit->height() :( - _videoAboutLimit->setVisible(aboutLimitShown); - - _videoAboutLimit->move(0, viewport); - _videoWrap->resize( - _videoWrap->width(), - std::max( - placeholder, - (viewport - + (aboutLimitShown ? _videoAboutLimit->height() : 0)))); + _viewport->fullHeightValue( + ) | rpl::start_with_next([=](int viewport) { + _videoWrap->resize(_videoWrap->width(), viewport); if (viewport > 0) { move(); resize(); diff --git a/Telegram/SourceFiles/calls/group/calls_group_members.h b/Telegram/SourceFiles/calls/group/calls_group_members.h index bb8c2a813..f828d7910 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members.h +++ b/Telegram/SourceFiles/calls/group/calls_group_members.h @@ -101,8 +101,6 @@ private: std::unique_ptr _listController; not_null _layout; const not_null _videoWrap; - const std::unique_ptr _videoPlaceholder; - const std::unique_ptr _videoAboutLimit; std::unique_ptr _viewport; rpl::variable _addMemberButton = nullptr; RpWidget *_topSkip = nullptr;