Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Unified Diff: webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm

Issue 2181163005: Treat foreground event as interruption end. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698