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" | 13 #import "WebRTC/RTCDispatcher.h" |
14 | 14 |
15 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" | 15 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" |
16 #include "webrtc/modules/utility/include/helpers_ios.h" | |
tkchin_webrtc
2016/06/24 00:30:48
Let's avoid using this file. I want to move helper
| |
16 | 17 |
17 // Try to use mono to save resources. Also avoids channel format conversion | 18 // Try to use mono to save resources. Also avoids channel format conversion |
18 // in the I/O audio unit. Initial tests have shown that it is possible to use | 19 // in the I/O audio unit. Initial tests have shown that it is possible to use |
19 // mono natively for built-in microphones and for BT headsets but not for | 20 // mono natively for built-in microphones and for BT headsets but not for |
20 // wired headsets. Wired headsets only support stereo as native channel format | 21 // wired headsets. Wired headsets only support stereo as native channel format |
21 // but it is a low cost operation to do a format conversion to mono in the | 22 // but it is a low cost operation to do a format conversion to mono in the |
22 // audio unit. Hence, we will not hit a RTC_CHECK in | 23 // audio unit. Hence, we will not hit a RTC_CHECK in |
23 // VerifyAudioParametersForActiveAudioSession() for a mismatch between the | 24 // VerifyAudioParametersForActiveAudioSession() for a mismatch between the |
24 // preferred number of channels and the actual number of channels. | 25 // preferred number of channels and the actual number of channels. |
25 const int kRTCAudioSessionPreferredNumberOfChannels = 1; | 26 const int kRTCAudioSessionPreferredNumberOfChannels = 1; |
(...skipping 11 matching lines...) Expand all Loading... | |
37 // Use a hardware I/O buffer size (unit is in seconds) that matches the 10ms | 38 // Use a hardware I/O buffer size (unit is in seconds) that matches the 10ms |
38 // size used by WebRTC. The exact actual size will differ between devices. | 39 // size used by WebRTC. The exact actual size will differ between devices. |
39 // Example: using 48kHz on iPhone 6 results in a native buffer size of | 40 // Example: using 48kHz on iPhone 6 results in a native buffer size of |
40 // ~10.6667ms or 512 audio frames per buffer. The FineAudioBuffer instance will | 41 // ~10.6667ms or 512 audio frames per buffer. The FineAudioBuffer instance will |
41 // take care of any buffering required to convert between native buffers and | 42 // take care of any buffering required to convert between native buffers and |
42 // buffers used by WebRTC. It is beneficial for the performance if the native | 43 // buffers used by WebRTC. It is beneficial for the performance if the native |
43 // size is as close to 10ms as possible since it results in "clean" callback | 44 // size is as close to 10ms as possible since it results in "clean" callback |
44 // sequence without bursts of callbacks back to back. | 45 // sequence without bursts of callbacks back to back. |
45 const double kRTCAudioSessionHighPerformanceIOBufferDuration = 0.01; | 46 const double kRTCAudioSessionHighPerformanceIOBufferDuration = 0.01; |
46 | 47 |
48 // Use a larger buffer size on iphone 4S to allow it running complex tasks | |
49 // e.g., encoding large frames with Opus codec. | |
50 const double kRTCAudioSessionHighPerformanceIOBufferDurationIphone4s = 0.02; | |
51 | |
47 // Use a larger buffer size on devices with only one core (e.g. iPhone 4). | 52 // Use a larger buffer size on devices with only one core (e.g. iPhone 4). |
48 // It will result in a lower CPU consumption at the cost of a larger latency. | 53 // It will result in a lower CPU consumption at the cost of a larger latency. |
49 // The size of 60ms is based on instrumentation that shows a significant | 54 // The size of 60ms is based on instrumentation that shows a significant |
50 // reduction in CPU load compared with 10ms on low-end devices. | 55 // reduction in CPU load compared with 10ms on low-end devices. |
51 // TODO(henrika): monitor this size and determine if it should be modified. | 56 // TODO(henrika): monitor this size and determine if it should be modified. |
52 const double kRTCAudioSessionLowComplexityIOBufferDuration = 0.06; | 57 const double kRTCAudioSessionLowComplexityIOBufferDuration = 0.06; |
53 | 58 |
54 static RTCAudioSessionConfiguration *gWebRTCConfiguration = nil; | 59 static RTCAudioSessionConfiguration *gWebRTCConfiguration = nil; |
55 | 60 |
56 @implementation RTCAudioSessionConfiguration | 61 @implementation RTCAudioSessionConfiguration |
(...skipping 20 matching lines...) Expand all Loading... | |
77 | 82 |
78 // Set the session's sample rate or the hardware sample rate. | 83 // Set the session's sample rate or the hardware sample rate. |
79 // It is essential that we use the same sample rate as stream format | 84 // It is essential that we use the same sample rate as stream format |
80 // to ensure that the I/O unit does not have to do sample rate conversion. | 85 // to ensure that the I/O unit does not have to do sample rate conversion. |
81 // Set the preferred audio I/O buffer duration, in seconds. | 86 // Set the preferred audio I/O buffer duration, in seconds. |
82 NSUInteger processorCount = [NSProcessInfo processInfo].processorCount; | 87 NSUInteger processorCount = [NSProcessInfo processInfo].processorCount; |
83 // Use best sample rate and buffer duration if the CPU has more than one | 88 // Use best sample rate and buffer duration if the CPU has more than one |
84 // core. | 89 // core. |
85 if (processorCount > 1) { | 90 if (processorCount > 1) { |
86 _sampleRate = kRTCAudioSessionHighPerformanceSampleRate; | 91 _sampleRate = kRTCAudioSessionHighPerformanceSampleRate; |
87 _ioBufferDuration = kRTCAudioSessionHighPerformanceIOBufferDuration; | 92 if (webrtc::ios::GetDeviceName() == "iPhone 4S") { |
tkchin_webrtc
2016/06/24 00:30:48
Wouldn't use strings like this. We should enumerat
| |
93 _ioBufferDuration = | |
94 kRTCAudioSessionHighPerformanceIOBufferDurationIphone4s; | |
95 } else { | |
96 _ioBufferDuration = kRTCAudioSessionHighPerformanceIOBufferDuration; | |
97 } | |
88 } else { | 98 } else { |
89 _sampleRate = kRTCAudioSessionLowComplexitySampleRate; | 99 _sampleRate = kRTCAudioSessionLowComplexitySampleRate; |
90 _ioBufferDuration = kRTCAudioSessionLowComplexityIOBufferDuration; | 100 _ioBufferDuration = kRTCAudioSessionLowComplexityIOBufferDuration; |
91 } | 101 } |
92 | 102 |
93 // We try to use mono in both directions to save resources and format | 103 // We try to use mono in both directions to save resources and format |
94 // conversions in the audio unit. Some devices does only support stereo; | 104 // conversions in the audio unit. Some devices does only support stereo; |
95 // e.g. wired headset on iPhone 6. | 105 // e.g. wired headset on iPhone 6. |
96 // TODO(henrika): add support for stereo if needed. | 106 // TODO(henrika): add support for stereo if needed. |
97 _inputNumberOfChannels = kRTCAudioSessionPreferredNumberOfChannels; | 107 _inputNumberOfChannels = kRTCAudioSessionPreferredNumberOfChannels; |
(...skipping 26 matching lines...) Expand all Loading... | |
124 } | 134 } |
125 } | 135 } |
126 | 136 |
127 + (void)setWebRTCConfiguration:(RTCAudioSessionConfiguration *)configuration { | 137 + (void)setWebRTCConfiguration:(RTCAudioSessionConfiguration *)configuration { |
128 @synchronized(self) { | 138 @synchronized(self) { |
129 gWebRTCConfiguration = configuration; | 139 gWebRTCConfiguration = configuration; |
130 } | 140 } |
131 } | 141 } |
132 | 142 |
133 @end | 143 @end |
OLD | NEW |