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}
diff --git a/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm b/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm
index 67a70da..69cfa22 100644
--- a/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm
+++ b/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm
@@ -335,6 +335,7 @@
   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 @@
     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 @@
   }
 }
 
+- (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