Reset IO thread checker when iOS audio unit stops

In AudioDeviceIOS, when we call Stop() on the VoiceProcessingAudioUnit,
we do not always detach the I/O thread checker in preparation for a new
start. This means that if we start up the VoiceProcessingAudioUnit - and
subsequently a new AURemoteIO thread to deal with I/O operations - the
DCHECK in OnDeliverRecordedData and OnGetPlayoutData will fail. Note
that we want to detach the I/O thread checker regardless of whether
Stop() returns with a success status or not. The success status is
dictated by the iOS function AudioOutputUnitStop. The documentation of
this function does not guarantee that the audio unit will not stop in
the case the function returns with an error code. That is to say, it is
possible the audio unit stops even if the function Stop() returns false.
Therefore, it is safer to prepare the I/O thread checker for a new start
in either case.

Change-Id: Iee50a2457959aff2e6089e9a664c649dc4dbbbd6
Bug: webrtc:12382
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/202945
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33063}
diff --git a/sdk/objc/native/src/audio/audio_device_ios.mm b/sdk/objc/native/src/audio/audio_device_ios.mm
index 5ffeaa0..1e9bef6 100644
--- a/sdk/objc/native/src/audio/audio_device_ios.mm
+++ b/sdk/objc/native/src/audio/audio_device_ios.mm
@@ -508,9 +508,8 @@
     RTCLog(@"Stopping the audio unit due to interruption begin.");
     if (!audio_unit_->Stop()) {
       RTCLogError(@"Failed to stop the audio unit for interruption begin.");
-    } else {
-      PrepareForNewStart();
     }
+    PrepareForNewStart();
   }
   is_interrupted_ = true;
 }
@@ -813,8 +812,10 @@
     RTCLog(@"Stopping audio unit for UpdateAudioUnit");
     if (!audio_unit_->Stop()) {
       RTCLogError(@"Failed to stop audio unit.");
+      PrepareForNewStart();
       return;
     }
+    PrepareForNewStart();
   }
 
   if (should_uninitialize_audio_unit) {