summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMax Hilbrunner <mhilbrunner@users.noreply.github.com>2021-09-07 23:15:38 +0200
committerGitHub <noreply@github.com>2021-09-07 23:15:38 +0200
commit643ae7063c83b3abd61312d8f99e3b1e438f2658 (patch)
treee2d58de1be53959541d19c1f1c570268040577e8 /modules
parentca11f8ad3045c280b559adea4e2263c38c2c6df4 (diff)
parente6801a098e49f7326b3b3601485d7ee9be96c4e4 (diff)
Merge pull request #51964 from bruvzg/request_camera_permission
[macOS] Request camera permission before session init.
Diffstat (limited to 'modules')
-rw-r--r--modules/camera/camera_osx.mm22
1 files changed, 19 insertions, 3 deletions
diff --git a/modules/camera/camera_osx.mm b/modules/camera/camera_osx.mm
index 4875eb578a..02f7287d1b 100644
--- a/modules/camera/camera_osx.mm
+++ b/modules/camera/camera_osx.mm
@@ -33,6 +33,7 @@
#include "camera_osx.h"
#include "servers/camera/camera_feed.h"
+
#import <AVFoundation/AVFoundation.h>
//////////////////////////////////////////////////////////////////////////
@@ -253,10 +254,25 @@ CameraFeedOSX::~CameraFeedOSX() {
bool CameraFeedOSX::activate_feed() {
if (capture_session) {
- // already recording!
+ // Already recording!
} else {
- // start camera capture
- capture_session = [[MyCaptureSession alloc] initForFeed:this andDevice:device];
+ // Start camera capture, check permission.
+ 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;