mirror of
https://github.com/opencv/opencv.git
synced 2024-11-30 14:29:49 +08:00
Merge pull request #15517 from mshabunin:fix-osx-avfoundation-auth
This commit is contained in:
commit
70c88a2087
@ -316,24 +316,45 @@ 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)
|
||||
{
|
||||
if (!cv::utils::getConfigurationParameterBool("OPENCV_AVFOUNDATION_SKIP_AUTH", false))
|
||||
{
|
||||
fprintf(stderr, "OpenCV: not authorized to capture video (status %ld), requesting...\n", status);
|
||||
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}];
|
||||
if ([NSThread isMainThread])
|
||||
{
|
||||
// we run the main loop for 0.1 sec to show the message
|
||||
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "OpenCV: can not spin main run loop from other thread, set "
|
||||
"OPENCV_AVFOUNDATION_SKIP_AUTH=1 to disable authorization request "
|
||||
"and perform it in your application.\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "OpenCV: not authorized to capture video (status %ld), set "
|
||||
"OPENCV_AVFOUNDATION_SKIP_AUTH=0 to enable authorization request or "
|
||||
"perform it in your application.\n", status);
|
||||
}
|
||||
[localpool drain];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user