From c1f083d143a32da49ec3c65a9cafb5ef30fe3855 Mon Sep 17 00:00:00 2001 From: JT Teh Date: Wed, 25 Apr 2018 09:19:35 -0700 Subject: [PATCH] Add notifiers for when the audio session will be activated/deactivated, did activate/deactivate and failed to activate/deactivate. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:9191 Change-Id: I68a71701dd4c3660331080495b5be4408493aa86 Reviewed-on: https://webrtc-review.googlesource.com/72262 Commit-Queue: JT Teh Reviewed-by: Kári Helgason Cr-Commit-Position: refs/heads/master@{#23028} --- .../Classes/Audio/RTCAudioSession.mm | 30 +++++++++++++++++++ .../Headers/WebRTC/RTCAudioSession.h | 14 +++++++++ 2 files changed, 44 insertions(+) diff --git a/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm b/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm index 67a70da800..69cfa22aa8 100644 --- a/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm +++ b/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm @@ -335,6 +335,7 @@ NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume"; if (!active && activationCount == 0) { RTCLogWarning(@"Attempting to deactivate without prior activation."); } + [self notifyWillSetActive:active]; BOOL success = YES; BOOL isActive = self.isActive; // Keep a local error so we can log it. @@ -365,9 +366,11 @@ NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume"; if (active) { [self incrementActivationCount]; } + [self notifyDidSetActive:active]; } else { RTCLogError(@"Failed to setActive:%d. Error: %@", active, error.localizedDescription); + [self notifyFailedToSetActive:active error:error]; } // Decrement activation count on deactivation whether or not it succeeded. if (!active) { @@ -931,4 +934,31 @@ NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume"; } } +- (void)notifyWillSetActive:(BOOL)active { + for (id delegate : self.delegates) { + SEL sel = @selector(audioSession:willSetActive:); + if ([delegate respondsToSelector:sel]) { + [delegate audioSession:self willSetActive:active]; + } + } +} + +- (void)notifyDidSetActive:(BOOL)active { + for (id delegate : self.delegates) { + SEL sel = @selector(audioSession:didSetActive:); + if ([delegate respondsToSelector:sel]) { + [delegate audioSession:self didSetActive:active]; + } + } +} + +- (void)notifyFailedToSetActive:(BOOL)active error:(NSError *)error { + for (id delegate : self.delegates) { + SEL sel = @selector(audioSession:failedToSetActive:error:); + if ([delegate respondsToSelector:sel]) { + [delegate audioSession:self failedToSetActive:active error:error]; + } + } +} + @end diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCAudioSession.h b/sdk/objc/Framework/Headers/WebRTC/RTCAudioSession.h index 354634ec39..6c4c96ab05 100644 --- a/sdk/objc/Framework/Headers/WebRTC/RTCAudioSession.h +++ b/sdk/objc/Framework/Headers/WebRTC/RTCAudioSession.h @@ -84,6 +84,20 @@ RTC_EXPORT - (void)audioSession:(RTCAudioSession *)audioSession didDetectPlayoutGlitch:(int64_t)totalNumberOfGlitches; +/** Called when the audio session is about to change the active state. + */ +- (void)audioSession:(RTCAudioSession *)audioSession willSetActive:(BOOL)active; + +/** Called after the audio session sucessfully changed the active state. + */ +- (void)audioSession:(RTCAudioSession *)audioSession didSetActive:(BOOL)active; + +/** Called after the audio session failed to change the active state. + */ +- (void)audioSession:(RTCAudioSession *)audioSession + failedToSetActive:(BOOL)active + error:(NSError *)error; + @end /** This is a protocol used to inform RTCAudioSession when the audio session