Add notifiers for when the audio session will be activated/deactivated, did activate/deactivate and failed to activate/deactivate.

Bug: webrtc:9191
Change-Id: I68a71701dd4c3660331080495b5be4408493aa86
Reviewed-on: https://webrtc-review.googlesource.com/72262
Commit-Queue: JT Teh <jtteh@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23028}
This commit is contained in:
JT Teh
2018-04-25 09:19:35 -07:00
committed by Commit Bot
parent dc872b6be1
commit c1f083d143
2 changed files with 44 additions and 0 deletions

View File

@ -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