fix(ios) fix deadlock when selecting audio device

In WebRTC M92 the RTCAudioSession lock changed from a recursive one to a regular
mutex one, so make sure we don't attempt to lock it  while already holding the
lock.
This commit is contained in:
Saúl Ibarra Corretgé 2021-08-19 10:34:54 +02:00 committed by Saúl Ibarra Corretgé
parent d41c597446
commit a4d516ca86
1 changed files with 11 additions and 4 deletions

View File

@ -125,12 +125,19 @@ RCT_EXPORT_MODULE();
return _workerQueue; return _workerQueue;
} }
- (BOOL)setConfigWithoutLock:(RTCAudioSessionConfiguration *)config
error:(NSError * _Nullable *)outError {
RTCAudioSession *session = [RTCAudioSession sharedInstance];
return [session setConfiguration:config error:outError];
}
- (BOOL)setConfig:(RTCAudioSessionConfiguration *)config - (BOOL)setConfig:(RTCAudioSessionConfiguration *)config
error:(NSError * _Nullable *)outError { error:(NSError * _Nullable *)outError {
RTCAudioSession *session = [RTCAudioSession sharedInstance]; RTCAudioSession *session = [RTCAudioSession sharedInstance];
[session lockForConfiguration]; [session lockForConfiguration];
BOOL success = [session setConfiguration:config error:outError]; BOOL success = [self setConfigWithoutLock:config error:outError];
[session unlockForConfiguration]; [session unlockForConfiguration];
return success; return success;
@ -196,7 +203,7 @@ RCT_EXPORT_METHOD(setAudioDevice:(NSString *)device
break; break;
} }
} }
if (port != nil) { if (port != nil) {
// First remove the override if we are going to select a different device. // First remove the override if we are going to select a different device.
if (isSpeakerOn) { if (isSpeakerOn) {
@ -206,11 +213,11 @@ RCT_EXPORT_METHOD(setAudioDevice:(NSString *)device
// Special case for the earpiece. // Special case for the earpiece.
if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic]) { if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
forceEarpiece = YES; forceEarpiece = YES;
[self setConfig:earpieceConfig error:nil]; [self setConfigWithoutLock:earpieceConfig error:nil];
} else if (isEarpieceOn) { } else if (isEarpieceOn) {
// Reset the config. // Reset the config.
RTCAudioSessionConfiguration *config = [self configForMode:activeMode]; RTCAudioSessionConfiguration *config = [self configForMode:activeMode];
[self setConfig:config error:nil]; [self setConfigWithoutLock:config error:nil];
} }
// Select our preferred input. // Select our preferred input.