diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-05-17 14:18:45 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-06-07 15:44:35 +0000 |
commit | 99c1e5934fef1dfda6ecd682e48b97abb6823887 (patch) | |
tree | 389bf94316191df8507e363bbc0e90630b9980ab | |
parent | dc70e81da3f7b639ace9c5cc14e1fd4eb1942e4c (diff) |
Fix WebRTC screen sharing on macOS
Previously when a screen sharing request was accepted on macOS, instead
of showing the captured screen, a black rectangle was displayed. This
was due to passing an incorrect screen id to the screen capturer, which
resulted in a failed attempt to find the main active screen.
The fix is to query for all available screen ids from the operating
system, and choose the first id as the id to pass along to the screen
capturer.
Task-number: QTBUG-55165
Change-Id: Id8e648e59755aa2820b05b990adeaa9b58fd26f0
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/core/media_capture_devices_dispatcher.cpp | 32 | ||||
-rw-r--r-- | src/core/qtwebengine.gni | 1 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/core/media_capture_devices_dispatcher.cpp b/src/core/media_capture_devices_dispatcher.cpp index b3c42aa08..65c818903 100644 --- a/src/core/media_capture_devices_dispatcher.cpp +++ b/src/core/media_capture_devices_dispatcher.cpp @@ -62,6 +62,8 @@ #include "content/public/common/media_stream_request.h" #include "media/audio/audio_device_description.h" #include "media/audio/audio_manager_base.h" +#include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" +#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" #include "ui/base/l10n/l10n_util.h" #include <QtCore/qcoreapplication.h> @@ -331,7 +333,35 @@ void MediaCaptureDevicesDispatcher::handleScreenCaptureAccessRequest(content::We content::MediaStreamDevices devices; std::unique_ptr<content::MediaStreamUI> ui; if (userAccepted) { - content::DesktopMediaID screenId = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, 0); + // Source id patterns are different across platforms. + // On Linux, the hardcoded value "0" is used. + // On Windows, the screens are enumerated consecutively in increasing order from 0. + // On macOS the source ids are randomish numbers assigned by the OS. + webrtc::DesktopCapturer::SourceId id = 0; + +#if defined(ENABLE_WEBRTC) + // In order to provide a correct screen id, we query for the available screen ids, and + // select the first one as the main display id. + // The code is based on the file + // src/chrome/browser/extensions/api/desktop_capture/desktop_capture_base.cc. + webrtc::DesktopCaptureOptions options = + webrtc::DesktopCaptureOptions::CreateDefault(); + options.set_disable_effects(false); + std::unique_ptr<webrtc::DesktopCapturer> screen_capturer( + webrtc::DesktopCapturer::CreateScreenCapturer(options)); + + if (screen_capturer) { + webrtc::DesktopCapturer::SourceList screens; + if (screen_capturer->GetSourceList(&screens)) { + if (screens.size() > 0) { + id = screens[0].id; + } + } + } +#endif + + content::DesktopMediaID screenId = content::DesktopMediaID( + content::DesktopMediaID::TYPE_SCREEN, id); ui = getDevicesForDesktopCapture(&devices, screenId, false/*capture_audio*/, false/*display_notification*/, getContentsUrl(webContents)); } std::map<content::WebContents*, RequestsQueue>::iterator it = diff --git a/src/core/qtwebengine.gni b/src/core/qtwebengine.gni index 1c0c8a415..bb269baa2 100644 --- a/src/core/qtwebengine.gni +++ b/src/core/qtwebengine.gni @@ -25,6 +25,7 @@ deps = [ "//net:net_browser_services", "//skia", "//third_party/WebKit/public:blink", + "//third_party/webrtc/base:base", "//ui/accessibility", "//third_party/mesa:mesa_headers", ":qtwebengine_sources", |