Skip to content

AVFoundation: Use runtime check for camera authorization#14278

Merged
alalek merged 2 commits intoopencv:masterfrom
mshabunin:fix-osx-camera-auth-rt
Apr 11, 2019
Merged

AVFoundation: Use runtime check for camera authorization#14278
alalek merged 2 commits intoopencv:masterfrom
mshabunin:fix-osx-camera-auth-rt

Conversation

@mshabunin
Copy link
Copy Markdown
Contributor

@mshabunin mshabunin commented Apr 8, 2019

related #14267

This pullrequest changes

Compile-time check has been replaced with runtime check.

cc @jeroen

force_builders_only=Mac,iOS
buildworker:Mac=macosx-1

@mshabunin mshabunin added the backport is needed Label for maintainers. Authors of PR can ignore this label Apr 8, 2019
@mshabunin
Copy link
Copy Markdown
Contributor Author

@jeroen , looks like there is an error when building on OSX 10.13 with dynamic check:

/build/precommit_macosx/opencv/modules/videoio/src/cap_avfoundation_mac.mm:329:9: error: 'AVAuthorizationStatus' is unavailable: not available on macOS
        AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        ^
/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1591:28: note: 'AVAuthorizationStatus' has been explicitly marked unavailable here
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
                           ^
/build/precommit_macosx/opencv/modules/videoio/src/cap_avfoundation_mac.mm:329:57: error: 'authorizationStatusForMediaType:' is unavailable: not available on macOS
        AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
                                                        ^
/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1617:1: note: 'authorizationStatusForMediaType:' has been explicitly marked unavailable here
+ (AVAuthorizationStatus)authorizationStatusForMediaType:(NSString *)mediaType NS_AVAILABLE_IOS(7_0);
^
/build/precommit_macosx/opencv/modules/videoio/src/cap_avfoundation_mac.mm:330:23: error: 'AVAuthorizationStatusDenied' is unavailable: not available on macOS
        if (status == AVAuthorizationStatusDenied)
                      ^
/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1591:28: note: 'AVAuthorizationStatus' has been explicitly marked unavailable here
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
                           ^
/build/precommit_macosx/opencv/modules/videoio/src/cap_avfoundation_mac.mm:339:28: error: 'AVAuthorizationStatusAuthorized' is unavailable: not available on macOS
        else if (status != AVAuthorizationStatusAuthorized)
                           ^
/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1591:28: note: 'AVAuthorizationStatus' has been explicitly marked unavailable here
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
                           ^
/build/precommit_macosx/opencv/modules/videoio/src/cap_avfoundation_mac.mm:343:30: error: 'requestAccessForMediaType:completionHandler:' is unavailable: not available on macOS
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}];
                             ^
/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1645:1: note: 'requestAccessForMediaType:completionHandler:' has been explicitly marked unavailable here
+ (void)requestAccessForMediaType:(NSString *)mediaType completionHandler:(void (^)(BOOL granted))handler NS_AVAILABLE_IOS(7_0);
^
5 errors generated.

I believe we need both compile-time and runtime checks and an application should be built on OSX 10.14. Also AppKit release notes state that dynamic checks with @include are available in Obj-C since XCode 9 (10.13).

@jeroen
Copy link
Copy Markdown

jeroen commented Apr 8, 2019

OK thank you for trying. I suppose we need to build on Mojave to use the AVAuthorizationStatus api. I am curious how other applications (which are distributed via a portable installer) handle this problem.

@Ritz-19
Copy link
Copy Markdown

Ritz-19 commented Apr 27, 2021

I am a college student learning OpenCV, I can't turn on my webcam as it shows

zsh: abort      /usr/local/bin/python3 

. StackOverflow and other internet resources show due to changes in macOS Mojave, AVFoundation needs to be used. I am currently doing

camera = cv2.VideoCapture(0)

I would be grateful if you could let me know how to make it work. I know this is not the place to ask, but I would be grateful if you did since I couldn't find documentation on it
I'm using macOS Big Sur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

port/backport done Label for maintainers. Authors of PR can ignore this

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants