28 lines
978 B
Plaintext
28 lines
978 B
Plaintext
// SPDX-License-Identifier: Apache-2.0
|
|
#include "sdl_audio.h"
|
|
|
|
#import <AVFoundation/AVFoundation.h>
|
|
#include <atomic>
|
|
|
|
error_t sdl_audio_microphone_permission() {
|
|
@autoreleasepool {
|
|
switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) {
|
|
case AVAuthorizationStatusAuthorized:
|
|
return ERROR_NONE;
|
|
case AVAuthorizationStatusDenied:
|
|
case AVAuthorizationStatusRestricted:
|
|
return ERROR_NOT_ALLOWED;
|
|
case AVAuthorizationStatusNotDetermined: {
|
|
static std::atomic<bool> requested { false };
|
|
if (!requested.exchange(true)) {
|
|
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
|
|
requested.store(false);
|
|
}];
|
|
}
|
|
return ERROR_RESOURCE_BUSY;
|
|
}
|
|
}
|
|
return ERROR_NOT_ALLOWED;
|
|
}
|
|
}
|