Skip to content

Commit

Permalink
Add ability to check Screen Recording privacy settings on macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 8, 2021
1 parent 539b9b5 commit 8926a5b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions webrtc/mac/webrtc_media_devices_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ class MacMediaDevices final : public MediaDevices {

};

[[nodiscard]] bool MacDesktopCaptureAllowed();

} // namespace Webrtc
11 changes: 11 additions & 0 deletions webrtc/mac/webrtc_media_devices_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "modules/audio_device/include/audio_device_defines.h"

#import <AVFoundation/AVFoundation.h>
#import <IOKit/hidsystem/IOHIDLib.h>

namespace Webrtc {
namespace {
Expand Down Expand Up @@ -395,4 +396,14 @@ OSStatus PropertyChangedCallback(
_resolvedVideoInputId = ResolveVideoInput(_videoInputId);
}

bool MacDesktopCaptureAllowed() {
if (@available(macOS 10.15, *)) {
// Screen Recording is required on macOS 10.15 an later.
// Even if user grants access, restart is required.
static const auto result = CGPreflightScreenCaptureAccess();
return result;
}
return true;
}

} // namespace Webrtc
8 changes: 8 additions & 0 deletions webrtc/webrtc_media_devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ std::unique_ptr<MediaDevices> CreateMediaDevices(
#endif
}

bool DesktopCaptureAllowed() {
#ifdef WEBRTC_MAC
return MacDesktopCaptureAllowed();
#else // WEBRTC_MAC
return true;
#endif // WEBRTC_MAC
}

std::optional<QString> UniqueDesktopCaptureSource() {
#ifdef WEBRTC_LINUX
return LinuxUniqueDesktopCaptureSource();
Expand Down
1 change: 1 addition & 0 deletions webrtc/webrtc_media_devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MediaDevices {
QString audioOutput,
QString videoInput);

[[nodiscard]] bool DesktopCaptureAllowed();
[[nodiscard]] std::optional<QString> UniqueDesktopCaptureSource();

} // namespace Webrtc

0 comments on commit 8926a5b

Please sign in to comment.