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

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

Issue 2895263006: Add observer for AVAudioSession.outputVolume (Closed)
Patch Set: Fixed formatting Created 3 years, 7 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 84cc6da4e436d566c007461912cd183bc3b3a9bf..5c25d0b91babb93f5836b5f3c35f6dbfb3ed5935 100644
--- a/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm
+++ b/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm
@@ -24,6 +24,7 @@
NSString * const kRTCAudioSessionErrorDomain = @"org.webrtc.RTCAudioSession";
NSInteger const kRTCAudioSessionErrorLockRequired = -1;
NSInteger const kRTCAudioSessionErrorConfiguration = -2;
+NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume";
// This class needs to be thread-safe because it is accessed from many threads.
// TODO(tkchin): Consider more granular locking. We're not expecting a lot of
@@ -86,6 +87,11 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
selector:@selector(handleApplicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
+ [_session addObserver:self
+ forKeyPath:kRTCAudioSessionOutputVolumeSelector
+ options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
+ context:nil];
+
RTCLog(@"RTCAudioSession (%p): init.", self);
}
return self;
@@ -93,6 +99,7 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ [_session removeObserver:self forKeyPath:kRTCAudioSessionOutputVolumeSelector context:nil];
RTCLog(@"RTCAudioSession (%p): dealloc.", self);
}
@@ -803,6 +810,19 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
[self decrementActivationCount];
}
+- (void)observeValueForKeyPath:(NSString *)keyPath
+ ofObject:(id)object
+ change:(NSDictionary *)change
+ context:(void *)context {
+ if (object == _session) {
+ NSNumber *newVolume = change[NSKeyValueChangeNewKey];
+ [self notifyAudioVolumeDidChange:newVolume.floatValue];
+ } else {
+ [super observeValueForKeyPath:keyPath ofObject:object change:change
tkchin_webrtc 2017/05/25 23:01:00 nit: either all args on same line, or all on diffe
+ context:context];
+ }
+}
+
- (void)notifyDidBeginInterruption {
for (auto delegate : self.delegates) {
SEL sel = @selector(audioSessionDidBeginInterruption:);
@@ -880,4 +900,14 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
}
}
+- (void)notifyAudioVolumeDidChange:(float)volume {
tkchin_webrtc 2017/05/25 23:01:00 nit: notifyDidChangeOutputVolume
+ RTCLog(@"AudioVolumeDidChange to %f", volume);
tkchin_webrtc 2017/05/25 23:01:00 Would place this at the point where you know it ch
+ for (auto delegate : self.delegates) {
+ SEL sel = @selector(audioSession:didChangeOutputVolume:);
+ if ([delegate respondsToSelector:sel]) {
+ [delegate audioSession:self didChangeOutputVolume:volume];
+ }
+ }
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698