avfvideosrc: wait for permissions request dialog callback
authorKevin King <4kevinking@gmail.com>
Tue, 23 Jun 2020 22:31:51 +0000 (15:31 -0700)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 24 Jun 2020 18:56:53 +0000 (18:56 +0000)
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>

sys/applemedia/avfvideosrc.m

index 147e46435b58644cd6b4e9ad5869af363a9f5bbb..081aa9a9fc2138efc577315d62935ce2008b9c15 100644 (file)
@@ -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) {