From 2e400d88d3e0171eea9e9001a534bd92daadc2f6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 30 Apr 2021 22:04:12 +0400 Subject: [PATCH] Fix creating group calls. --- Telegram/SourceFiles/calls/calls.style | 2 +- .../calls/group/calls_group_call.cpp | 42 ++++++++++++------- .../calls/group/calls_group_call.h | 9 ++-- .../calls/group/calls_group_panel.cpp | 12 +++--- .../ui/desktop_capture_choose_source.cpp | 5 +-- 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/calls/calls.style b/Telegram/SourceFiles/calls/calls.style index e346a43ee7..afc113e1ae 100644 --- a/Telegram/SourceFiles/calls/calls.style +++ b/Telegram/SourceFiles/calls/calls.style @@ -1130,7 +1130,7 @@ desktopCaptureSubmit: RoundButton(desktopCaptureCancel) { textBgOver: groupCallMuted1; ripple: RippleAnimation(groupCallRipple) { - color: groupCallMuted2; + color: shadowFg; } } diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index ae1cddad0a..a3b5222e73 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -379,10 +379,6 @@ GroupCall::GroupCall( , _joinHash(info.joinHash) , _id(inputCall.c_inputGroupCall().vid().v) , _scheduleDate(info.scheduleDate) -, _cameraOutgoing( - std::make_unique(Webrtc::VideoState::Inactive)) -, _screenOutgoing( - std::make_unique(Webrtc::VideoState::Inactive)) , _lastSpokeCheckTimer([=] { checkLastSpoke(); }) , _checkJoinedTimer([=] { checkJoined(); }) , _pushToTalkCancelTimer([=] { pushToTalkCancel(); }) @@ -454,7 +450,13 @@ GroupCall::~GroupCall() { } bool GroupCall::isScreenSharing() const { - return (_screenOutgoing->state() == Webrtc::VideoState::Active); + return _screenOutgoing + && (_screenOutgoing->state() == Webrtc::VideoState::Active); +} + +bool GroupCall::isCameraSharing() const { + return _cameraOutgoing + && (_cameraOutgoing->state() == Webrtc::VideoState::Active); } QString GroupCall::screenSharingDeviceId() const { @@ -462,6 +464,10 @@ QString GroupCall::screenSharingDeviceId() const { } void GroupCall::toggleVideo(bool active) { + if (!_instance || !_id) { + return; + } + ensureOutgoingVideo(); const auto state = active ? Webrtc::VideoState::Active : Webrtc::VideoState::Inactive; @@ -471,6 +477,7 @@ void GroupCall::toggleVideo(bool active) { } void GroupCall::toggleScreenSharing(std::optional uniqueId) { + ensureOutgoingVideo(); if (!uniqueId) { _screenOutgoing->setState(Webrtc::VideoState::Inactive); return; @@ -1233,14 +1240,6 @@ void GroupCall::addVideoOutput( } } -not_null GroupCall::outgoingCameraTrack() const { - return _cameraOutgoing.get(); -} - -not_null GroupCall::outgoingScreenTrack() const { - return _screenOutgoing.get(); -} - void GroupCall::setMuted(MuteState mute) { const auto set = [=] { const auto wasMuted = (muted() == MuteState::Muted) @@ -1502,10 +1501,20 @@ void GroupCall::setupMediaDevices() { _cameraCapture->switchToDevice(id.toStdString()); } }, _lifetime); - setupOutgoingVideo(); } -void GroupCall::setupOutgoingVideo() { +void GroupCall::ensureOutgoingVideo() { + Expects(_id != 0); + + if (_cameraOutgoing) { + return; + } + + _cameraOutgoing = std::make_unique( + Webrtc::VideoState::Inactive); + _screenOutgoing = std::make_unique( + Webrtc::VideoState::Inactive); + //static const auto hasDevices = [] { // return !Webrtc::GetVideoInputList().empty(); //}; @@ -2265,7 +2274,8 @@ void GroupCall::sendSelfUpdate(SendUpdateType type) { MTP_bool(muted() != MuteState::Active), MTP_int(100000), // volume MTP_bool(muted() == MuteState::RaisedHand), - MTP_bool(_cameraOutgoing->state() != Webrtc::VideoState::Active) + MTP_bool(!_cameraOutgoing + || _cameraOutgoing->state() != Webrtc::VideoState::Active) )).done([=](const MTPUpdates &result) { _updateMuteRequestId = 0; _peer->session().api().applyUpdates(result); diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index 8a98f63411..65eed2165b 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -172,8 +172,6 @@ public: void addVideoOutput( const std::string &endpoint, not_null track); - [[nodiscard]] not_null outgoingCameraTrack() const; - [[nodiscard]] not_null outgoingScreenTrack() const; void setMuted(MuteState mute); void setMutedAndUpdate(MuteState mute); @@ -268,6 +266,7 @@ public: void setCurrentAudioDevice(bool input, const QString &deviceId); void setCurrentVideoDevice(const QString &deviceId); [[nodiscard]] bool isScreenSharing() const; + [[nodiscard]] bool isCameraSharing() const; [[nodiscard]] QString screenSharingDeviceId() const; void toggleVideo(bool active); void toggleScreenSharing(std::optional uniqueId); @@ -387,7 +386,7 @@ private: void applyOtherParticipantUpdate(const MTPDgroupCallParticipant &data); void setupMediaDevices(); - void setupOutgoingVideo(); + void ensureOutgoingVideo(); [[nodiscard]] MTPInputGroupCall inputCall() const; @@ -435,14 +434,14 @@ private: InstanceMode _instanceMode = InstanceMode::None; std::unique_ptr _instance; std::shared_ptr _cameraCapture; - const std::unique_ptr _cameraOutgoing; + std::unique_ptr _cameraOutgoing; rpl::variable _screenInstanceState = InstanceState::Disconnected; InstanceMode _screenInstanceMode = InstanceMode::None; std::unique_ptr _screenInstance; std::shared_ptr _screenCapture; - const std::unique_ptr _screenOutgoing; + std::unique_ptr _screenOutgoing; QString _screenDeviceId; std::string _screenEndpoint; diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index 732e1a9702..9dc9ed036f 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -722,8 +722,7 @@ void Panel::refreshLeftButton() { &st::groupCallVideoActiveSmall); _video->show(); _video->setClickedCallback([=] { - _call->toggleVideo(_call->outgoingCameraTrack()->state() - != Webrtc::VideoState::Active); + _call->toggleVideo(!_call->isCameraSharing()); }); _video->setText(tr::lng_group_call_video()); _video->setColorOverrides(_mute->colorOverrides()); @@ -912,6 +911,9 @@ void Panel::setupMembers() { _startsWhen.destroy(); _members.create(widget(), _call); + setupPinnedVideo(); + + _members->setMode(_mode); _members->show(); _members->desiredHeightValue( @@ -946,8 +948,6 @@ void Panel::setupMembers() { addMembers(); } }, _callLifetime); - - setupPinnedVideo(); } void Panel::raiseControls() { @@ -1550,7 +1550,9 @@ bool Panel::updateMode() { if (_members) { _members->setMode(mode); } - _pinnedVideo->setVisible(mode == PanelMode::Wide); + if (_pinnedVideo) { + _pinnedVideo->setVisible(mode == PanelMode::Wide); + } refreshControlsBackground(); updateControlsGeometry(); return true; diff --git a/Telegram/SourceFiles/calls/group/ui/desktop_capture_choose_source.cpp b/Telegram/SourceFiles/calls/group/ui/desktop_capture_choose_source.cpp index 0aed00c137..17d9af835d 100644 --- a/Telegram/SourceFiles/calls/group/ui/desktop_capture_choose_source.cpp +++ b/Telegram/SourceFiles/calls/group/ui/desktop_capture_choose_source.cpp @@ -198,7 +198,7 @@ void Source::paint() { _widget.paintRipple( p, { 0, 0 }, - _active ? &st::groupCallMuted2->c : nullptr); + _active ? &st::shadowFg->c : nullptr); const auto size = _preview ? _preview->track.frameSize() : QSize(); const auto factor = style::DevicePixelRatio(); @@ -230,9 +230,8 @@ void Source::setupPreview() { ) | rpl::start_with_next([=] { if (_preview->track.frameSize().isEmpty()) { _preview->track.markFrameShown(); - } else { - _widget.update(); } + _widget.update(); }, _preview->lifetime); }