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