From 91ef6f13c83deacaf8f0d6de595515d9ced0d618 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 9 Aug 2021 15:05:58 +0300 Subject: [PATCH] Use good bitrate for screen capture in calls. --- Telegram/SourceFiles/calls/calls_call.cpp | 18 ++++++++++--- Telegram/SourceFiles/calls/calls_call.h | 6 +++-- Telegram/SourceFiles/calls/calls_instance.cpp | 25 ++++++++++++------- Telegram/SourceFiles/calls/calls_instance.h | 3 ++- .../calls/group/calls_group_call.cpp | 11 +++++--- .../SourceFiles/settings/settings_calls.cpp | 7 ++++-- Telegram/ThirdParty/tgcalls | 2 +- Telegram/cmake/lib_tgcalls.cmake | 13 ---------- 8 files changed, 49 insertions(+), 36 deletions(-) diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 3b2c1ee4e1..af79225781 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -378,7 +378,8 @@ void Call::setupOutgoingVideo() { Assert(state == Webrtc::VideoState::Active); if (!_videoCapture) { _videoCapture = _delegate->callGetVideoCapture( - _videoCaptureDeviceId); + _videoCaptureDeviceId, + _videoCaptureIsScreencast); _videoCapture->setOutput(_videoOutgoing->sink()); } if (_instance) { @@ -985,7 +986,10 @@ void Call::setCurrentCameraDevice(const QString &deviceId) { if (!_videoCaptureIsScreencast) { _videoCaptureDeviceId = deviceId; if (_videoCapture) { - _videoCapture->switchToDevice(deviceId.toStdString()); + _videoCapture->switchToDevice(deviceId.toStdString(), false); + if (_instance) { + _instance->sendVideoDeviceUpdated(); + } } } } @@ -1042,7 +1046,10 @@ void Call::toggleCameraSharing(bool enabled) { const auto deviceId = Core::App().settings().callVideoInputDeviceId(); _videoCaptureDeviceId = deviceId; if (_videoCapture) { - _videoCapture->switchToDevice(deviceId.toStdString()); + _videoCapture->switchToDevice(deviceId.toStdString(), false); + if (_instance) { + _instance->sendVideoDeviceUpdated(); + } } _videoOutgoing->setState(Webrtc::VideoState::Active); }), true); @@ -1066,7 +1073,10 @@ void Call::toggleScreenSharing(std::optional uniqueId) { _videoCaptureIsScreencast = true; _videoCaptureDeviceId = *uniqueId; if (_videoCapture) { - _videoCapture->switchToDevice(uniqueId->toStdString()); + _videoCapture->switchToDevice(uniqueId->toStdString(), true); + if (_instance) { + _instance->sendVideoDeviceUpdated(); + } } _videoOutgoing->setState(Webrtc::VideoState::Active); } diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index 479c5829a5..1478a8ed8b 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -77,8 +77,10 @@ public: Fn onSuccess, bool video) = 0; - virtual auto callGetVideoCapture(const QString &deviceId) - -> std::shared_ptr = 0; + virtual auto callGetVideoCapture( + const QString &deviceId, + bool isScreenCapture) + -> std::shared_ptr = 0; virtual ~Delegate() = default; diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index b32cccbe90..d14b12ebc5 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -64,8 +64,10 @@ public: Fn onSuccess, bool video) override; void callPlaySound(CallSound sound) override; - auto callGetVideoCapture(const QString &deviceId) - -> std::shared_ptr override; + auto callGetVideoCapture( + const QString &deviceId, + bool isScreenCapture) + -> std::shared_ptr override; void groupCallFinished(not_null call) override; void groupCallFailed(not_null call) override; @@ -123,9 +125,11 @@ void Instance::Delegate::callPlaySound(CallSound sound) { }()); } -auto Instance::Delegate::callGetVideoCapture(const QString &deviceId) +auto Instance::Delegate::callGetVideoCapture( + const QString &deviceId, + bool isScreenCapture) -> std::shared_ptr { - return _instance->getVideoCapture(deviceId); + return _instance->getVideoCapture(deviceId, isScreenCapture); } void Instance::Delegate::groupCallFinished(not_null call) { @@ -159,7 +163,7 @@ void Instance::Delegate::groupCallPlaySound(GroupCallSound sound) { auto Instance::Delegate::groupCallGetVideoCapture(const QString &deviceId) -> std::shared_ptr { - return _instance->getVideoCapture(deviceId); + return _instance->getVideoCapture(deviceId, false); } FnMut Instance::Delegate::groupCallAddAsyncWaiter() { @@ -699,12 +703,15 @@ void Instance::requestPermissionOrFail(Platform::PermissionType type, Fn } std::shared_ptr Instance::getVideoCapture( - std::optional deviceId) { + std::optional deviceId, + bool isScreenCapture) { if (auto result = _videoCapture.lock()) { if (deviceId) { - result->switchToDevice((deviceId->isEmpty() - ? Core::App().settings().callVideoInputDeviceId() - : *deviceId).toStdString()); + result->switchToDevice( + (deviceId->isEmpty() + ? Core::App().settings().callVideoInputDeviceId() + : *deviceId).toStdString(), + isScreenCapture); } return result; } diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h index f9604ff485..c403ef4ebb 100644 --- a/Telegram/SourceFiles/calls/calls_instance.h +++ b/Telegram/SourceFiles/calls/calls_instance.h @@ -76,7 +76,8 @@ public: bool minimizeCurrentActiveCall(); bool closeCurrentActiveCall(); [[nodiscard]] auto getVideoCapture( - std::optional deviceId = std::nullopt) + std::optional deviceId = std::nullopt, + bool isScreenCapture = false) -> std::shared_ptr; void requestPermissionsOrFail(Fn onSuccess, bool video = true); diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index e861e87fe5..7f38ec867b 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -654,7 +654,7 @@ void GroupCall::toggleScreenSharing( _screenWithAudio = withAudio; _screenState = Webrtc::VideoState::Active; if (changed && wasSharing && isSharingScreen()) { - _screenCapture->switchToDevice(uniqueId->toStdString()); + _screenCapture->switchToDevice(uniqueId->toStdString(), true); } if (_screenInstance) { _screenInstance->setIsMuted(!withAudio); @@ -1951,7 +1951,7 @@ void GroupCall::setupMediaDevices() { ) | rpl::start_with_next([=](QString id) { _cameraInputId = id; if (_cameraCapture) { - _cameraCapture->switchToDevice(id.toStdString()); + _cameraCapture->switchToDevice(id.toStdString(), false); } }, _lifetime); } @@ -2064,7 +2064,9 @@ void GroupCall::setupOutgoingVideo() { }); }); } else { - _cameraCapture->switchToDevice(_cameraInputId.toStdString()); + _cameraCapture->switchToDevice( + _cameraInputId.toStdString(), + false); } if (_instance) { _instance->setVideoCapture(_cameraCapture); @@ -2131,7 +2133,8 @@ void GroupCall::setupOutgoingVideo() { }); } else { _screenCapture->switchToDevice( - _screenDeviceId.toStdString()); + _screenDeviceId.toStdString(), + true); } if (_screenInstance) { _screenInstance->setVideoCapture(_screenCapture); diff --git a/Telegram/SourceFiles/settings/settings_calls.cpp b/Telegram/SourceFiles/settings/settings_calls.cpp index 77b17ebf25..a5bcd1b3e8 100644 --- a/Telegram/SourceFiles/settings/settings_calls.cpp +++ b/Telegram/SourceFiles/settings/settings_calls.cpp @@ -124,7 +124,9 @@ void Calls::setupContent() { call->setCurrentCameraDevice(deviceId); } if (*capturerOwner) { - (*capturerOwner)->switchToDevice(deviceId.toStdString()); + (*capturerOwner)->switchToDevice( + deviceId.toStdString(), + false); } }); _controller->show(Box([=](not_null box) { @@ -179,7 +181,8 @@ void Calls::setupContent() { return; } *capturerOwner = Core::App().calls().getVideoCapture( - Core::App().settings().callVideoInputDeviceId()); + Core::App().settings().callVideoInputDeviceId(), + false); (*capturerOwner)->setPreferredAspectRatio(0.); track->setState(VideoState::Active); (*capturerOwner)->setState(tgcalls::VideoState::Active); diff --git a/Telegram/ThirdParty/tgcalls b/Telegram/ThirdParty/tgcalls index 6f2746e04c..ae2a132788 160000 --- a/Telegram/ThirdParty/tgcalls +++ b/Telegram/ThirdParty/tgcalls @@ -1 +1 @@ -Subproject commit 6f2746e04c9b040f8c8dfc64d916a1853d09c4ce +Subproject commit ae2a132788a1b03a47c449bf5b933daeb1907247 diff --git a/Telegram/cmake/lib_tgcalls.cmake b/Telegram/cmake/lib_tgcalls.cmake index a1e469863a..7c7d5d5e38 100644 --- a/Telegram/cmake/lib_tgcalls.cmake +++ b/Telegram/cmake/lib_tgcalls.cmake @@ -177,19 +177,11 @@ PRIVATE ) if (WIN32) - target_compile_definitions(lib_tgcalls - PRIVATE - WEBRTC_WIN - ) elseif (APPLE) target_compile_options(lib_tgcalls PRIVATE -fobjc-arc ) - target_compile_definitions(lib_tgcalls - PRIVATE - WEBRTC_MAC - ) remove_target_sources(lib_tgcalls ${tgcalls_loc} platform/darwin/DesktopCaptureSourceView.h platform/darwin/DesktopCaptureSourceView.mm @@ -212,11 +204,6 @@ elseif (APPLE) platform/tdesktop/VideoCameraCapturer.cpp platform/tdesktop/VideoCameraCapturer.h ) -elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_definitions(lib_tgcalls - PRIVATE - WEBRTC_LINUX - ) endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")