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 | |
88 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | |
89 // TODO(ihf): Remove this once ARM Chromebooks support low latency audio. For | |
90 // now we classify them as high latency. See crbug.com/289770. | |
dmichael (off chromium)
2013/09/13 20:44:46
This doesn't seem like the right place to fix this
| |
91 return CalculateMultipleOfSampleFrameCount( | |
92 sample_frame_count, kHighLatencySampleFrameCount); | |
dmichael (off chromium)
2013/09/13 21:15:56
should we copy the high latency section below and
ilja
2013/09/14 01:44:39
I followed the second approach and left a comment.
| |
93 #endif // defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | |
94 | |
84 // If client is using same sample rate as audio hardware, then recommend a | 95 // If client is using same sample rate as audio hardware, then recommend a |
85 // multiple of the audio hardware's sample frame count. | 96 // multiple of the audio hardware's sample frame count. |
86 if (hardware_sample_rate == sample_rate) { | 97 if (hardware_sample_rate == sample_rate) { |
87 return CalculateMultipleOfSampleFrameCount( | 98 return CalculateMultipleOfSampleFrameCount( |
88 hardware_sample_frame_count, sample_frame_count); | 99 hardware_sample_frame_count, sample_frame_count); |
89 } | 100 } |
90 | 101 |
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 | 102 // 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 | 103 // 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 | 104 // 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. | 105 // is 16kHz and a sample frame count greater than 160 frames. |
98 if (hardware_sample_frame_count >= kHighLatencySampleFrameCount || | 106 if (hardware_sample_frame_count >= kHighLatencySampleFrameCount || |
99 (hardware_sample_rate < 44100 && | 107 (hardware_sample_rate < 44100 && |
100 hardware_sample_frame_count > hardware_sample_rate / 100u)) { | 108 hardware_sample_frame_count > hardware_sample_rate / 100u)) { |
101 return CalculateMultipleOfSampleFrameCount( | 109 return CalculateMultipleOfSampleFrameCount( |
102 sample_frame_count, | 110 sample_frame_count, |
103 std::max(kHighLatencySampleFrameCount, hardware_sample_frame_count)); | 111 std::max(kHighLatencySampleFrameCount, hardware_sample_frame_count)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT || | 169 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT || |
162 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) | 170 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) |
163 return false; | 171 return false; |
164 | 172 |
165 sample_rate_ = sample_rate; | 173 sample_rate_ = sample_rate; |
166 sample_frame_count_ = sample_frame_count; | 174 sample_frame_count_ = sample_frame_count; |
167 return true; | 175 return true; |
168 } | 176 } |
169 | 177 |
170 } // namespace ppapi | 178 } // namespace ppapi |
OLD | NEW |