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

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

Issue 1796983004: Use RTCAudioSessionDelegate in AudioDeviceIOS. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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
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 b80a7fd255e3ac48d11fa3ac68c67e9b706ecbad..5f7f8dd7424246bd5ccc2f4c148c65f05e163396 100644
--- a/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm
+++ b/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm
@@ -12,6 +12,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/criticalsection.h"
+#include "webrtc/modules/audio_device/ios/audio_device_ios.h"
#import "webrtc/base/objc/RTCLogging.h"
#import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h"
@@ -26,7 +27,6 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
@implementation RTCAudioSession {
rtc::CriticalSection _crit;
AVAudioSession *_session;
- NSHashTable *_delegates;
NSInteger _activationCount;
NSInteger _lockRecursionCount;
BOOL _isActive;
@@ -34,6 +34,7 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
}
@synthesize session = _session;
+@synthesize delegates = _delegates;
Chuck 2016/03/15 14:33:21 Where does _delegates get initialized?
tkchin_webrtc 2016/03/15 20:14:58 It's on the stack so it's ctor gets called automat
+ (instancetype)sharedInstance {
static dispatch_once_t onceToken;
@@ -47,7 +48,6 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
- (instancetype)init {
if (self = [super init]) {
_session = [AVAudioSession sharedInstance];
- _delegates = [NSHashTable weakObjectsHashTable];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
@@ -109,14 +109,24 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
}
- (void)addDelegate:(id<RTCAudioSessionDelegate>)delegate {
+ if (!delegate) {
+ return;
+ }
@synchronized(self) {
- [_delegates addObject:delegate];
+ _delegates.push_back(delegate);
+ [self removeZeroedDelegates];
}
}
- (void)removeDelegate:(id<RTCAudioSessionDelegate>)delegate {
+ if (!delegate) {
+ return;
+ }
@synchronized(self) {
- [_delegates removeObject:delegate];
+ _delegates.erase(std::remove(_delegates.begin(),
+ _delegates.end(),
+ delegate));
+ [self removeZeroedDelegates];
}
}
@@ -227,6 +237,8 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
return self.session.IOBufferDuration;
}
+// TODO(tkchin): Simplify the amount of locking happening here. Likely that we
+// can just do atomic increments / decrements.
- (BOOL)setActive:(BOOL)active
error:(NSError **)outError {
if (![self checkLock:outError]) {
@@ -459,9 +471,25 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
return error;
}
-- (NSSet *)delegates {
+- (std::vector<__weak id<RTCAudioSessionDelegate> >)delegates {
Chuck 2016/03/15 14:33:21 Does the set for this property need to be synchron
tkchin_webrtc 2016/03/15 20:14:58 Thanks for catching that. No setter.
+ @synchronized(self) {
+ return _delegates;
+ }
+}
+
+- (void)pushDelegate:(id<RTCAudioSessionDelegate>)delegate {
@synchronized(self) {
- return _delegates.setRepresentation;
+ _delegates.insert(_delegates.begin(), delegate);
+ }
+}
+
+- (void)removeZeroedDelegates {
+ @synchronized(self) {
+ for (auto it = _delegates.begin(); it != _delegates.end(); ++it) {
+ if (!*it) {
+ _delegates.erase(it);
+ }
+ }
}
}
@@ -513,14 +541,14 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
}
- (void)notifyDidBeginInterruption {
- for (id<RTCAudioSessionDelegate> delegate in self.delegates) {
+ for (auto delegate : self.delegates) {
[delegate audioSessionDidBeginInterruption:self];
}
}
- (void)notifyDidEndInterruptionWithShouldResumeSession:
(BOOL)shouldResumeSession {
- for (id<RTCAudioSessionDelegate> delegate in self.delegates) {
+ for (auto delegate : self.delegates) {
[delegate audioSessionDidEndInterruption:self
shouldResumeSession:shouldResumeSession];
}
@@ -529,7 +557,7 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
- (void)notifyDidChangeRouteWithReason:(AVAudioSessionRouteChangeReason)reason
previousRoute:(AVAudioSessionRouteDescription *)previousRoute {
- for (id<RTCAudioSessionDelegate> delegate in self.delegates) {
+ for (auto delegate : self.delegates) {
[delegate audioSessionDidChangeRoute:self
reason:reason
previousRoute:previousRoute];
@@ -537,13 +565,13 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
}
- (void)notifyMediaServicesWereLost {
- for (id<RTCAudioSessionDelegate> delegate in self.delegates) {
+ for (auto delegate : self.delegates) {
[delegate audioSessionMediaServicesWereLost:self];
}
}
- (void)notifyMediaServicesWereReset {
- for (id<RTCAudioSessionDelegate> delegate in self.delegates) {
+ for (auto delegate : self.delegates) {
[delegate audioSessionMediaServicesWereReset:self];
}
}

Powered by Google App Engine
This is Rietveld 408576698