Fix occasional crash in iOS ADM.

RTCNativeAudioSessionDelegateAdapter has a raw pointer to AudioDeviceIOS,
and receives callbacks from RTCAudioSession and forwards them to AudioDeviceIOS.

During teardown of these components the situation can occur that the dtor for
AudioDeviceIOS has been called but the ObjC runtime has not yet dealloced
RTCNativeAudioSessionDelegateAdapter, so it's still receiving callbacks while
the pointer it keeps to AudioDeviceIOS has been invalidated.

This occasionally triggers a crash when WebRTC is shutting down.

The fix in this CL is to make sure to deregister the adapter from RTCAudioSession
_before_ the dtor for AudioDeviceIOS returns.

Bug: webrtc:9523
Change-Id: Ica85420d76efc63940472bc43e3ec71d16036ccf
Reviewed-on: https://webrtc-review.googlesource.com/90245
Reviewed-by: Peter Hanspers <peterhanspers@webrtc.org>
Commit-Queue: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24173}
This commit is contained in:
Kári Tristan Helgason
2018-07-24 12:57:49 +02:00
committed by Commit Bot
parent ab4a530b87
commit ee1e74fb86

View File

@ -122,10 +122,10 @@ AudioDeviceIOS::AudioDeviceIOS()
}
AudioDeviceIOS::~AudioDeviceIOS() {
LOGI() << "~dtor" << ios::GetCurrentThreadDescription();
audio_session_observer_ = nil;
RTC_DCHECK(thread_checker_.CalledOnValidThread());
LOGI() << "~dtor" << ios::GetCurrentThreadDescription();
Terminate();
audio_session_observer_ = nil;
}
void AudioDeviceIOS::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
@ -835,6 +835,7 @@ void AudioDeviceIOS::UnconfigureAudioSession() {
RTCAudioSession* session = [RTCAudioSession sharedInstance];
[session lockForConfiguration];
[session unconfigureWebRTCSession:nil];
[session endWebRTCSession:nil];
[session unlockForConfiguration];
has_configured_session_ = false;
RTCLog(@"Unconfigured audio session.");
@ -902,10 +903,7 @@ void AudioDeviceIOS::ShutdownPlayOrRecord() {
// All I/O should be stopped or paused prior to deactivating the audio
// session, hence we deactivate as last action.
[session lockForConfiguration];
UnconfigureAudioSession();
[session endWebRTCSession:nil];
[session unlockForConfiguration];
}
void AudioDeviceIOS::PrepareForNewStart() {