diff options
author | o0Ignition0o <jeremy.lempereur@gmail.com> | 2019-11-30 14:08:06 +0100 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2019-12-02 10:16:28 +0000 |
commit | 6d68e1e6506309997146667e79d1950150e18540 (patch) | |
tree | 0247824433a39475ae5184b8c7c00de897748aac /sys | |
parent | d3d4228972565018b1488babafe95af0d71f0a84 (diff) | |
download | gstreamer-plugins-bad-6d68e1e6506309997146667e79d1950150e18540.tar.gz |
avfvideosrc: Explicitly request device video permissions for macOS 10.14+
Since macOS Mojave (10.14), video permissions have to be explicitly
granted by a user in order to open a video device such as a camera.
This commit adds a check for the current permission status, and tries
to request for permission if applicable.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/applemedia/avfvideosrc.m | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sys/applemedia/avfvideosrc.m b/sys/applemedia/avfvideosrc.m index 0ef697da1..5a91d1d6e 100644 --- a/sys/applemedia/avfvideosrc.m +++ b/sys/applemedia/avfvideosrc.m @@ -427,6 +427,45 @@ static AVCaptureVideoOrientation GstAVFVideoSourceOrientation2AVCaptureVideoOrie GST_DEBUG_OBJECT (element, "Opening device"); + // Since Mojave, permissions are now supposed to be explicitly granted + // before performing anything on a device + if (@available(macOS 10.14, *)) { + // Check if permission has already been granted (or denied) + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; + switch (authStatus) { + case AVAuthorizationStatusDenied: + // The user has explicitly denied permission for media capture. + GST_ELEMENT_ERROR (element, RESOURCE, NOT_AUTHORIZED, + ("Device video access permission has been explicitly denied before"), ("Authorization status: %d", (int)authStatus)); + return success; + case AVAuthorizationStatusRestricted: + // The user is not allowed to access media capture devices. + GST_ELEMENT_ERROR (element, RESOURCE, NOT_AUTHORIZED, + ("Device video access permission cannot be granted by the user"), ("Authorization status: %d", (int)authStatus)); + return success; + case AVAuthorizationStatusAuthorized: + // The user has explicitly granted permission for media capture, + // or explicit user permission is not necessary for the media type in question. + GST_DEBUG_OBJECT (element, "Device video access permission has already been granted"); + break; + case AVAuthorizationStatusNotDetermined: + // Explicit user permission is required for media capture, + // but the user has not yet granted or denied such permission. + dispatch_sync (mainQueue, ^{ + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { + GST_DEBUG_OBJECT (element, "Device video access permission %s", granted ? "granted" : "not granted"); + }]; + }); + // Check if permission has been granted + AVAuthorizationStatus videoAuthorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; + if (videoAuthorizationStatus != AVAuthorizationStatusAuthorized) { + GST_ELEMENT_ERROR (element, RESOURCE, NOT_AUTHORIZED, + ("Device video access permission has just been denied"), ("Authorization status: %d", (int)videoAuthorizationStatus)); + return success; + } + } + } + dispatch_sync (mainQueue, ^{ BOOL ret; |