From 5cb0eded642861d0f845f9c32140b00afd15826a Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Thu, 11 Apr 2019 19:16:50 +0300 Subject: [PATCH] Merge pull request #14278 from mshabunin:fix-osx-camera-auth-rt * AVFoundation: Use runtime check for camera authorization --- modules/videoio/src/cap_avfoundation_mac.mm | 37 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/modules/videoio/src/cap_avfoundation_mac.mm b/modules/videoio/src/cap_avfoundation_mac.mm index 5d49628..98a6c95 100644 --- a/modules/videoio/src/cap_avfoundation_mac.mm +++ b/modules/videoio/src/cap_avfoundation_mac.mm @@ -325,24 +325,27 @@ int CvCaptureCAM::startCaptureDevice(int cameraNum) { NSAutoreleasePool *localpool = [[NSAutoreleasePool alloc] init]; #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; - if (status == AVAuthorizationStatusDenied) + if (@available(macOS 10.14, *)) { - fprintf(stderr, "OpenCV: camera access has been denied. Either run 'tccutil reset Camera' " - "command in same terminal to reset application authorization status, " - "either modify 'System Preferences -> Security & Privacy -> Camera' " - "settings for your application.\n"); - [localpool drain]; - return 0; - } - else if (status != AVAuthorizationStatusAuthorized) - { - fprintf(stderr, "OpenCV: not authorized to capture video (status %ld), requesting...\n", status); - // TODO: doesn't work via ssh - [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}]; - // we do not wait for completion - [localpool drain]; - return 0; + AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; + if (status == AVAuthorizationStatusDenied) + { + fprintf(stderr, "OpenCV: camera access has been denied. Either run 'tccutil reset Camera' " + "command in same terminal to reset application authorization status, " + "either modify 'System Preferences -> Security & Privacy -> Camera' " + "settings for your application.\n"); + [localpool drain]; + return 0; + } + else if (status != AVAuthorizationStatusAuthorized) + { + fprintf(stderr, "OpenCV: not authorized to capture video (status %ld), requesting...\n", status); + // TODO: doesn't work via ssh + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}]; + // we do not wait for completion + [localpool drain]; + return 0; + } } #endif -- 2.7.4