OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | |
5 #include "ppapi/shared_impl/ppb_audio_config_shared.h" | 6 #include "ppapi/shared_impl/ppb_audio_config_shared.h" |
6 #include "ppapi/thunk/enter.h" | 7 #include "ppapi/thunk/enter.h" |
7 #include "ppapi/thunk/ppb_instance_api.h" | 8 #include "ppapi/thunk/ppb_instance_api.h" |
8 | 9 |
9 namespace ppapi { | 10 namespace ppapi { |
10 | 11 |
11 // Rounds up requested_size to the nearest multiple of minimum_size. | 12 // Rounds up requested_size to the nearest multiple of minimum_size. |
12 static uint32_t CalculateMultipleOfSampleFrameCount(uint32_t minimum_size, | 13 static uint32_t CalculateMultipleOfSampleFrameCount(uint32_t minimum_size, |
13 uint32_t requested_size) { | 14 uint32_t requested_size) { |
14 const uint32_t multiple = (requested_size + minimum_size - 1) / minimum_size; | 15 const uint32_t multiple = (requested_size + minimum_size - 1) / minimum_size; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 // output stream on the browser side, so we can use whatever sample count the | 75 // output stream on the browser side, so we can use whatever sample count the |
75 // client wants. | 76 // client wants. |
76 if (!hardware_sample_frame_count || !hardware_sample_rate) | 77 if (!hardware_sample_frame_count || !hardware_sample_rate) |
77 return sample_frame_count; | 78 return sample_frame_count; |
78 | 79 |
79 // Note: All the values below were determined through experimentation to | 80 // Note: All the values below were determined through experimentation to |
80 // minimize jitter and back-to-back callbacks from the browser. Please take | 81 // minimize jitter and back-to-back callbacks from the browser. Please take |
81 // care when modifying these values as they impact a large number of users. | 82 // care when modifying these values as they impact a large number of users. |
82 // TODO(dalecurtis): Land jitter test and add documentation for updating this. | 83 // TODO(dalecurtis): Land jitter test and add documentation for updating this. |
83 | 84 |
84 // If client is using same sample rate as audio hardware, then recommend a | |
85 // multiple of the audio hardware's sample frame count. | |
86 if (hardware_sample_rate == sample_rate) { | |
87 return CalculateMultipleOfSampleFrameCount( | |
88 hardware_sample_frame_count, sample_frame_count); | |
89 } | |
90 | |
91 // Should track the value reported by XP and ALSA backends. | 85 // Should track the value reported by XP and ALSA backends. |
92 const uint32_t kHighLatencySampleFrameCount = 2048; | 86 const uint32_t kHighLatencySampleFrameCount = 2048; |
87 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | |
88 // TODO(ihf): Remove this once ARM Chromebooks support low latency audio. For | |
89 // now we classify them as high latency. See crbug.com/289770. Note that | |
90 // Adobe Flash is affected but not HTML5, WebRTC and WebAudio (they are using | |
91 // real time threads). | |
92 const bool kHighLatencyDevice = true; | |
DaleCurtis
2013/09/16 16:27:46
indent is wrong.
ilja
2013/09/16 19:15:33
Done.
| |
93 #else | |
94 const bool kHighLatencyDevice = false; | |
95 #endif | |
93 | 96 |
94 // If the hardware requires a high latency buffer or we're at a low sample | 97 // If the hardware requires a high latency buffer or we're at a low sample |
95 // rate w/ a buffer that's larger than 10ms, choose the nearest multiple of | 98 // rate w/ a buffer that's larger than 10ms, choose the nearest multiple of |
96 // the high latency sample frame count. An example of too low and too large | 99 // the high latency sample frame count. An example of too low and too large |
97 // is 16kHz and a sample frame count greater than 160 frames. | 100 // is 16kHz and a sample frame count greater than 160 frames. |
98 if (hardware_sample_frame_count >= kHighLatencySampleFrameCount || | 101 if (kHighLatencyDevice || |
102 hardware_sample_frame_count >= kHighLatencySampleFrameCount || | |
99 (hardware_sample_rate < 44100 && | 103 (hardware_sample_rate < 44100 && |
100 hardware_sample_frame_count > hardware_sample_rate / 100u)) { | 104 hardware_sample_frame_count > hardware_sample_rate / 100u)) { |
101 return CalculateMultipleOfSampleFrameCount( | 105 return CalculateMultipleOfSampleFrameCount( |
102 sample_frame_count, | 106 sample_frame_count, |
103 std::max(kHighLatencySampleFrameCount, hardware_sample_frame_count)); | 107 std::max(kHighLatencySampleFrameCount, hardware_sample_frame_count)); |
104 } | 108 } |
105 | 109 |
110 // If client is using same sample rate as audio hardware, then recommend a | |
DaleCurtis
2013/09/16 16:27:46
This will result in a larger than necessary buffer
ilja
2013/09/16 19:15:33
Thanks for clarifying!
| |
111 // multiple of the audio hardware's sample frame count. | |
112 if (hardware_sample_rate == sample_rate) { | |
113 return CalculateMultipleOfSampleFrameCount( | |
114 hardware_sample_frame_count, sample_frame_count); | |
115 } | |
116 | |
106 // All low latency clients should be able to handle a 512 frame buffer with | 117 // All low latency clients should be able to handle a 512 frame buffer with |
107 // resampling from 44.1kHz and 48kHz to higher sample rates. | 118 // resampling from 44.1kHz and 48kHz to higher sample rates. |
108 // TODO(dalecurtis): We may need to investigate making the callback thread | 119 // TODO(dalecurtis): We may need to investigate making the callback thread |
109 // high priority to handle buffers at the absolute minimum w/o glitching. | 120 // high priority to handle buffers at the absolute minimum w/o glitching. |
110 const uint32_t kLowLatencySampleFrameCount = 512; | 121 const uint32_t kLowLatencySampleFrameCount = 512; |
111 | 122 |
112 // Special case for 48kHz -> 44.1kHz and buffer sizes greater than 10ms. In | 123 // Special case for 48kHz -> 44.1kHz and buffer sizes greater than 10ms. In |
113 // testing most buffer sizes > 10ms led to glitching, so we choose a size we | 124 // testing most buffer sizes > 10ms led to glitching, so we choose a size we |
114 // know won't cause jitter. | 125 // know won't cause jitter. |
115 int min_sample_frame_count = kLowLatencySampleFrameCount; | 126 int min_sample_frame_count = kLowLatencySampleFrameCount; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT || | 172 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT || |
162 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) | 173 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) |
163 return false; | 174 return false; |
164 | 175 |
165 sample_rate_ = sample_rate; | 176 sample_rate_ = sample_rate; |
166 sample_frame_count_ = sample_frame_count; | 177 sample_frame_count_ = sample_frame_count; |
167 return true; | 178 return true; |
168 } | 179 } |
169 | 180 |
170 } // namespace ppapi | 181 } // namespace ppapi |
OLD | NEW |