diff options
author | Kevin King <4kevinking@gmail.com> | 2020-06-23 15:31:51 -0700 |
---|---|---|
committer | GStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2020-06-24 18:56:53 +0000 |
commit | eebfed0726d25f7be559a650a2ca22cb8a89917a (patch) | |
tree | 0a56fd2f958d236756c8951b7530a90f2537ee5a | |
parent | 482d2c9459e679b1d1a289d18fdcb57c894eaf26 (diff) |
avfvideosrc: wait for permissions request dialog callback
otherwise gstreamer gives up on transitioning the pipeline before the
user has accepted
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1370>
-rw-r--r-- | sys/applemedia/avfvideosrc.m | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/sys/applemedia/avfvideosrc.m b/sys/applemedia/avfvideosrc.m index 147e46435..081aa9a9f 100644 --- a/sys/applemedia/avfvideosrc.m +++ b/sys/applemedia/avfvideosrc.m @@ -452,13 +452,24 @@ static AVCaptureVideoOrientation GstAVFVideoSourceOrientation2AVCaptureVideoOrie 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_semaphore_t sema = dispatch_semaphore_create(0); dispatch_sync (mainQueue, ^{ [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { GST_DEBUG_OBJECT (element, "Device video access permission %s", granted ? "granted" : "not granted"); + dispatch_semaphore_signal(sema); }]; }); + // Block on dialog being answered + if (![NSThread isMainThread]) { + dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); + } else { + while (dispatch_semaphore_wait(sema, DISPATCH_TIME_NOW)) { + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0]]; + } + } // Check if permission has been granted AVAuthorizationStatus videoAuthorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (videoAuthorizationStatus != AVAuthorizationStatusAuthorized) { |