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 |
11 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h" | 11 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h" |
12 | 12 |
| 13 #import "WebRTC/RTCDispatcher.h" |
| 14 |
13 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" | 15 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" |
14 | 16 |
15 // Try to use mono to save resources. Also avoids channel format conversion | 17 // Try to use mono to save resources. Also avoids channel format conversion |
16 // in the I/O audio unit. Initial tests have shown that it is possible to use | 18 // in the I/O audio unit. Initial tests have shown that it is possible to use |
17 // mono natively for built-in microphones and for BT headsets but not for | 19 // mono natively for built-in microphones and for BT headsets but not for |
18 // wired headsets. Wired headsets only support stereo as native channel format | 20 // wired headsets. Wired headsets only support stereo as native channel format |
19 // but it is a low cost operation to do a format conversion to mono in the | 21 // but it is a low cost operation to do a format conversion to mono in the |
20 // audio unit. Hence, we will not hit a RTC_CHECK in | 22 // audio unit. Hence, we will not hit a RTC_CHECK in |
21 // VerifyAudioParametersForActiveAudioSession() for a mismatch between the | 23 // VerifyAudioParametersForActiveAudioSession() for a mismatch between the |
22 // preferred number of channels and the actual number of channels. | 24 // preferred number of channels and the actual number of channels. |
(...skipping 19 matching lines...) Expand all Loading... |
42 // sequence without bursts of callbacks back to back. | 44 // sequence without bursts of callbacks back to back. |
43 const double kRTCAudioSessionHighPerformanceIOBufferDuration = 0.01; | 45 const double kRTCAudioSessionHighPerformanceIOBufferDuration = 0.01; |
44 | 46 |
45 // Use a larger buffer size on devices with only one core (e.g. iPhone 4). | 47 // Use a larger buffer size on devices with only one core (e.g. iPhone 4). |
46 // It will result in a lower CPU consumption at the cost of a larger latency. | 48 // It will result in a lower CPU consumption at the cost of a larger latency. |
47 // The size of 60ms is based on instrumentation that shows a significant | 49 // The size of 60ms is based on instrumentation that shows a significant |
48 // reduction in CPU load compared with 10ms on low-end devices. | 50 // reduction in CPU load compared with 10ms on low-end devices. |
49 // TODO(henrika): monitor this size and determine if it should be modified. | 51 // TODO(henrika): monitor this size and determine if it should be modified. |
50 const double kRTCAudioSessionLowComplexityIOBufferDuration = 0.06; | 52 const double kRTCAudioSessionLowComplexityIOBufferDuration = 0.06; |
51 | 53 |
| 54 static RTCAudioSessionConfiguration *gWebRTCConfiguration = nil; |
| 55 |
52 @implementation RTCAudioSessionConfiguration | 56 @implementation RTCAudioSessionConfiguration |
53 | 57 |
54 @synthesize category = _category; | 58 @synthesize category = _category; |
55 @synthesize categoryOptions = _categoryOptions; | 59 @synthesize categoryOptions = _categoryOptions; |
56 @synthesize mode = _mode; | 60 @synthesize mode = _mode; |
57 @synthesize sampleRate = _sampleRate; | 61 @synthesize sampleRate = _sampleRate; |
58 @synthesize ioBufferDuration = _ioBufferDuration; | 62 @synthesize ioBufferDuration = _ioBufferDuration; |
59 @synthesize inputNumberOfChannels = _inputNumberOfChannels; | 63 @synthesize inputNumberOfChannels = _inputNumberOfChannels; |
60 @synthesize outputNumberOfChannels = _outputNumberOfChannels; | 64 @synthesize outputNumberOfChannels = _outputNumberOfChannels; |
61 | 65 |
(...skipping 27 matching lines...) Expand all Loading... |
89 // We try to use mono in both directions to save resources and format | 93 // We try to use mono in both directions to save resources and format |
90 // conversions in the audio unit. Some devices does only support stereo; | 94 // conversions in the audio unit. Some devices does only support stereo; |
91 // e.g. wired headset on iPhone 6. | 95 // e.g. wired headset on iPhone 6. |
92 // TODO(henrika): add support for stereo if needed. | 96 // TODO(henrika): add support for stereo if needed. |
93 _inputNumberOfChannels = kRTCAudioSessionPreferredNumberOfChannels; | 97 _inputNumberOfChannels = kRTCAudioSessionPreferredNumberOfChannels; |
94 _outputNumberOfChannels = kRTCAudioSessionPreferredNumberOfChannels; | 98 _outputNumberOfChannels = kRTCAudioSessionPreferredNumberOfChannels; |
95 } | 99 } |
96 return self; | 100 return self; |
97 } | 101 } |
98 | 102 |
| 103 + (void)initialize { |
| 104 gWebRTCConfiguration = [[self alloc] init]; |
| 105 } |
| 106 |
99 + (instancetype)currentConfiguration { | 107 + (instancetype)currentConfiguration { |
100 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 108 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
101 RTCAudioSessionConfiguration *config = | 109 RTCAudioSessionConfiguration *config = |
102 [[RTCAudioSessionConfiguration alloc] init]; | 110 [[RTCAudioSessionConfiguration alloc] init]; |
103 config.category = session.category; | 111 config.category = session.category; |
104 config.categoryOptions = session.categoryOptions; | 112 config.categoryOptions = session.categoryOptions; |
105 config.mode = session.mode; | 113 config.mode = session.mode; |
106 config.sampleRate = session.sampleRate; | 114 config.sampleRate = session.sampleRate; |
107 config.ioBufferDuration = session.IOBufferDuration; | 115 config.ioBufferDuration = session.IOBufferDuration; |
108 config.inputNumberOfChannels = session.inputNumberOfChannels; | 116 config.inputNumberOfChannels = session.inputNumberOfChannels; |
109 config.outputNumberOfChannels = session.outputNumberOfChannels; | 117 config.outputNumberOfChannels = session.outputNumberOfChannels; |
110 return config; | 118 return config; |
111 } | 119 } |
112 | 120 |
113 + (instancetype)webRTCConfiguration { | 121 + (instancetype)webRTCConfiguration { |
114 return [[self alloc] init]; | 122 @synchronized(self) { |
| 123 return (RTCAudioSessionConfiguration *)gWebRTCConfiguration; |
| 124 } |
| 125 } |
| 126 |
| 127 + (void)setWebRTCConfiguration:(RTCAudioSessionConfiguration *)configuration { |
| 128 @synchronized(self) { |
| 129 gWebRTCConfiguration = configuration; |
| 130 } |
115 } | 131 } |
116 | 132 |
117 @end | 133 @end |
OLD | NEW |