OLD | NEW |
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 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // hint to enable or disable audio that is secondary. | 79 // hint to enable or disable audio that is secondary. |
80 [center addObserver:self | 80 [center addObserver:self |
81 selector:@selector(handleSilenceSecondaryAudioHintNotification:) | 81 selector:@selector(handleSilenceSecondaryAudioHintNotification:) |
82 name:AVAudioSessionSilenceSecondaryAudioHintNotification | 82 name:AVAudioSessionSilenceSecondaryAudioHintNotification |
83 object:nil]; | 83 object:nil]; |
84 // Also track foreground event in order to deal with interruption ended situ
ation. | 84 // Also track foreground event in order to deal with interruption ended situ
ation. |
85 [center addObserver:self | 85 [center addObserver:self |
86 selector:@selector(handleApplicationDidBecomeActive:) | 86 selector:@selector(handleApplicationDidBecomeActive:) |
87 name:UIApplicationDidBecomeActiveNotification | 87 name:UIApplicationDidBecomeActiveNotification |
88 object:nil]; | 88 object:nil]; |
| 89 RTCLog(@"RTCAudioSession (%p): init.", self); |
89 } | 90 } |
90 return self; | 91 return self; |
91 } | 92 } |
92 | 93 |
93 - (void)dealloc { | 94 - (void)dealloc { |
94 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 95 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 96 RTCLog(@"RTCAudioSession (%p): dealloc.", self); |
95 } | 97 } |
96 | 98 |
97 - (NSString *)description { | 99 - (NSString *)description { |
98 NSString *format = | 100 NSString *format = |
99 @"RTCAudioSession: {\n" | 101 @"RTCAudioSession: {\n" |
100 " category: %@\n" | 102 " category: %@\n" |
101 " categoryOptions: %ld\n" | 103 " categoryOptions: %ld\n" |
102 " mode: %@\n" | 104 " mode: %@\n" |
103 " isActive: %d\n" | 105 " isActive: %d\n" |
104 " sampleRate: %.2f\n" | 106 " sampleRate: %.2f\n" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 162 } |
161 | 163 |
162 - (BOOL)isAudioEnabled { | 164 - (BOOL)isAudioEnabled { |
163 @synchronized(self) { | 165 @synchronized(self) { |
164 return _isAudioEnabled; | 166 return _isAudioEnabled; |
165 } | 167 } |
166 } | 168 } |
167 | 169 |
168 // TODO(tkchin): Check for duplicates. | 170 // TODO(tkchin): Check for duplicates. |
169 - (void)addDelegate:(id<RTCAudioSessionDelegate>)delegate { | 171 - (void)addDelegate:(id<RTCAudioSessionDelegate>)delegate { |
| 172 RTCLog(@"Adding delegate: (%p)", delegate); |
170 if (!delegate) { | 173 if (!delegate) { |
171 return; | 174 return; |
172 } | 175 } |
173 @synchronized(self) { | 176 @synchronized(self) { |
174 _delegates.push_back(delegate); | 177 _delegates.push_back(delegate); |
175 [self removeZeroedDelegates]; | 178 [self removeZeroedDelegates]; |
176 } | 179 } |
177 } | 180 } |
178 | 181 |
179 - (void)removeDelegate:(id<RTCAudioSessionDelegate>)delegate { | 182 - (void)removeDelegate:(id<RTCAudioSessionDelegate>)delegate { |
| 183 RTCLog(@"Removing delegate: (%p)", delegate); |
180 if (!delegate) { | 184 if (!delegate) { |
181 return; | 185 return; |
182 } | 186 } |
183 @synchronized(self) { | 187 @synchronized(self) { |
184 _delegates.erase(std::remove(_delegates.begin(), | 188 _delegates.erase(std::remove(_delegates.begin(), |
185 _delegates.end(), | 189 _delegates.end(), |
186 delegate), | 190 delegate), |
187 _delegates.end()); | 191 _delegates.end()); |
188 [self removeZeroedDelegates]; | 192 [self removeZeroedDelegates]; |
189 } | 193 } |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 case AVAudioSessionSilenceSecondaryAudioHintTypeBegin: | 538 case AVAudioSessionSilenceSecondaryAudioHintTypeBegin: |
535 RTCLog(@"Another application's primary audio has started."); | 539 RTCLog(@"Another application's primary audio has started."); |
536 break; | 540 break; |
537 case AVAudioSessionSilenceSecondaryAudioHintTypeEnd: | 541 case AVAudioSessionSilenceSecondaryAudioHintTypeEnd: |
538 RTCLog(@"Another application's primary audio has stopped."); | 542 RTCLog(@"Another application's primary audio has stopped."); |
539 break; | 543 break; |
540 } | 544 } |
541 } | 545 } |
542 | 546 |
543 - (void)handleApplicationDidBecomeActive:(NSNotification *)notification { | 547 - (void)handleApplicationDidBecomeActive:(NSNotification *)notification { |
| 548 RTCLog(@"Application became active after an interruption. Treating as interrup
tion " |
| 549 " end. isInterrupted changed from %d to 0.", self.isInterrupted); |
544 if (self.isInterrupted) { | 550 if (self.isInterrupted) { |
545 RTCLog(@"Application became active after an interruption. Treating as interr
uption end."); | |
546 self.isInterrupted = NO; | 551 self.isInterrupted = NO; |
547 [self updateAudioSessionAfterEvent]; | 552 [self updateAudioSessionAfterEvent]; |
548 [self notifyDidEndInterruptionWithShouldResumeSession:YES]; | |
549 } | 553 } |
| 554 // Always treat application becoming active as an interruption end event. |
| 555 [self notifyDidEndInterruptionWithShouldResumeSession:YES]; |
550 } | 556 } |
551 | 557 |
552 #pragma mark - Private | 558 #pragma mark - Private |
553 | 559 |
554 + (NSError *)lockError { | 560 + (NSError *)lockError { |
555 NSDictionary *userInfo = @{ | 561 NSDictionary *userInfo = @{ |
556 NSLocalizedDescriptionKey: | 562 NSLocalizedDescriptionKey: |
557 @"Must call lockForConfiguration before calling this method." | 563 @"Must call lockForConfiguration before calling this method." |
558 }; | 564 }; |
559 NSError *error = | 565 NSError *error = |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 - (void)notifyDidStopPlayOrRecord { | 853 - (void)notifyDidStopPlayOrRecord { |
848 for (auto delegate : self.delegates) { | 854 for (auto delegate : self.delegates) { |
849 SEL sel = @selector(audioSessionDidStopPlayOrRecord:); | 855 SEL sel = @selector(audioSessionDidStopPlayOrRecord:); |
850 if ([delegate respondsToSelector:sel]) { | 856 if ([delegate respondsToSelector:sel]) { |
851 [delegate audioSessionDidStopPlayOrRecord:self]; | 857 [delegate audioSessionDidStopPlayOrRecord:self]; |
852 } | 858 } |
853 } | 859 } |
854 } | 860 } |
855 | 861 |
856 @end | 862 @end |
OLD | NEW |