| Index: webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm
|
| diff --git a/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm b/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm
|
| index 159d34e993acfbf755515bb3e507367c92bca80e..b17c601270c09bb9703de7c3002c9391692c1ff3 100644
|
| --- a/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm
|
| +++ b/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm
|
| @@ -10,6 +10,8 @@
|
|
|
| #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h"
|
|
|
| +#import <UIKit/UIKit.h>
|
| +
|
| #include "webrtc/base/atomicops.h"
|
| #include "webrtc/base/checks.h"
|
| #include "webrtc/base/criticalsection.h"
|
| @@ -36,6 +38,7 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
|
| BOOL _useManualAudio;
|
| BOOL _isAudioEnabled;
|
| BOOL _canPlayOrRecord;
|
| + BOOL _isInterrupted;
|
| }
|
|
|
| @synthesize session = _session;
|
| @@ -72,6 +75,11 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
|
| selector:@selector(handleMediaServicesWereReset:)
|
| name:AVAudioSessionMediaServicesWereResetNotification
|
| object:nil];
|
| + // Also track foreground event in order to deal with interruption ended situation.
|
| + [center addObserver:self
|
| + selector:@selector(handleApplicationDidBecomeActive:)
|
| + name:UIApplicationDidBecomeActiveNotification
|
| + object:nil];
|
| }
|
| return self;
|
| }
|
| @@ -434,10 +442,12 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
|
| case AVAudioSessionInterruptionTypeBegan:
|
| RTCLog(@"Audio session interruption began.");
|
| self.isActive = NO;
|
| + self.isInterrupted = YES;
|
| [self notifyDidBeginInterruption];
|
| break;
|
| case AVAudioSessionInterruptionTypeEnded: {
|
| RTCLog(@"Audio session interruption ended.");
|
| + self.isInterrupted = NO;
|
| [self updateAudioSessionAfterEvent];
|
| NSNumber *optionsNumber =
|
| notification.userInfo[AVAudioSessionInterruptionOptionKey];
|
| @@ -505,6 +515,15 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
|
| [self notifyMediaServicesWereReset];
|
| }
|
|
|
| +- (void)handleApplicationDidBecomeActive:(NSNotification *)notification {
|
| + if (self.isInterrupted) {
|
| + RTCLog(@"Application became active after an interruption. Treating as interruption end.");
|
| + self.isInterrupted = NO;
|
| + [self updateAudioSessionAfterEvent];
|
| + [self notifyDidEndInterruptionWithShouldResumeSession:YES];
|
| + }
|
| +}
|
| +
|
| #pragma mark - Private
|
|
|
| + (NSError *)lockError {
|
| @@ -565,6 +584,21 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
|
| return !self.useManualAudio || self.isAudioEnabled;
|
| }
|
|
|
| +- (BOOL)isInterrupted {
|
| + @synchronized(self) {
|
| + return _isInterrupted;
|
| + }
|
| +}
|
| +
|
| +- (void)setIsInterrupted:(BOOL)isInterrupted {
|
| + @synchronized(self) {
|
| + if (_isInterrupted == isInterrupted) {
|
| + return;
|
| + }
|
| + _isInterrupted = isInterrupted;
|
| + }
|
| +}
|
| +
|
| - (BOOL)checkLock:(NSError **)outError {
|
| // Check ivar instead of trying to acquire lock so that we won't accidentally
|
| // acquire lock if it hasn't already been called.
|
|
|