Fix creating group calls.

This commit is contained in:
John Preston 2021-04-30 22:04:12 +04:00
parent d9aa660253
commit 2e400d88d3
5 changed files with 40 additions and 30 deletions

View file

@ -1130,7 +1130,7 @@ desktopCaptureSubmit: RoundButton(desktopCaptureCancel) {
textBgOver: groupCallMuted1; textBgOver: groupCallMuted1;
ripple: RippleAnimation(groupCallRipple) { ripple: RippleAnimation(groupCallRipple) {
color: groupCallMuted2; color: shadowFg;
} }
} }

View file

@ -379,10 +379,6 @@ GroupCall::GroupCall(
, _joinHash(info.joinHash) , _joinHash(info.joinHash)
, _id(inputCall.c_inputGroupCall().vid().v) , _id(inputCall.c_inputGroupCall().vid().v)
, _scheduleDate(info.scheduleDate) , _scheduleDate(info.scheduleDate)
, _cameraOutgoing(
std::make_unique<Webrtc::VideoTrack>(Webrtc::VideoState::Inactive))
, _screenOutgoing(
std::make_unique<Webrtc::VideoTrack>(Webrtc::VideoState::Inactive))
, _lastSpokeCheckTimer([=] { checkLastSpoke(); }) , _lastSpokeCheckTimer([=] { checkLastSpoke(); })
, _checkJoinedTimer([=] { checkJoined(); }) , _checkJoinedTimer([=] { checkJoined(); })
, _pushToTalkCancelTimer([=] { pushToTalkCancel(); }) , _pushToTalkCancelTimer([=] { pushToTalkCancel(); })
@ -454,7 +450,13 @@ GroupCall::~GroupCall() {
} }
bool GroupCall::isScreenSharing() const { 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 { QString GroupCall::screenSharingDeviceId() const {
@ -462,6 +464,10 @@ QString GroupCall::screenSharingDeviceId() const {
} }
void GroupCall::toggleVideo(bool active) { void GroupCall::toggleVideo(bool active) {
if (!_instance || !_id) {
return;
}
ensureOutgoingVideo();
const auto state = active const auto state = active
? Webrtc::VideoState::Active ? Webrtc::VideoState::Active
: Webrtc::VideoState::Inactive; : Webrtc::VideoState::Inactive;
@ -471,6 +477,7 @@ void GroupCall::toggleVideo(bool active) {
} }
void GroupCall::toggleScreenSharing(std::optional<QString> uniqueId) { void GroupCall::toggleScreenSharing(std::optional<QString> uniqueId) {
ensureOutgoingVideo();
if (!uniqueId) { if (!uniqueId) {
_screenOutgoing->setState(Webrtc::VideoState::Inactive); _screenOutgoing->setState(Webrtc::VideoState::Inactive);
return; return;
@ -1233,14 +1240,6 @@ void GroupCall::addVideoOutput(
} }
} }
not_null<Webrtc::VideoTrack*> GroupCall::outgoingCameraTrack() const {
return _cameraOutgoing.get();
}
not_null<Webrtc::VideoTrack*> GroupCall::outgoingScreenTrack() const {
return _screenOutgoing.get();
}
void GroupCall::setMuted(MuteState mute) { void GroupCall::setMuted(MuteState mute) {
const auto set = [=] { const auto set = [=] {
const auto wasMuted = (muted() == MuteState::Muted) const auto wasMuted = (muted() == MuteState::Muted)
@ -1502,10 +1501,20 @@ void GroupCall::setupMediaDevices() {
_cameraCapture->switchToDevice(id.toStdString()); _cameraCapture->switchToDevice(id.toStdString());
} }
}, _lifetime); }, _lifetime);
setupOutgoingVideo();
} }
void GroupCall::setupOutgoingVideo() { void GroupCall::ensureOutgoingVideo() {
Expects(_id != 0);
if (_cameraOutgoing) {
return;
}
_cameraOutgoing = std::make_unique<Webrtc::VideoTrack>(
Webrtc::VideoState::Inactive);
_screenOutgoing = std::make_unique<Webrtc::VideoTrack>(
Webrtc::VideoState::Inactive);
//static const auto hasDevices = [] { //static const auto hasDevices = [] {
// return !Webrtc::GetVideoInputList().empty(); // return !Webrtc::GetVideoInputList().empty();
//}; //};
@ -2265,7 +2274,8 @@ void GroupCall::sendSelfUpdate(SendUpdateType type) {
MTP_bool(muted() != MuteState::Active), MTP_bool(muted() != MuteState::Active),
MTP_int(100000), // volume MTP_int(100000), // volume
MTP_bool(muted() == MuteState::RaisedHand), MTP_bool(muted() == MuteState::RaisedHand),
MTP_bool(_cameraOutgoing->state() != Webrtc::VideoState::Active) MTP_bool(!_cameraOutgoing
|| _cameraOutgoing->state() != Webrtc::VideoState::Active)
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
_updateMuteRequestId = 0; _updateMuteRequestId = 0;
_peer->session().api().applyUpdates(result); _peer->session().api().applyUpdates(result);

View file

@ -172,8 +172,6 @@ public:
void addVideoOutput( void addVideoOutput(
const std::string &endpoint, const std::string &endpoint,
not_null<Webrtc::VideoTrack*> track); not_null<Webrtc::VideoTrack*> track);
[[nodiscard]] not_null<Webrtc::VideoTrack*> outgoingCameraTrack() const;
[[nodiscard]] not_null<Webrtc::VideoTrack*> outgoingScreenTrack() const;
void setMuted(MuteState mute); void setMuted(MuteState mute);
void setMutedAndUpdate(MuteState mute); void setMutedAndUpdate(MuteState mute);
@ -268,6 +266,7 @@ public:
void setCurrentAudioDevice(bool input, const QString &deviceId); void setCurrentAudioDevice(bool input, const QString &deviceId);
void setCurrentVideoDevice(const QString &deviceId); void setCurrentVideoDevice(const QString &deviceId);
[[nodiscard]] bool isScreenSharing() const; [[nodiscard]] bool isScreenSharing() const;
[[nodiscard]] bool isCameraSharing() const;
[[nodiscard]] QString screenSharingDeviceId() const; [[nodiscard]] QString screenSharingDeviceId() const;
void toggleVideo(bool active); void toggleVideo(bool active);
void toggleScreenSharing(std::optional<QString> uniqueId); void toggleScreenSharing(std::optional<QString> uniqueId);
@ -387,7 +386,7 @@ private:
void applyOtherParticipantUpdate(const MTPDgroupCallParticipant &data); void applyOtherParticipantUpdate(const MTPDgroupCallParticipant &data);
void setupMediaDevices(); void setupMediaDevices();
void setupOutgoingVideo(); void ensureOutgoingVideo();
[[nodiscard]] MTPInputGroupCall inputCall() const; [[nodiscard]] MTPInputGroupCall inputCall() const;
@ -435,14 +434,14 @@ private:
InstanceMode _instanceMode = InstanceMode::None; InstanceMode _instanceMode = InstanceMode::None;
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _instance; std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _instance;
std::shared_ptr<tgcalls::VideoCaptureInterface> _cameraCapture; std::shared_ptr<tgcalls::VideoCaptureInterface> _cameraCapture;
const std::unique_ptr<Webrtc::VideoTrack> _cameraOutgoing; std::unique_ptr<Webrtc::VideoTrack> _cameraOutgoing;
rpl::variable<InstanceState> _screenInstanceState rpl::variable<InstanceState> _screenInstanceState
= InstanceState::Disconnected; = InstanceState::Disconnected;
InstanceMode _screenInstanceMode = InstanceMode::None; InstanceMode _screenInstanceMode = InstanceMode::None;
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _screenInstance; std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _screenInstance;
std::shared_ptr<tgcalls::VideoCaptureInterface> _screenCapture; std::shared_ptr<tgcalls::VideoCaptureInterface> _screenCapture;
const std::unique_ptr<Webrtc::VideoTrack> _screenOutgoing; std::unique_ptr<Webrtc::VideoTrack> _screenOutgoing;
QString _screenDeviceId; QString _screenDeviceId;
std::string _screenEndpoint; std::string _screenEndpoint;

View file

@ -722,8 +722,7 @@ void Panel::refreshLeftButton() {
&st::groupCallVideoActiveSmall); &st::groupCallVideoActiveSmall);
_video->show(); _video->show();
_video->setClickedCallback([=] { _video->setClickedCallback([=] {
_call->toggleVideo(_call->outgoingCameraTrack()->state() _call->toggleVideo(!_call->isCameraSharing());
!= Webrtc::VideoState::Active);
}); });
_video->setText(tr::lng_group_call_video()); _video->setText(tr::lng_group_call_video());
_video->setColorOverrides(_mute->colorOverrides()); _video->setColorOverrides(_mute->colorOverrides());
@ -912,6 +911,9 @@ void Panel::setupMembers() {
_startsWhen.destroy(); _startsWhen.destroy();
_members.create(widget(), _call); _members.create(widget(), _call);
setupPinnedVideo();
_members->setMode(_mode);
_members->show(); _members->show();
_members->desiredHeightValue( _members->desiredHeightValue(
@ -946,8 +948,6 @@ void Panel::setupMembers() {
addMembers(); addMembers();
} }
}, _callLifetime); }, _callLifetime);
setupPinnedVideo();
} }
void Panel::raiseControls() { void Panel::raiseControls() {
@ -1550,7 +1550,9 @@ bool Panel::updateMode() {
if (_members) { if (_members) {
_members->setMode(mode); _members->setMode(mode);
} }
_pinnedVideo->setVisible(mode == PanelMode::Wide); if (_pinnedVideo) {
_pinnedVideo->setVisible(mode == PanelMode::Wide);
}
refreshControlsBackground(); refreshControlsBackground();
updateControlsGeometry(); updateControlsGeometry();
return true; return true;

View file

@ -198,7 +198,7 @@ void Source::paint() {
_widget.paintRipple( _widget.paintRipple(
p, p,
{ 0, 0 }, { 0, 0 },
_active ? &st::groupCallMuted2->c : nullptr); _active ? &st::shadowFg->c : nullptr);
const auto size = _preview ? _preview->track.frameSize() : QSize(); const auto size = _preview ? _preview->track.frameSize() : QSize();
const auto factor = style::DevicePixelRatio(); const auto factor = style::DevicePixelRatio();
@ -230,9 +230,8 @@ void Source::setupPreview() {
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
if (_preview->track.frameSize().isEmpty()) { if (_preview->track.frameSize().isEmpty()) {
_preview->track.markFrameShown(); _preview->track.markFrameShown();
} else {
_widget.update();
} }
_widget.update();
}, _preview->lifetime); }, _preview->lifetime);
} }