Procházet zdrojové kódy

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.
master
Saúl Ibarra Corretgé před 3 roky
rodič
revize
a4d516ca86
1 změnil soubory, kde provedl 11 přidání a 4 odebrání
  1. 11
    4
      ios/sdk/src/AudioMode.m

+ 11
- 4
ios/sdk/src/AudioMode.m Zobrazit soubor

@@ -125,12 +125,19 @@ RCT_EXPORT_MODULE();
125 125
     return _workerQueue;
126 126
 }
127 127
 
128
+- (BOOL)setConfigWithoutLock:(RTCAudioSessionConfiguration *)config
129
+                       error:(NSError * _Nullable *)outError {
130
+    RTCAudioSession *session = [RTCAudioSession sharedInstance];
131
+
132
+    return [session setConfiguration:config error:outError];
133
+}
134
+
128 135
 - (BOOL)setConfig:(RTCAudioSessionConfiguration *)config
129 136
             error:(NSError * _Nullable *)outError {
130 137
 
131 138
     RTCAudioSession *session = [RTCAudioSession sharedInstance];
132 139
     [session lockForConfiguration];
133
-    BOOL success = [session setConfiguration:config error:outError];
140
+    BOOL success = [self setConfigWithoutLock:config error:outError];
134 141
     [session unlockForConfiguration];
135 142
 
136 143
     return success;
@@ -196,7 +203,7 @@ RCT_EXPORT_METHOD(setAudioDevice:(NSString *)device
196 203
                 break;
197 204
             }
198 205
         }
199
-        
206
+
200 207
         if (port != nil) {
201 208
             // First remove the override if we are going to select a different device.
202 209
             if (isSpeakerOn) {
@@ -206,11 +213,11 @@ RCT_EXPORT_METHOD(setAudioDevice:(NSString *)device
206 213
             // Special case for the earpiece.
207 214
             if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
208 215
                 forceEarpiece = YES;
209
-                [self setConfig:earpieceConfig error:nil];
216
+                [self setConfigWithoutLock:earpieceConfig error:nil];
210 217
             } else if (isEarpieceOn) {
211 218
                 // Reset the config.
212 219
                 RTCAudioSessionConfiguration *config = [self configForMode:activeMode];
213
-                [self setConfig:config error:nil];
220
+                [self setConfigWithoutLock:config error:nil];
214 221
             }
215 222
 
216 223
             // Select our preferred input.

Načítá se…
Zrušit
Uložit