Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions modules/audio_device/audio_engine_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ class AudioEngineDevice : public AudioDeviceModule, public AudioSessionObserver
std::vector<std::string> input_device_labels_;
#endif

bool IsMicrophonePermissionGranted();
bool EnsureMicrophonePermissionSync();
bool IsMicrophonePermissionAuthorized();

#if !TARGET_OS_OSX
bool IsAudioSessionCategoryValid(NSString* category, bool is_input_enabled,
Expand Down
33 changes: 3 additions & 30 deletions modules/audio_device/audio_engine_device.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1876,8 +1876,8 @@
if (state.DidEnableInput()) {
LOGI() << "Checking microphone permission...";
// Attempt to acquire mic permissions at this point to return an erorr early.
bool isAuthorized = EnsureMicrophonePermissionSync();
LOGI() << "AudioEngine pre-enable check, device permission: "
bool isAuthorized = IsMicrophonePermissionAuthorized();
LOGI() << "AudioEngine pre-enable check, mic permission authorized: "
<< (isAuthorized ? "true" : "false");
if (!isAuthorized) {
return rollback(kAudioEngineErrorInsufficientDevicePermission);
Expand Down Expand Up @@ -2705,38 +2705,11 @@
// ----------------------------------------------------------------------------------------------------
// Private - Microphone permission

bool AudioEngineDevice::IsMicrophonePermissionGranted() {
bool AudioEngineDevice::IsMicrophonePermissionAuthorized() {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
return status == AVAuthorizationStatusAuthorized;
}

bool AudioEngineDevice::EnsureMicrophonePermissionSync() {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];

if (status == AVAuthorizationStatusAuthorized) {
return true;
}

if (status == AVAuthorizationStatusNotDetermined) {
// Request permission synchronously - this will block WebRTC's worker thread
// but this is acceptable since instantiating AVAudioInputNode would block anyway
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
__block BOOL granted = NO;

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio
completionHandler:^(BOOL granted_inner) {
granted = granted_inner;
dispatch_semaphore_signal(semaphore);
}];

dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return granted;
}

// Status is denied or restricted
return false;
}

// ----------------------------------------------------------------------------------------------------
// Private - Audio session

Expand Down