From 0c05b1a12f50883897145450f4bf0fce63de4e06 Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Tue, 7 May 2019 10:46:22 -0700 Subject: [PATCH] Add support for ignoring errors encountered while configuring preferred attributes of an audio session. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will allow call audio to function when audio session attributes like `preferredInputNumberOfChannels` cannot be set due to intermittent OS errors. Bug: webrtc:10602 Change-Id: Ie9f3e58a6ab54a26a9bd795575d16c3a9fe5c65f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/135440 Commit-Queue: Kári Helgason Reviewed-by: Zeke Chin Reviewed-by: Kári Helgason Cr-Commit-Position: refs/heads/master@{#27871} --- .../audio/RTCAudioSession+Configuration.mm | 16 ++++++++++++---- sdk/objc/components/audio/RTCAudioSession.h | 9 +++++++++ sdk/objc/components/audio/RTCAudioSession.mm | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/sdk/objc/components/audio/RTCAudioSession+Configuration.mm b/sdk/objc/components/audio/RTCAudioSession+Configuration.mm index 0ece5926a8..c81ce1b916 100644 --- a/sdk/objc/components/audio/RTCAudioSession+Configuration.mm +++ b/sdk/objc/components/audio/RTCAudioSession+Configuration.mm @@ -97,7 +97,9 @@ error:&sampleRateError]) { RTCLogError(@"Failed to set preferred sample rate: %@", sampleRateError.localizedDescription); - error = sampleRateError; + if (!self.ignoresPreferredAttributeConfigurationErrors) { + error = sampleRateError; + } } else { RTCLog(@"Set preferred sample rate to: %.2f", configuration.sampleRate); @@ -110,7 +112,9 @@ error:&bufferDurationError]) { RTCLogError(@"Failed to set preferred IO buffer duration: %@", bufferDurationError.localizedDescription); - error = bufferDurationError; + if (!self.ignoresPreferredAttributeConfigurationErrors) { + error = bufferDurationError; + } } else { RTCLog(@"Set preferred IO buffer duration to: %f", configuration.ioBufferDuration); @@ -139,7 +143,9 @@ error:&inputChannelsError]) { RTCLogError(@"Failed to set preferred input number of channels: %@", inputChannelsError.localizedDescription); - error = inputChannelsError; + if (!self.ignoresPreferredAttributeConfigurationErrors) { + error = inputChannelsError; + } } else { RTCLog(@"Set input number of channels to: %ld", (long)inputNumberOfChannels); @@ -152,7 +158,9 @@ error:&outputChannelsError]) { RTCLogError(@"Failed to set preferred output number of channels: %@", outputChannelsError.localizedDescription); - error = outputChannelsError; + if (!self.ignoresPreferredAttributeConfigurationErrors) { + error = outputChannelsError; + } } else { RTCLog(@"Set output number of channels to: %ld", (long)outputNumberOfChannels); diff --git a/sdk/objc/components/audio/RTCAudioSession.h b/sdk/objc/components/audio/RTCAudioSession.h index d43418b44a..b5bba2f21e 100644 --- a/sdk/objc/components/audio/RTCAudioSession.h +++ b/sdk/objc/components/audio/RTCAudioSession.h @@ -182,6 +182,15 @@ RTC_OBJC_EXPORT @property(readonly) NSTimeInterval IOBufferDuration; @property(readonly) NSTimeInterval preferredIOBufferDuration; +/** + When YES, calls to -setConfiguration:error: and -setConfiguration:active:error: ignore errors in + configuring the audio session's "preferred" attributes (e.g. preferredInputNumberOfChannels). + Typically, configurations to preferred attributes are optimizations, and ignoring this type of + configuration error allows code flow to continue along the happy path when these optimization are + not available. The default value of this property is NO. + */ +@property(nonatomic) BOOL ignoresPreferredAttributeConfigurationErrors; + /** Default constructor. */ + (instancetype)sharedInstance; - (instancetype)init NS_UNAVAILABLE; diff --git a/sdk/objc/components/audio/RTCAudioSession.mm b/sdk/objc/components/audio/RTCAudioSession.mm index 1b2b487c5d..09ffa16fcc 100644 --- a/sdk/objc/components/audio/RTCAudioSession.mm +++ b/sdk/objc/components/audio/RTCAudioSession.mm @@ -43,6 +43,8 @@ NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume"; @synthesize session = _session; @synthesize delegates = _delegates; +@synthesize ignoresPreferredAttributeConfigurationErrors = + _ignoresPreferredAttributeConfigurationErrors; + (instancetype)sharedInstance { static dispatch_once_t onceToken; @@ -180,6 +182,23 @@ NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume"; } } +- (void)setIgnoresPreferredAttributeConfigurationErrors: + (BOOL)ignoresPreferredAttributeConfigurationErrors { + @synchronized(self) { + if (_ignoresPreferredAttributeConfigurationErrors == + ignoresPreferredAttributeConfigurationErrors) { + return; + } + _ignoresPreferredAttributeConfigurationErrors = ignoresPreferredAttributeConfigurationErrors; + } +} + +- (BOOL)ignoresPreferredAttributeConfigurationErrors { + @synchronized(self) { + return _ignoresPreferredAttributeConfigurationErrors; + } +} + // TODO(tkchin): Check for duplicates. - (void)addDelegate:(id)delegate { RTCLog(@"Adding delegate: (%p)", delegate);