[macOS] Request camera permission before session init.
(cherry picked from commit e6801a098e
)
This commit is contained in:
parent
fe745e2fff
commit
92377f4b20
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "camera_osx.h"
|
#include "camera_osx.h"
|
||||||
#include "servers/camera/camera_feed.h"
|
#include "servers/camera/camera_feed.h"
|
||||||
|
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -253,10 +254,25 @@ CameraFeedOSX::~CameraFeedOSX() {
|
||||||
|
|
||||||
bool CameraFeedOSX::activate_feed() {
|
bool CameraFeedOSX::activate_feed() {
|
||||||
if (capture_session) {
|
if (capture_session) {
|
||||||
// already recording!
|
// Already recording!
|
||||||
} else {
|
} else {
|
||||||
// start camera capture
|
// Start camera capture, check permission.
|
||||||
capture_session = [[MyCaptureSession alloc] initForFeed:this andDevice:device];
|
if (@available(macOS 10.14, *)) {
|
||||||
|
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||||
|
if (status == AVAuthorizationStatusAuthorized) {
|
||||||
|
capture_session = [[MyCaptureSession alloc] initForFeed:this andDevice:device];
|
||||||
|
} else if (status == AVAuthorizationStatusNotDetermined) {
|
||||||
|
// Request permission.
|
||||||
|
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
|
||||||
|
completionHandler:^(BOOL granted) {
|
||||||
|
if (granted) {
|
||||||
|
capture_session = [[MyCaptureSession alloc] initForFeed:this andDevice:device];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
capture_session = [[MyCaptureSession alloc] initForFeed:this andDevice:device];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue