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;
ripple: RippleAnimation(groupCallRipple) {
color: groupCallMuted2;
color: shadowFg;
}
}

View File

@ -379,10 +379,6 @@ GroupCall::GroupCall(
, _joinHash(info.joinHash)
, _id(inputCall.c_inputGroupCall().vid().v)
, _scheduleDate(info.scheduleDate)
, _cameraOutgoing(
std::make_unique<Webrtc::VideoTrack>(Webrtc::VideoState::Inactive))
, _screenOutgoing(
std::make_unique<Webrtc::VideoTrack>(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<QString> uniqueId) {
ensureOutgoingVideo();
if (!uniqueId) {
_screenOutgoing->setState(Webrtc::VideoState::Inactive);
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) {
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::VideoTrack>(
Webrtc::VideoState::Inactive);
_screenOutgoing = std::make_unique<Webrtc::VideoTrack>(
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);

View File

@ -172,8 +172,6 @@ public:
void addVideoOutput(
const std::string &endpoint,
not_null<Webrtc::VideoTrack*> track);
[[nodiscard]] not_null<Webrtc::VideoTrack*> outgoingCameraTrack() const;
[[nodiscard]] not_null<Webrtc::VideoTrack*> 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<QString> 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<tgcalls::GroupInstanceCustomImpl> _instance;
std::shared_ptr<tgcalls::VideoCaptureInterface> _cameraCapture;
const std::unique_ptr<Webrtc::VideoTrack> _cameraOutgoing;
std::unique_ptr<Webrtc::VideoTrack> _cameraOutgoing;
rpl::variable<InstanceState> _screenInstanceState
= InstanceState::Disconnected;
InstanceMode _screenInstanceMode = InstanceMode::None;
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _screenInstance;
std::shared_ptr<tgcalls::VideoCaptureInterface> _screenCapture;
const std::unique_ptr<Webrtc::VideoTrack> _screenOutgoing;
std::unique_ptr<Webrtc::VideoTrack> _screenOutgoing;
QString _screenDeviceId;
std::string _screenEndpoint;

View File

@ -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;

View File

@ -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);
}