diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index a67723f5827e5..92d67385fc65f 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -520,7 +520,12 @@ rpl::producer Call::captureMuteDeviceId() { void Call::setMuted(bool mute) { _muted = mute; - if (_instance) { + if (_screenWithAudio && _screenAudioControl) { + _screenAudioControl->setMicrophoneMuted(mute); + if (_instance) { + _instance->setMuteMicrophone(false); + } + } else if (_instance) { _instance->setMuteMicrophone(mute); } } @@ -1187,9 +1192,13 @@ void Call::createAndStartController(const MTPDphoneCall &call) { sendSignalingData(bytes); }); }, - .createAudioDeviceModule = Webrtc::AudioDeviceModuleCreator( - saveSetDeviceIdCallback), }; + + _screenAudioControl = std::make_shared(); + descriptor.createAudioDeviceModule + = Webrtc::MixingAudioDeviceModuleCreator( + Webrtc::AudioDeviceModuleCreator(saveSetDeviceIdCallback), + _screenAudioControl); if (Logs::DebugEnabled()) { const auto callLogFolder = cWorkingDir() + u"DebugLogs"_q; const auto callLogPath = callLogFolder + u"/last_call_log.txt"_q; @@ -1493,6 +1502,13 @@ void Call::toggleScreenSharing( } _videoCaptureDeviceId = QString(); _videoCaptureIsScreencast = false; + if (_screenWithAudio && _screenAudioControl) { + _screenAudioControl->setMicrophoneMuted(false); + _screenAudioControl->setLoopbackEnabled(false); + if (_muted.current() && _instance) { + _instance->setMuteMicrophone(true); + } + } _screenWithAudio = false; if (_systemAudioCapture) { _systemAudioCapture->stop(); @@ -1507,6 +1523,15 @@ void Call::toggleScreenSharing( _videoCaptureIsScreencast = true; _videoCaptureDeviceId = *uniqueId; _screenWithAudio = withAudio; + if (_screenAudioControl) { + _screenAudioControl->setLoopbackEnabled(withAudio); + if (withAudio && _muted.current()) { + _screenAudioControl->setMicrophoneMuted(true); + if (_instance) { + _instance->setMuteMicrophone(false); + } + } + } if (_videoCapture) { _videoCapture->switchToDevice(uniqueId->toStdString(), true); if (_instance) { @@ -1695,6 +1720,7 @@ void Call::handleControllerError(const QString &error) { } void Call::destroyController() { + _screenAudioControl = nullptr; _instanceLifetime.destroy(); Core::App().mediaDevices().setCaptureMuteTracker(this, false); if (_systemAudioCapture) { diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index 73baeb3b50212..2a558c81ef5bc 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -37,6 +37,7 @@ namespace Webrtc { enum class VideoState; class VideoTrack; struct DeviceResolvedId; +class MixingAudioControl; } // namespace Webrtc namespace Calls { @@ -387,6 +388,7 @@ class Call final std::vector> _conferenceParticipants; std::unique_ptr _instance; + std::shared_ptr _screenAudioControl; std::shared_ptr _videoCapture; QString _videoCaptureDeviceId; bool _videoCaptureIsScreencast = false; diff --git a/Telegram/lib_webrtc b/Telegram/lib_webrtc index 52636e86eaa49..8ecb2257958ab 160000 --- a/Telegram/lib_webrtc +++ b/Telegram/lib_webrtc @@ -1 +1 @@ -Subproject commit 52636e86eaa493de670daf71959d000b281bd153 +Subproject commit 8ecb2257958ab9913fbfc4210b06026989db182c