Add proof-of-concept screen sharing on Windows.

This commit is contained in:
John Preston 2021-04-16 18:15:56 +04:00
parent ebdbe4a8d6
commit 38cb1b195d
5 changed files with 111 additions and 24 deletions

View File

@ -368,6 +368,9 @@ GroupCall::GroupCall(
_realChanges.fire_copy(real);
}, _lifetime);
}
setupMediaDevices();
if (_id) {
join(inputCall);
} else {
@ -376,26 +379,31 @@ GroupCall::GroupCall(
if (_scheduleDate) {
saveDefaultJoinAs(_joinAs);
}
_mediaDevices->audioInputId(
) | rpl::start_with_next([=](QString id) {
_audioInputId = id;
if (_instance) {
_instance->setAudioInputDevice(id.toStdString());
}
}, _lifetime);
_mediaDevices->audioOutputId(
) | rpl::start_with_next([=](QString id) {
_audioOutputId = id;
if (_instance) {
_instance->setAudioOutputDevice(id.toStdString());
}
}, _lifetime);
}
GroupCall::~GroupCall() {
destroyController();
switchToCamera();
}
bool GroupCall::isScreenSharing() const {
return (_videoDeviceId != _videoInputId);
}
void GroupCall::switchToCamera() {
if (!_videoCapture || !isScreenSharing()) {
return;
}
_videoDeviceId = _videoInputId;
_videoCapture->switchToDevice(_videoDeviceId.toStdString());
}
void GroupCall::switchToScreenSharing() {
if (isScreenSharing()) {
return;
}
_videoDeviceId = "desktop_capturer_";
_videoCapture->switchToDevice(_videoDeviceId.toStdString());
}
void GroupCall::setScheduledDate(TimeId date) {
@ -1322,6 +1330,41 @@ void GroupCall::applyOtherParticipantUpdate(
});
}
void GroupCall::setupMediaDevices() {
_mediaDevices->audioInputId(
) | rpl::start_with_next([=](QString id) {
_audioInputId = id;
if (_instance) {
_instance->setAudioInputDevice(id.toStdString());
}
}, _lifetime);
_mediaDevices->audioOutputId(
) | rpl::start_with_next([=](QString id) {
_audioOutputId = id;
if (_instance) {
_instance->setAudioOutputDevice(id.toStdString());
}
}, _lifetime);
_mediaDevices->videoInputId(
) | rpl::start_with_next([=](QString id) {
const auto usedCamera = !isScreenSharing();
_videoInputId = id;
if (_videoCapture && usedCamera) {
_videoCapture->switchToDevice(_videoDeviceId.toStdString());
}
}, _lifetime);
setupOutgoingVideo();
}
void GroupCall::setupOutgoingVideo() {
_videoCapture = _delegate->groupCallGetVideoCapture();
_videoOutgoing->setState(Webrtc::VideoState::Active);
_videoCapture->setOutput(_videoOutgoing->sink());
_videoDeviceId = _videoInputId;
}
void GroupCall::changeTitle(const QString &title) {
const auto real = lookupReal();
if (!real || real->title() == title) {
@ -1372,12 +1415,6 @@ void GroupCall::ensureControllerCreated() {
}
const auto &settings = Core::App().settings();
if (!_videoCapture) {
_videoCapture = _delegate->groupCallGetVideoCapture();
_videoOutgoing->setState(Webrtc::VideoState::Active);
_videoCapture->setOutput(_videoOutgoing->sink());
}
const auto weak = base::make_weak(this);
const auto myLevel = std::make_shared<tgcalls::GroupLevelValue>();
tgcalls::GroupInstanceDescriptor descriptor = {
@ -1821,6 +1858,10 @@ void GroupCall::setCurrentAudioDevice(bool input, const QString &deviceId) {
}
}
void GroupCall::setCurrentVideoDevice(const QString &deviceId) {
_mediaDevices->switchToVideoInput(deviceId);
}
void GroupCall::toggleMute(const Group::MuteRequest &data) {
if (data.locallyOnly) {
applyParticipantLocally(data.peer, data.mute, std::nullopt);

View File

@ -209,6 +209,10 @@ public:
static constexpr auto kSpeakLevelThreshold = 0.2;
void setCurrentAudioDevice(bool input, const QString &deviceId);
void setCurrentVideoDevice(const QString &deviceId);
bool isScreenSharing() const;
void switchToCamera();
void switchToScreenSharing();
//void setAudioVolume(bool input, float level);
void setAudioDuckingEnabled(bool enabled);
@ -314,6 +318,9 @@ private:
void applySelfUpdate(const MTPDgroupCallParticipant &data);
void applyOtherParticipantUpdate(const MTPDgroupCallParticipant &data);
void setupMediaDevices();
void setupOutgoingVideo();
[[nodiscard]] MTPInputGroupCall inputCall() const;
const not_null<Delegate*> _delegate;
@ -377,6 +384,8 @@ private:
std::unique_ptr<Webrtc::MediaDevices> _mediaDevices;
QString _audioInputId;
QString _audioOutputId;
QString _videoInputId;
QString _videoDeviceId;
rpl::lifetime _lifetime;

View File

@ -673,7 +673,12 @@ void Panel::refreshLeftButton() {
_share.destroy();
_settings.create(widget(), st::groupCallSettings);
_settings->setClickedCallback([=] {
_layerBg->showBox(Box(SettingsBox, _call));
if (_call->isScreenSharing()) {
_call->switchToCamera();
} else {
_call->switchToScreenSharing();
}
//_layerBg->showBox(Box(SettingsBox, _call));
});
_settings->setText(tr::lng_group_call_settings());
}

@ -1 +1 @@
Subproject commit cdd2803ad40cbba455f64ee93bc434698afc2e06
Subproject commit 082b938cbfef6539bdf6b71f9b46f9c2b2880d24

View File

@ -56,6 +56,19 @@ PRIVATE
VideoCaptureInterfaceImpl.h
VideoCapturerInterface.h
# Desktop capturer
desktop_capturer/DesktopCaptureSource.h
desktop_capturer/DesktopCaptureSource.mm
desktop_capturer/DesktopCaptureSourceHelper.h
desktop_capturer/DesktopCaptureSourceHelper.mm
desktop_capturer/DesktopCaptureSourceManager.h
desktop_capturer/DesktopCaptureSourceManager.mm
desktop_capturer/DesktopCaptureSourceView.h
desktop_capturer/DesktopCaptureSourceView.mm
desktop_capturer/DesktopSharingCapturer.h
desktop_capturer/DesktopSharingCapturer.mm
# Group calls
group/GroupInstanceCustomImpl.cpp
group/GroupInstanceCustomImpl.h
group/GroupNetworkManager.cpp
@ -80,6 +93,8 @@ PRIVATE
platform/darwin/DarwinInterface.mm
platform/darwin/GLVideoView.h
platform/darwin/GLVideoView.mm
platform/darwin/GLVideoViewMac.h
platform/darwin/GLVideoViewMac.mm
platform/darwin/TGRTCCVPixelBuffer.h
platform/darwin/TGRTCCVPixelBuffer.mm
platform/darwin/TGRTCDefaultVideoDecoderFactory.h
@ -108,6 +123,8 @@ PRIVATE
# POSIX
# Teleram Desktop
platform/tdesktop/DesktopCapturer.cpp
platform/tdesktop/DesktopCapturer.h
platform/tdesktop/DesktopInterface.cpp
platform/tdesktop/DesktopInterface.h
platform/tdesktop/VideoCapturerInterfaceImpl.cpp
@ -122,6 +139,19 @@ PRIVATE
reference/InstanceImplReference.h
)
remove_target_sources(lib_tgcalls ${tgcalls_loc}
desktop_capturer/DesktopCaptureSource.h
desktop_capturer/DesktopCaptureSource.mm
desktop_capturer/DesktopCaptureSourceHelper.h
desktop_capturer/DesktopCaptureSourceHelper.mm
desktop_capturer/DesktopCaptureSourceManager.h
desktop_capturer/DesktopCaptureSourceManager.mm
desktop_capturer/DesktopCaptureSourceView.h
desktop_capturer/DesktopCaptureSourceView.mm
desktop_capturer/DesktopSharingCapturer.h
desktop_capturer/DesktopSharingCapturer.mm
)
target_link_libraries(lib_tgcalls
PRIVATE
desktop-app::external_webrtc
@ -152,6 +182,8 @@ elseif (APPLE)
remove_target_sources(lib_tgcalls ${tgcalls_loc}
platform/darwin/GLVideoView.h
platform/darwin/GLVideoView.mm
platform/darwin/GLVideoViewMac.h
platform/darwin/GLVideoViewMac.mm
platform/darwin/VideoCameraCapturer.h
platform/darwin/VideoCameraCapturer.mm
platform/darwin/VideoMetalView.h