You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #import "RTCNativeAudioSessionDelegateAdapter.h"
  11. #include "sdk/objc/native/src/audio/audio_session_observer.h"
  12. #import "base/RTCLogging.h"
  13. @implementation RTCNativeAudioSessionDelegateAdapter {
  14. webrtc::AudioSessionObserver *_observer;
  15. }
  16. - (instancetype)initWithObserver:(webrtc::AudioSessionObserver *)observer {
  17. RTC_DCHECK(observer);
  18. if (self = [super init]) {
  19. _observer = observer;
  20. }
  21. return self;
  22. }
  23. #pragma mark - RTCAudioSessionDelegate
  24. - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session {
  25. _observer->OnInterruptionBegin();
  26. }
  27. - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session
  28. shouldResumeSession:(BOOL)shouldResumeSession {
  29. _observer->OnInterruptionEnd();
  30. }
  31. - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session
  32. reason:(AVAudioSessionRouteChangeReason)reason
  33. previousRoute:(AVAudioSessionRouteDescription *)previousRoute {
  34. switch (reason) {
  35. case AVAudioSessionRouteChangeReasonUnknown:
  36. case AVAudioSessionRouteChangeReasonNewDeviceAvailable:
  37. case AVAudioSessionRouteChangeReasonOldDeviceUnavailable:
  38. case AVAudioSessionRouteChangeReasonCategoryChange:
  39. // It turns out that we see a category change (at least in iOS 9.2)
  40. // when making a switch from a BT device to e.g. Speaker using the
  41. // iOS Control Center and that we therefore must check if the sample
  42. // rate has changed. And if so is the case, restart the audio unit.
  43. case AVAudioSessionRouteChangeReasonOverride:
  44. case AVAudioSessionRouteChangeReasonWakeFromSleep:
  45. case AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory:
  46. _observer->OnValidRouteChange();
  47. break;
  48. case AVAudioSessionRouteChangeReasonRouteConfigurationChange:
  49. // The set of input and output ports has not changed, but their
  50. // configuration has, e.g., a port’s selected data source has
  51. // changed. Ignore this type of route change since we are focusing
  52. // on detecting headset changes.
  53. RTCLog(@"Ignoring RouteConfigurationChange");
  54. break;
  55. }
  56. }
  57. - (void)audioSessionMediaServerTerminated:(RTCAudioSession *)session {
  58. }
  59. - (void)audioSessionMediaServerReset:(RTCAudioSession *)session {
  60. }
  61. - (void)audioSession:(RTCAudioSession *)session
  62. didChangeCanPlayOrRecord:(BOOL)canPlayOrRecord {
  63. _observer->OnCanPlayOrRecordChange(canPlayOrRecord);
  64. }
  65. - (void)audioSessionDidStartPlayOrRecord:(RTCAudioSession *)session {
  66. }
  67. - (void)audioSessionDidStopPlayOrRecord:(RTCAudioSession *)session {
  68. }
  69. - (void)audioSession:(RTCAudioSession *)audioSession
  70. didChangeOutputVolume:(float)outputVolume {
  71. _observer->OnChangedOutputVolume();
  72. }
  73. @end