OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionDelegateAdapter.h" |
| 12 |
| 13 #include "webrtc/base/asyncinvoker.h" |
| 14 #include "webrtc/base/bind.h" |
| 15 #include "webrtc/base/thread.h" |
| 16 #include "webrtc/modules/audio_device/ios/audio_device_ios.h" |
| 17 |
| 18 #import "webrtc/base/objc/RTCLogging.h" |
| 19 |
| 20 @implementation RTCAudioSessionDelegateAdapter { |
| 21 webrtc::AudioDeviceIOS *_device; |
| 22 rtc::Thread *_callbackThread; |
| 23 std::unique_ptr<rtc::AsyncInvoker> _asyncInvoker; |
| 24 } |
| 25 |
| 26 - (instancetype)initWithAudioDevice:(webrtc::AudioDeviceIOS *)device |
| 27 callbackThread:(rtc::Thread *)callbackThread { |
| 28 NSParameterAssert(device); |
| 29 NSParameterAssert(callbackThread); |
| 30 if (self = [super init]) { |
| 31 _device = device; |
| 32 _callbackThread = callbackThread; |
| 33 _asyncInvoker.reset(new rtc::AsyncInvoker()); |
| 34 } |
| 35 return self; |
| 36 } |
| 37 |
| 38 #pragma mark - RTCAudioSessionDelegate |
| 39 |
| 40 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session { |
| 41 _asyncInvoker->AsyncInvoke<void>( |
| 42 _callbackThread, |
| 43 rtc::Bind(&webrtc::AudioDeviceIOS::OnInterruptionBegin, _device)); |
| 44 } |
| 45 |
| 46 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session |
| 47 shouldResumeSession:(BOOL)shouldResumeSession { |
| 48 _asyncInvoker->AsyncInvoke<void>( |
| 49 _callbackThread, |
| 50 rtc::Bind(&webrtc::AudioDeviceIOS::OnInterruptionEnd, _device)); |
| 51 } |
| 52 |
| 53 - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session |
| 54 reason:(AVAudioSessionRouteChangeReason)reason |
| 55 previousRoute:(AVAudioSessionRouteDescription *)previousRoute { |
| 56 switch (reason) { |
| 57 case AVAudioSessionRouteChangeReasonUnknown: |
| 58 case AVAudioSessionRouteChangeReasonNewDeviceAvailable: |
| 59 case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: |
| 60 case AVAudioSessionRouteChangeReasonCategoryChange: |
| 61 // It turns out that we see a category change (at least in iOS 9.2) |
| 62 // when making a switch from a BT device to e.g. Speaker using the |
| 63 // iOS Control Center and that we therefore must check if the sample |
| 64 // rate has changed. And if so is the case, restart the audio unit. |
| 65 case AVAudioSessionRouteChangeReasonOverride: |
| 66 case AVAudioSessionRouteChangeReasonWakeFromSleep: |
| 67 case AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory: |
| 68 _asyncInvoker->AsyncInvoke<void>( |
| 69 _callbackThread, |
| 70 rtc::Bind(&webrtc::AudioDeviceIOS::OnValidRouteChange, _device)); |
| 71 break; |
| 72 case AVAudioSessionRouteChangeReasonRouteConfigurationChange: |
| 73 // The set of input and output ports has not changed, but their |
| 74 // configuration has, e.g., a port’s selected data source has |
| 75 // changed. Ignore this type of route change since we are focusing |
| 76 // on detecting headset changes. |
| 77 RTCLog(@"Ignoring RouteConfigurationChange"); |
| 78 break; |
| 79 } |
| 80 } |
| 81 |
| 82 - (void)audioSessionMediaServicesWereLost:(RTCAudioSession *)session { |
| 83 } |
| 84 |
| 85 - (void)audioSessionMediaServicesWereReset:(RTCAudioSession *)session { |
| 86 } |
| 87 |
| 88 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session { |
| 89 } |
| 90 |
| 91 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session { |
| 92 } |
| 93 |
| 94 @end |
OLD | NEW |