Skip to content
Permalink
Browse files
In M1 Ventura safari 16.1, when the constraints passed in by getDispl…
…ayMedia contain the 'ideal' parameter, screen sharing will fail.

https://bugs.webkit.org/show_bug.cgi?id=247310
rdar://problem/101819966

Reviewed by Eric Carlson.

The issue is that the intrinsic size computation is wrong in GPUProcess.
This leads to a max size of (0, 0), which is used in case ideal constraints are used.

Instead of using CGDisplayCopyDisplayMode, we use getShareableContentWithCompletionHandler API which does not need any change to the sandbox.

* Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm:
(WebCore::ScreenCaptureKitCaptureSource::intrinsicSize const):

Canonical link: https://commits.webkit.org/256458@main
  • Loading branch information
youennf committed Nov 8, 2022
1 parent a20a8cd commit 882a38ecdaf1712c1415cdbbe39cdb6c075eb021
Showing 1 changed file with 35 additions and 1 deletion.
@@ -42,8 +42,10 @@
#import <wtf/BlockPtr.h>
#import <wtf/NeverDestroyed.h>
#import <wtf/ObjCRuntimeExtras.h>
#import <wtf/Scope.h>
#import <wtf/UUID.h>
#import <wtf/text/StringToIntegerConversion.h>
#include <wtf/threads/BinarySemaphore.h>

#import <pal/cf/CoreMediaSoftLink.h>
#import <pal/mac/ScreenCaptureKitSoftLink.h>
@@ -468,7 +470,38 @@ static void findSharableDevice(RetainPtr<SCShareableContent>&& shareableContent,

return { static_cast<int>(frame.size.width), static_cast<int>(frame.size.height) };
}

#if HAVE(SC_CONTENT_SHARING_SESSION)
IntSize size;
BinarySemaphore semaphore;
[PAL::getSCShareableContentClass() getShareableContentWithCompletionHandler:makeBlockPtr([&size, &semaphore, deviceID = m_deviceID, deviceType = m_captureDevice.type()] (SCShareableContent *shareableContent, NSError *error) mutable {
auto scope = makeScopeExit([&semaphore] {
semaphore.signal();
});
if (error) {
RELEASE_LOG_ERROR(WebRTC, "ScreenCaptureKitCaptureSource::intrinsicSize getShareableContentWithCompletionHandler failed with error %s", [[error localizedDescription] UTF8String]);
return;
}
if (deviceType == CaptureDevice::DeviceType::Screen) {
[[shareableContent displays] enumerateObjectsUsingBlock:makeBlockPtr([&] (SCDisplay *display, NSUInteger, BOOL *stop) {
if (display.displayID == deviceID) {
size = { static_cast<int>(display.width), static_cast<int>(display.height) };
*stop = YES;
}
}).get()];
return;
}
if (deviceType == CaptureDevice::DeviceType::Window) {
[[shareableContent windows] enumerateObjectsUsingBlock:makeBlockPtr([&] (SCWindow *window, NSUInteger, BOOL *stop) {
if (window.windowID == deviceID) {
size = { static_cast<int>(window.frame.size.width), static_cast<int>(window.frame.size.height) };
*stop = YES;
}
}).get()];
}
}).get()];
semaphore.wait();
return size;
#else
if (m_captureDevice.type() == CaptureDevice::DeviceType::Screen) {
auto displayMode = adoptCF(CGDisplayCopyDisplayMode(m_deviceID));
auto screenWidth = CGDisplayModeGetPixelsWide(displayMode.get());
@@ -491,6 +524,7 @@ static void findSharableDevice(RetainPtr<SCShareableContent>&& shareableContent,
});

return { static_cast<int>(bounds.size.width), static_cast<int>(bounds.size.height) };
#endif
}

void ScreenCaptureKitCaptureSource::updateStreamConfiguration()

0 comments on commit 882a38e

Please sign in to comment.