|
1876 | 1876 | if (state.DidEnableInput()) { |
1877 | 1877 | LOGI() << "Checking microphone permission..."; |
1878 | 1878 | // Attempt to acquire mic permissions at this point to return an erorr early. |
1879 | | - bool isAuthorized = EnsureMicrophonePermissionSync(); |
1880 | | - LOGI() << "AudioEngine pre-enable check, device permission: " |
| 1879 | + bool isAuthorized = IsMicrophonePermissionAuthorized(); |
| 1880 | + LOGI() << "AudioEngine pre-enable check, mic permission authorized: " |
1881 | 1881 | << (isAuthorized ? "true" : "false"); |
1882 | 1882 | if (!isAuthorized) { |
1883 | 1883 | return rollback(kAudioEngineErrorInsufficientDevicePermission); |
|
2705 | 2705 | // ---------------------------------------------------------------------------------------------------- |
2706 | 2706 | // Private - Microphone permission |
2707 | 2707 |
|
2708 | | -bool AudioEngineDevice::IsMicrophonePermissionGranted() { |
| 2708 | +bool AudioEngineDevice::IsMicrophonePermissionAuthorized() { |
2709 | 2709 | AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; |
2710 | 2710 | return status == AVAuthorizationStatusAuthorized; |
2711 | 2711 | } |
2712 | 2712 |
|
2713 | | -bool AudioEngineDevice::EnsureMicrophonePermissionSync() { |
2714 | | - AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; |
2715 | | - |
2716 | | - if (status == AVAuthorizationStatusAuthorized) { |
2717 | | - return true; |
2718 | | - } |
2719 | | - |
2720 | | - if (status == AVAuthorizationStatusNotDetermined) { |
2721 | | - // Request permission synchronously - this will block WebRTC's worker thread |
2722 | | - // but this is acceptable since instantiating AVAudioInputNode would block anyway |
2723 | | - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
2724 | | - __block BOOL granted = NO; |
2725 | | - |
2726 | | - [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio |
2727 | | - completionHandler:^(BOOL granted_inner) { |
2728 | | - granted = granted_inner; |
2729 | | - dispatch_semaphore_signal(semaphore); |
2730 | | - }]; |
2731 | | - |
2732 | | - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); |
2733 | | - return granted; |
2734 | | - } |
2735 | | - |
2736 | | - // Status is denied or restricted |
2737 | | - return false; |
2738 | | -} |
2739 | | - |
2740 | 2713 | // ---------------------------------------------------------------------------------------------------- |
2741 | 2714 | // Private - Audio session |
2742 | 2715 |
|
|
0 commit comments