Chromium Code Reviews| 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 init: (%p)", self); | |
|
tkchin_webrtc
2017/03/29 20:02:51
nit: "RTCAudioSession (%p): init"
(usually ptr val
Chuck
2017/03/29 20:29:18
Done.
| |
| 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 dealloc: (%p)", 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 { |
| 544 if (self.isInterrupted) { | 548 if (self.isInterrupted) { |
| 545 RTCLog(@"Application became active after an interruption. Treating as interr uption end."); | 549 RTCLog(@"Application became active after an interruption. Treating as interr uption end."); |
| 546 self.isInterrupted = NO; | 550 self.isInterrupted = NO; |
| 547 [self updateAudioSessionAfterEvent]; | 551 [self updateAudioSessionAfterEvent]; |
| 548 [self notifyDidEndInterruptionWithShouldResumeSession:YES]; | |
| 549 } | 552 } |
| 553 // Always treat application becoming active as an interruption end event. | |
| 554 [self notifyDidEndInterruptionWithShouldResumeSession:YES]; | |
|
tkchin_webrtc
2017/03/29 20:02:51
Hm. I don't recall the details here - but can you
Chuck
2017/03/29 20:29:18
Modified the logging here so it always logs someth
| |
| 550 } | 555 } |
| 551 | 556 |
| 552 #pragma mark - Private | 557 #pragma mark - Private |
| 553 | 558 |
| 554 + (NSError *)lockError { | 559 + (NSError *)lockError { |
| 555 NSDictionary *userInfo = @{ | 560 NSDictionary *userInfo = @{ |
| 556 NSLocalizedDescriptionKey: | 561 NSLocalizedDescriptionKey: |
| 557 @"Must call lockForConfiguration before calling this method." | 562 @"Must call lockForConfiguration before calling this method." |
| 558 }; | 563 }; |
| 559 NSError *error = | 564 NSError *error = |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 847 - (void)notifyDidStopPlayOrRecord { | 852 - (void)notifyDidStopPlayOrRecord { |
| 848 for (auto delegate : self.delegates) { | 853 for (auto delegate : self.delegates) { |
| 849 SEL sel = @selector(audioSessionDidStopPlayOrRecord:); | 854 SEL sel = @selector(audioSessionDidStopPlayOrRecord:); |
| 850 if ([delegate respondsToSelector:sel]) { | 855 if ([delegate respondsToSelector:sel]) { |
| 851 [delegate audioSessionDidStopPlayOrRecord:self]; | 856 [delegate audioSessionDidStopPlayOrRecord:self]; |
| 852 } | 857 } |
| 853 } | 858 } |
| 854 } | 859 } |
| 855 | 860 |
| 856 @end | 861 @end |
| OLD | NEW |