blob: ee142d7371802e79b1ce55ddd08317ddf1b2ec8d [file] [log] [blame]
tkchine54467f2016-03-15 16:54:03 -07001/*
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/modules/audio_device/ios/audio_session_observer.h"
14
tkchin9eeb6242016-04-27 01:54:20 -070015#import "WebRTC/RTCLogging.h"
tkchine54467f2016-03-15 16:54:03 -070016
17@implementation RTCAudioSessionDelegateAdapter {
18 webrtc::AudioSessionObserver *_observer;
19}
20
21- (instancetype)initWithObserver:(webrtc::AudioSessionObserver *)observer {
22 NSParameterAssert(observer);
23 if (self = [super init]) {
24 _observer = observer;
25 }
26 return self;
27}
28
29#pragma mark - RTCAudioSessionDelegate
30
31- (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session {
32 _observer->OnInterruptionBegin();
33}
34
35- (void)audioSessionDidEndInterruption:(RTCAudioSession *)session
36 shouldResumeSession:(BOOL)shouldResumeSession {
37 _observer->OnInterruptionEnd();
38}
39
40- (void)audioSessionDidChangeRoute:(RTCAudioSession *)session
41 reason:(AVAudioSessionRouteChangeReason)reason
42 previousRoute:(AVAudioSessionRouteDescription *)previousRoute {
43 switch (reason) {
44 case AVAudioSessionRouteChangeReasonUnknown:
45 case AVAudioSessionRouteChangeReasonNewDeviceAvailable:
46 case AVAudioSessionRouteChangeReasonOldDeviceUnavailable:
47 case AVAudioSessionRouteChangeReasonCategoryChange:
48 // It turns out that we see a category change (at least in iOS 9.2)
49 // when making a switch from a BT device to e.g. Speaker using the
50 // iOS Control Center and that we therefore must check if the sample
51 // rate has changed. And if so is the case, restart the audio unit.
52 case AVAudioSessionRouteChangeReasonOverride:
53 case AVAudioSessionRouteChangeReasonWakeFromSleep:
54 case AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory:
55 _observer->OnValidRouteChange();
56 break;
57 case AVAudioSessionRouteChangeReasonRouteConfigurationChange:
58 // The set of input and output ports has not changed, but their
59 // configuration has, e.g., a port’s selected data source has
60 // changed. Ignore this type of route change since we are focusing
61 // on detecting headset changes.
62 RTCLog(@"Ignoring RouteConfigurationChange");
63 break;
64 }
65}
66
kthelgason1634e162017-02-07 02:48:55 -080067- (void)audioSessionMediaServerTerminated:(RTCAudioSession *)session {
tkchine54467f2016-03-15 16:54:03 -070068}
69
kthelgason1634e162017-02-07 02:48:55 -080070- (void)audioSessionMediaServerReset:(RTCAudioSession *)session {
tkchine54467f2016-03-15 16:54:03 -070071}
72
tkchind2511962016-05-06 18:54:15 -070073- (void)audioSession:(RTCAudioSession *)session
74 didChangeCanPlayOrRecord:(BOOL)canPlayOrRecord {
75 _observer->OnCanPlayOrRecordChange(canPlayOrRecord);
tkchine54467f2016-03-15 16:54:03 -070076}
77
tkchind2511962016-05-06 18:54:15 -070078- (void)audioSessionDidStartPlayOrRecord:(RTCAudioSession *)session {
tkchine54467f2016-03-15 16:54:03 -070079}
80
tkchind2511962016-05-06 18:54:15 -070081- (void)audioSessionDidStopPlayOrRecord:(RTCAudioSession *)session {
Tze Kwang Chin307a0922016-03-21 13:57:40 -070082}
83
tkchine54467f2016-03-15 16:54:03 -070084@end