From fb09eeb8f1b7e13d6b8a0a120af10bfd6ad576c8 Mon Sep 17 00:00:00 2001 From: henrika Date: Wed, 22 Nov 2017 14:25:25 +0100 Subject: [PATCH] Attempt to resolve crash in AudioDeviceIOS::UpdateAudioDeviceBuffer Bug: b/69547732 Change-Id: I078175f96d55351ab0318aa2de96f4b859e752ea Reviewed-on: https://webrtc-review.googlesource.com/24864 Commit-Queue: Henrik Andreassson Reviewed-by: Zeke Chin Cr-Commit-Position: refs/heads/master@{#20903} --- modules/audio_device/ios/audio_device_ios.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/audio_device/ios/audio_device_ios.mm b/modules/audio_device/ios/audio_device_ios.mm index 6027ab794a..528e146068 100644 --- a/modules/audio_device/ios/audio_device_ios.mm +++ b/modules/audio_device/ios/audio_device_ios.mm @@ -675,6 +675,17 @@ void AudioDeviceIOS::SetupAudioBuffersForActiveAudioSession() { RTC_LOG(LS_WARNING) << "Unable to set the preferred sample rate"; } + // Crash reports indicates that it can happen in rare cases that the reported + // sample rate is less than or equal to zero. If that happens and if a valid + // sample rate has already been set during initialization, the best guess we + // can do is to reuse the current sample rate. + if (sample_rate <= DBL_EPSILON && playout_parameters_.sample_rate() > 0) { + RTCLogError(@"Reported rate is invalid: %f. " + "Using %d as sample rate instead.", + sample_rate, playout_parameters_.sample_rate()); + sample_rate = playout_parameters_.sample_rate(); + } + // At this stage, we also know the exact IO buffer duration and can add // that info to the existing audio parameters where it is converted into // number of audio frames.