From 616f4e4027ca8a7ab0411305a9ea9036bb3cb086 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 14 Mar 2022 12:59:54 +0400 Subject: [PATCH] Allow volume changing in RTMP stream context menu. --- .../calls/group/calls_group_call.cpp | 28 +++++++++++++++---- .../calls/group/calls_group_call.h | 2 ++ .../calls/group/calls_group_members.cpp | 20 +++++++------ .../calls/group/calls_group_settings.cpp | 4 ++- .../SourceFiles/window/window_peer_menu.cpp | 3 -- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index dd0f151a8..09fb828dc 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -594,6 +594,7 @@ GroupCall::GroupCall( , _connectingSoundTimer([=] { playConnectingSoundOnce(); }) , _listenersHidden(info.rtmp) , _rtmp(info.rtmp) +, _rtmpVolume(Group::kDefaultVolume) , _mediaDevices(CreateMediaDevices()) { _muted.value( ) | rpl::combine_previous( @@ -1029,6 +1030,10 @@ rpl::producer GroupCall::emptyRtmpValue() const { return _emptyRtmp.value(); } +int GroupCall::rtmpVolume() const { + return _rtmpVolume; +} + Calls::Group::RtmpInfo GroupCall::rtmpInfo() const { return { _rtmpUrl, _rtmpKey }; } @@ -1094,7 +1099,7 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) { update.was->ssrc, GetAdditionalAudioSsrc(update.was->videoParams), }); - } else { + } else if (!_rtmp) { updateInstanceVolume(update.was, *update.now); } }, _lifetime); @@ -2885,9 +2890,14 @@ void GroupCall::updateInstanceVolumes() { return; } - const auto &participants = real->participants(); - for (const auto &participant : participants) { - updateInstanceVolume(std::nullopt, participant); + if (_rtmp) { + const auto value = _rtmpVolume / float64(Group::kDefaultVolume); + _instance->setVolume(1, value); + } else { + const auto &participants = real->participants(); + for (const auto &participant : participants) { + updateInstanceVolume(std::nullopt, participant); + } } } @@ -3283,7 +3293,10 @@ void GroupCall::setCurrentAudioDevice(bool input, const QString &deviceId) { } void GroupCall::toggleMute(const Group::MuteRequest &data) { - if (data.locallyOnly) { + if (_rtmp) { + _rtmpVolume = data.mute ? 0 : Group::kDefaultVolume; + updateInstanceVolumes(); + } else if (data.locallyOnly) { applyParticipantLocally(data.peer, data.mute, std::nullopt); } else { editParticipant(data.peer, data.mute, std::nullopt); @@ -3291,7 +3304,10 @@ void GroupCall::toggleMute(const Group::MuteRequest &data) { } void GroupCall::changeVolume(const Group::VolumeRequest &data) { - if (data.locallyOnly) { + if (_rtmp) { + _rtmpVolume = data.volume; + updateInstanceVolumes(); + } else if (data.locallyOnly) { applyParticipantLocally(data.peer, false, data.volume); } else { editParticipant(data.peer, false, data.volume); diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index 15b75e677..6f363c1c2 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -236,6 +236,7 @@ public: [[nodiscard]] bool listenersHidden() const; [[nodiscard]] bool emptyRtmp() const; [[nodiscard]] rpl::producer emptyRtmpValue() const; + [[nodiscard]] int rtmpVolume() const; [[nodiscard]] Group::RtmpInfo rtmpInfo() const; @@ -673,6 +674,7 @@ private: bool _hadJoinedState = false; bool _listenersHidden = false; bool _rtmp = false; + int _rtmpVolume = 0; std::unique_ptr _mediaDevices; QString _audioInputId; diff --git a/Telegram/SourceFiles/calls/group/calls_group_members.cpp b/Telegram/SourceFiles/calls/group/calls_group_members.cpp index cbca11e06..5086768ad 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_members.cpp @@ -1190,9 +1190,8 @@ base::unique_qptr Members::Controller::createRowContextMenu( const auto muteState = real->state(); const auto muted = (muteState == Row::State::Muted) || (muteState == Row::State::RaisedHand); - const auto addCover = true; - const auto addVolumeItem = !_call->rtmp() - && (!muted || isMe(participantPeer)); + const auto addCover = !_call->rtmp(); + const auto addVolumeItem = (!muted || isMe(participantPeer)); const auto admin = IsGroupCallAdmin(_peer, participantPeer); const auto session = &_peer->session(); const auto getCurrentWindow = [=]() -> Window::SessionController* { @@ -1327,7 +1326,13 @@ base::unique_qptr Members::Controller::createRowContextMenu( } } - if (participant + if (_call->rtmp()) { + addMuteActionsToContextMenu( + result, + row->peer(), + false, + static_cast(row.get())); + } else if (participant && (!isMe(participantPeer) || _peer->canManageGroupCall()) && (participant->ssrc != 0 || GetAdditionalAudioSsrc(participant->videoParams) != 0)) { @@ -1431,8 +1436,7 @@ void Members::Controller::addMuteActionsToContextMenu( auto mutesFromVolume = rpl::never() | rpl::type_erased(); - const auto addVolumeItem = !_call->rtmp() - && (!muted || isMe(participantPeer)); + const auto addVolumeItem = (!muted || isMe(participantPeer)); if (addVolumeItem) { auto otherParticipantStateValue = _call->otherParticipantStateValue( @@ -1444,7 +1448,7 @@ void Members::Controller::addMuteActionsToContextMenu( menu->menu(), st::groupCallPopupVolumeMenu, otherParticipantStateValue, - row->volume(), + _call->rtmp() ? _call->rtmpVolume() : row->volume(), Group::kMaxVolume, muted); @@ -1487,7 +1491,7 @@ void Members::Controller::addMuteActionsToContextMenu( menu->addAction(std::move(volumeItem)); - if (!isMe(participantPeer)) { + if (!_call->rtmp() && !isMe(participantPeer)) { menu->addSeparator(); } }; diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp index 4c017f55f..9ab4f72dd 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp @@ -266,7 +266,9 @@ void SettingsBox( const auto &settings = Core::App().settings(); const auto joinMuted = goodReal ? real->joinMuted() : false; - const auto canChangeJoinMuted = (goodReal && real->canChangeJoinMuted()); + const auto canChangeJoinMuted = !rtmp + && goodReal + && real->canChangeJoinMuted(); const auto addCheck = (peer->canManageGroupCall() && canChangeJoinMuted); const auto addDivider = [&] { diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index d99c65069..958148396 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -164,9 +164,6 @@ private: void addNewMembers(); void addDeleteContact(); - void addChatActions(not_null chat); - void addChannelActions(not_null channel); - not_null _controller; Dialogs::EntryState _request; PeerData *_peer = nullptr;