Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.m

Issue 2066993005: (OBSOLETE) Increasing audio buffer on Iphone 4S. Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <sys/utsname.h>
14
13 #import "WebRTC/RTCDispatcher.h" 15 #import "WebRTC/RTCDispatcher.h"
14 16
15 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" 17 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h"
16 18
17 // Try to use mono to save resources. Also avoids channel format conversion 19 // 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 20 // 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 21 // 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 22 // 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 23 // 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 24 // audio unit. Hence, we will not hit a RTC_CHECK in
(...skipping 14 matching lines...) Expand all
37 // Use a hardware I/O buffer size (unit is in seconds) that matches the 10ms 39 // 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. 40 // 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 41 // 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 42 // ~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 43 // 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 44 // 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 45 // size is as close to 10ms as possible since it results in "clean" callback
44 // sequence without bursts of callbacks back to back. 46 // sequence without bursts of callbacks back to back.
45 const double kRTCAudioSessionHighPerformanceIOBufferDuration = 0.01; 47 const double kRTCAudioSessionHighPerformanceIOBufferDuration = 0.01;
46 48
49 // Use a larger buffer size on iphone 4S to allow it running complex tasks
50 // e.g., encoding long frames with Opus codec.
henrika_webrtc 2016/06/17 07:37:37 nit, I would say large frames
minyue-webrtc 2016/06/23 11:35:07 Done.
51 NSString* const kIphone4sDeviceTyp = @"iPhone4,1";
52 const double kRTCAudioSessionHighPerformanceIOBufferDurationIphone4s = 0.02;
53
47 // Use a larger buffer size on devices with only one core (e.g. iPhone 4). 54 // 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. 55 // 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 56 // The size of 60ms is based on instrumentation that shows a significant
50 // reduction in CPU load compared with 10ms on low-end devices. 57 // reduction in CPU load compared with 10ms on low-end devices.
51 // TODO(henrika): monitor this size and determine if it should be modified. 58 // TODO(henrika): monitor this size and determine if it should be modified.
52 const double kRTCAudioSessionLowComplexityIOBufferDuration = 0.06; 59 const double kRTCAudioSessionLowComplexityIOBufferDuration = 0.06;
53 60
54 static RTCAudioSessionConfiguration *gWebRTCConfiguration = nil; 61 static RTCAudioSessionConfiguration *gWebRTCConfiguration = nil;
55 62
56 @implementation RTCAudioSessionConfiguration 63 @implementation RTCAudioSessionConfiguration
(...skipping 16 matching lines...) Expand all
73 _categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth; 80 _categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth;
74 81
75 // Specify mode for two-way voice communication (e.g. VoIP). 82 // Specify mode for two-way voice communication (e.g. VoIP).
76 _mode = AVAudioSessionModeVoiceChat; 83 _mode = AVAudioSessionModeVoiceChat;
77 84
78 // Set the session's sample rate or the hardware sample rate. 85 // 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 86 // 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. 87 // 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. 88 // Set the preferred audio I/O buffer duration, in seconds.
82 NSUInteger processorCount = [NSProcessInfo processInfo].processorCount; 89 NSUInteger processorCount = [NSProcessInfo processInfo].processorCount;
90
91 struct utsname systemInfo;
henrika_webrtc 2016/06/17 07:37:37 Please compare with existing methods in https://cs
minyue-webrtc 2016/06/23 11:35:07 Done.
92 uname(&systemInfo);
93 NSString *device_type = [NSString stringWithCString:systemInfo.machine
94 encoding:NSUTF8StringEncoding];
95
83 // Use best sample rate and buffer duration if the CPU has more than one 96 // Use best sample rate and buffer duration if the CPU has more than one
84 // core. 97 // core.
85 if (processorCount > 1) { 98 if (processorCount > 1) {
86 _sampleRate = kRTCAudioSessionHighPerformanceSampleRate; 99 _sampleRate = kRTCAudioSessionHighPerformanceSampleRate;
87 _ioBufferDuration = kRTCAudioSessionHighPerformanceIOBufferDuration; 100 if ([device_type isEqualToString:kIphone4sDeviceTyp]) {
101 _ioBufferDuration =
102 kRTCAudioSessionHighPerformanceIOBufferDurationIphone4s;
103 } else {
104 _ioBufferDuration = kRTCAudioSessionHighPerformanceIOBufferDuration;
105 }
88 } else { 106 } else {
89 _sampleRate = kRTCAudioSessionLowComplexitySampleRate; 107 _sampleRate = kRTCAudioSessionLowComplexitySampleRate;
90 _ioBufferDuration = kRTCAudioSessionLowComplexityIOBufferDuration; 108 _ioBufferDuration = kRTCAudioSessionLowComplexityIOBufferDuration;
91 } 109 }
92 110
93 // We try to use mono in both directions to save resources and format 111 // 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; 112 // conversions in the audio unit. Some devices does only support stereo;
95 // e.g. wired headset on iPhone 6. 113 // e.g. wired headset on iPhone 6.
96 // TODO(henrika): add support for stereo if needed. 114 // TODO(henrika): add support for stereo if needed.
97 _inputNumberOfChannels = kRTCAudioSessionPreferredNumberOfChannels; 115 _inputNumberOfChannels = kRTCAudioSessionPreferredNumberOfChannels;
(...skipping 26 matching lines...) Expand all
124 } 142 }
125 } 143 }
126 144
127 + (void)setWebRTCConfiguration:(RTCAudioSessionConfiguration *)configuration { 145 + (void)setWebRTCConfiguration:(RTCAudioSessionConfiguration *)configuration {
128 @synchronized(self) { 146 @synchronized(self) {
129 gWebRTCConfiguration = configuration; 147 gWebRTCConfiguration = configuration;
130 } 148 }
131 } 149 }
132 150
133 @end 151 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698