Commit e98852a3 authored by Maksim Shabunin's avatar Maksim Shabunin

AVFoundation: fix authorization request not being shown

parent 08e4ffdf
...@@ -338,11 +338,29 @@ int CvCaptureCAM::startCaptureDevice(int cameraNum) { ...@@ -338,11 +338,29 @@ int CvCaptureCAM::startCaptureDevice(int cameraNum) {
return 0; return 0;
} }
else if (status != AVAuthorizationStatusAuthorized) 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); 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 */}]; [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}];
// we do not wait for completion 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]; [localpool drain];
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment