• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 *  Copyright 2018 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 "RTCNativeAudioSessionDelegateAdapter.h"
12
13#include "sdk/objc/native/src/audio/audio_session_observer.h"
14
15#import "base/RTCLogging.h"
16
17@implementation RTCNativeAudioSessionDelegateAdapter {
18  webrtc::AudioSessionObserver *_observer;
19}
20
21- (instancetype)initWithObserver:(webrtc::AudioSessionObserver *)observer {
22  RTC_DCHECK(observer);
23  if (self = [super init]) {
24    _observer = observer;
25  }
26  return self;
27}
28
29#pragma mark - RTC_OBJC_TYPE(RTCAudioSessionDelegate)
30
31- (void)audioSessionDidBeginInterruption:(RTC_OBJC_TYPE(RTCAudioSession) *)session {
32  _observer->OnInterruptionBegin();
33}
34
35- (void)audioSessionDidEndInterruption:(RTC_OBJC_TYPE(RTCAudioSession) *)session
36                   shouldResumeSession:(BOOL)shouldResumeSession {
37  _observer->OnInterruptionEnd();
38}
39
40- (void)audioSessionDidChangeRoute:(RTC_OBJC_TYPE(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
67- (void)audioSessionMediaServerTerminated:(RTC_OBJC_TYPE(RTCAudioSession) *)session {
68}
69
70- (void)audioSessionMediaServerReset:(RTC_OBJC_TYPE(RTCAudioSession) *)session {
71}
72
73- (void)audioSession:(RTC_OBJC_TYPE(RTCAudioSession) *)session
74    didChangeCanPlayOrRecord:(BOOL)canPlayOrRecord {
75  _observer->OnCanPlayOrRecordChange(canPlayOrRecord);
76}
77
78- (void)audioSessionDidStartPlayOrRecord:(RTC_OBJC_TYPE(RTCAudioSession) *)session {
79}
80
81- (void)audioSessionDidStopPlayOrRecord:(RTC_OBJC_TYPE(RTCAudioSession) *)session {
82}
83
84- (void)audioSession:(RTC_OBJC_TYPE(RTCAudioSession) *)audioSession
85    didChangeOutputVolume:(float)outputVolume {
86  _observer->OnChangedOutputVolume();
87}
88
89@end
90