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

Side by Side Diff: webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm

Issue 2895263006: Add observer for AVAudioSession.outputVolume (Closed)
Patch Set: Add observer on AVAudioSession outputVolume. 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" 11 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h"
12 12
13 #import <UIKit/UIKit.h> 13 #import <UIKit/UIKit.h>
14 14
15 #include "webrtc/base/atomicops.h" 15 #include "webrtc/base/atomicops.h"
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/criticalsection.h" 17 #include "webrtc/base/criticalsection.h"
18 #include "webrtc/modules/audio_device/ios/audio_device_ios.h" 18 #include "webrtc/modules/audio_device/ios/audio_device_ios.h"
19 19
20 #import "WebRTC/RTCLogging.h" 20 #import "WebRTC/RTCLogging.h"
21 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h" 21 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h"
22 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h" 22 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h"
23 23
24 NSString * const kRTCAudioSessionErrorDomain = @"org.webrtc.RTCAudioSession"; 24 NSString * const kRTCAudioSessionErrorDomain = @"org.webrtc.RTCAudioSession";
25 NSInteger const kRTCAudioSessionErrorLockRequired = -1; 25 NSInteger const kRTCAudioSessionErrorLockRequired = -1;
26 NSInteger const kRTCAudioSessionErrorConfiguration = -2; 26 NSInteger const kRTCAudioSessionErrorConfiguration = -2;
27 NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume";
27 28
28 // This class needs to be thread-safe because it is accessed from many threads. 29 // This class needs to be thread-safe because it is accessed from many threads.
29 // TODO(tkchin): Consider more granular locking. We're not expecting a lot of 30 // TODO(tkchin): Consider more granular locking. We're not expecting a lot of
30 // lock contention so coarse locks should be fine for now. 31 // lock contention so coarse locks should be fine for now.
31 @implementation RTCAudioSession { 32 @implementation RTCAudioSession {
32 rtc::CriticalSection _crit; 33 rtc::CriticalSection _crit;
33 AVAudioSession *_session; 34 AVAudioSession *_session;
34 volatile int _activationCount; 35 volatile int _activationCount;
35 volatile int _lockRecursionCount; 36 volatile int _lockRecursionCount;
36 volatile int _webRTCSessionCount; 37 volatile int _webRTCSessionCount;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // hint to enable or disable audio that is secondary. 80 // hint to enable or disable audio that is secondary.
80 [center addObserver:self 81 [center addObserver:self
81 selector:@selector(handleSilenceSecondaryAudioHintNotification:) 82 selector:@selector(handleSilenceSecondaryAudioHintNotification:)
82 name:AVAudioSessionSilenceSecondaryAudioHintNotification 83 name:AVAudioSessionSilenceSecondaryAudioHintNotification
83 object:nil]; 84 object:nil];
84 // Also track foreground event in order to deal with interruption ended situ ation. 85 // Also track foreground event in order to deal with interruption ended situ ation.
85 [center addObserver:self 86 [center addObserver:self
86 selector:@selector(handleApplicationDidBecomeActive:) 87 selector:@selector(handleApplicationDidBecomeActive:)
87 name:UIApplicationDidBecomeActiveNotification 88 name:UIApplicationDidBecomeActiveNotification
88 object:nil]; 89 object:nil];
90
tkchin_webrtc 2017/05/25 20:24:33 nit: remove blank lines
91 [_session addObserver:self
92 forKeyPath:kRTCAudioSessionOutputVolumeSelector
93 options:NSKeyValueObservingOptionNew | NSKeyValueObservingOpti onOld
94 context:nil];
95
89 RTCLog(@"RTCAudioSession (%p): init.", self); 96 RTCLog(@"RTCAudioSession (%p): init.", self);
90 } 97 }
91 return self; 98 return self;
92 } 99 }
93 100
94 - (void)dealloc { 101 - (void)dealloc {
95 [[NSNotificationCenter defaultCenter] removeObserver:self]; 102 [[NSNotificationCenter defaultCenter] removeObserver:self];
103 [_session removeObserver:self forKeyPath:kRTCAudioSessionOutputVolumeSelector context:nil];
96 RTCLog(@"RTCAudioSession (%p): dealloc.", self); 104 RTCLog(@"RTCAudioSession (%p): dealloc.", self);
97 } 105 }
98 106
99 - (NSString *)description { 107 - (NSString *)description {
100 NSString *format = 108 NSString *format =
101 @"RTCAudioSession: {\n" 109 @"RTCAudioSession: {\n"
102 " category: %@\n" 110 " category: %@\n"
103 " categoryOptions: %ld\n" 111 " categoryOptions: %ld\n"
104 " mode: %@\n" 112 " mode: %@\n"
105 " isActive: %d\n" 113 " isActive: %d\n"
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 } 804 }
797 805
798 - (void)audioSessionDidDeactivate:(AVAudioSession *)session { 806 - (void)audioSessionDidDeactivate:(AVAudioSession *)session {
799 if (_session != session) { 807 if (_session != session) {
800 RTCLogError(@"audioSessionDidDeactivate called on different AVAudioSession") ; 808 RTCLogError(@"audioSessionDidDeactivate called on different AVAudioSession") ;
801 } 809 }
802 self.isActive = NO; 810 self.isActive = NO;
803 [self decrementActivationCount]; 811 [self decrementActivationCount];
804 } 812 }
805 813
814 - (void)observeValueForKeyPath:(NSString *)keyPath
815 ofObject:(id)object
816 change:(NSDictionary *)change
817 context:(void *)context {
818 if (object == _session) {
819 NSNumber *newVolume = change[NSKeyValueChangeNewKey];
820 [self notifyAudioVolumeDidChange:newVolume];
tkchin_webrtc 2017/05/25 20:24:32 notifyOutputVolumeDidChange also, pass the float d
821 } else {
822 [super observeValueForKeyPath:keyPath ofObject:object change:change context: context];
823 }
824 }
825
806 - (void)notifyDidBeginInterruption { 826 - (void)notifyDidBeginInterruption {
807 for (auto delegate : self.delegates) { 827 for (auto delegate : self.delegates) {
808 SEL sel = @selector(audioSessionDidBeginInterruption:); 828 SEL sel = @selector(audioSessionDidBeginInterruption:);
809 if ([delegate respondsToSelector:sel]) { 829 if ([delegate respondsToSelector:sel]) {
810 [delegate audioSessionDidBeginInterruption:self]; 830 [delegate audioSessionDidBeginInterruption:self];
811 } 831 }
812 } 832 }
813 } 833 }
814 834
815 - (void)notifyDidEndInterruptionWithShouldResumeSession: 835 - (void)notifyDidEndInterruptionWithShouldResumeSession:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 893
874 - (void)notifyDidStopPlayOrRecord { 894 - (void)notifyDidStopPlayOrRecord {
875 for (auto delegate : self.delegates) { 895 for (auto delegate : self.delegates) {
876 SEL sel = @selector(audioSessionDidStopPlayOrRecord:); 896 SEL sel = @selector(audioSessionDidStopPlayOrRecord:);
877 if ([delegate respondsToSelector:sel]) { 897 if ([delegate respondsToSelector:sel]) {
878 [delegate audioSessionDidStopPlayOrRecord:self]; 898 [delegate audioSessionDidStopPlayOrRecord:self];
879 } 899 }
880 } 900 }
881 } 901 }
882 902
903 - (void)notifyAudioVolumeDidChange:(NSNumber *)volume {
904 for (auto delegate : self.delegates) {
905 SEL sel = @selector(audioVolumeDidChange:);
906 if ([delegate respondsToSelector:sel]) {
907 [delegate audioVolumeDidChange:volume.floatValue];
908 }
909 }
910 }
911
883 @end 912 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698