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 |
| 85 // Should track the value reported by XP and ALSA backends. |
| 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; |
| 93 #else |
| 94 const bool kHighLatencyDevice = false; |
| 95 #endif |
| 96 |
84 // If client is using same sample rate as audio hardware, then recommend a | 97 // If client is using same sample rate as audio hardware, then recommend a |
85 // multiple of the audio hardware's sample frame count. | 98 // multiple of the audio hardware's sample frame count. |
86 if (hardware_sample_rate == sample_rate) { | 99 if (!kHighLatencyDevice && hardware_sample_rate == sample_rate) { |
87 return CalculateMultipleOfSampleFrameCount( | 100 return CalculateMultipleOfSampleFrameCount( |
88 hardware_sample_frame_count, sample_frame_count); | 101 hardware_sample_frame_count, sample_frame_count); |
89 } | 102 } |
90 | 103 |
91 // Should track the value reported by XP and ALSA backends. | |
92 const uint32_t kHighLatencySampleFrameCount = 2048; | |
93 | |
94 // If the hardware requires a high latency buffer or we're at a low sample | 104 // 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 | 105 // 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 | 106 // 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. | 107 // is 16kHz and a sample frame count greater than 160 frames. |
98 if (hardware_sample_frame_count >= kHighLatencySampleFrameCount || | 108 if (kHighLatencyDevice || |
| 109 hardware_sample_frame_count >= kHighLatencySampleFrameCount || |
99 (hardware_sample_rate < 44100 && | 110 (hardware_sample_rate < 44100 && |
100 hardware_sample_frame_count > hardware_sample_rate / 100u)) { | 111 hardware_sample_frame_count > hardware_sample_rate / 100u)) { |
101 return CalculateMultipleOfSampleFrameCount( | 112 return CalculateMultipleOfSampleFrameCount( |
102 sample_frame_count, | 113 sample_frame_count, |
103 std::max(kHighLatencySampleFrameCount, hardware_sample_frame_count)); | 114 std::max(kHighLatencySampleFrameCount, hardware_sample_frame_count)); |
104 } | 115 } |
105 | 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 |
(...skipping 52 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 |