| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "media/base/audio_hardware_config.h" | 5 #include "media/base/audio_hardware_config.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 void AudioHardwareConfig::UpdateOutputConfig( | 94 void AudioHardwareConfig::UpdateOutputConfig( |
| 95 const AudioParameters& output_params) { | 95 const AudioParameters& output_params) { |
| 96 AutoLock auto_lock(config_lock_); | 96 AutoLock auto_lock(config_lock_); |
| 97 output_params_ = output_params; | 97 output_params_ = output_params; |
| 98 } | 98 } |
| 99 | 99 |
| 100 int AudioHardwareConfig::GetHighLatencyBufferSize() const { | 100 int AudioHardwareConfig::GetHighLatencyBufferSize() const { |
| 101 AutoLock auto_lock(config_lock_); | 101 AutoLock auto_lock(config_lock_); |
| 102 #if defined(OS_LINUX) | 102 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 103 // Empirically, use the nearest higher power of two buffer size corresponding | 103 // Empirically, use the nearest higher power of two buffer size corresponding |
| 104 // to 20 ms worth of samples. For a given sample rate, this works out to: | 104 // to 20 ms worth of samples. For a given sample rate, this works out to: |
| 105 // | 105 // |
| 106 // <= 3200 : 64 | 106 // <= 3200 : 64 |
| 107 // <= 6400 : 128 | 107 // <= 6400 : 128 |
| 108 // <= 12800 : 256 | 108 // <= 12800 : 256 |
| 109 // <= 25600 : 512 | 109 // <= 25600 : 512 |
| 110 // <= 51200 : 1024 | 110 // <= 51200 : 1024 |
| 111 // <= 102400 : 2048 | 111 // <= 102400 : 2048 |
| 112 // <= 204800 : 4096 | 112 // <= 204800 : 4096 |
| 113 // | 113 // |
| 114 // On Linux, the minimum hardware buffer size is 512, so the lower calculated | 114 // On Linux, the minimum hardware buffer size is 512, so the lower calculated |
| 115 // values are unused. OSX may have a value as low as 128. Windows is device | 115 // values are unused. OSX may have a value as low as 128. Windows is device |
| 116 // dependent but will generally be sample_rate() / 100. | 116 // dependent but will generally be sample_rate() / 100. |
| 117 const int high_latency_buffer_size = | 117 const int high_latency_buffer_size = |
| 118 RoundUpToPowerOfTwo(2 * output_params_.sample_rate() / 100); | 118 RoundUpToPowerOfTwo(2 * output_params_.sample_rate() / 100); |
| 119 return std::max(output_params_.frames_per_buffer(), high_latency_buffer_size); | 119 return std::max(output_params_.frames_per_buffer(), high_latency_buffer_size); |
| 120 #else | 120 #else |
| 121 return output_params_.frames_per_buffer(); | 121 return output_params_.frames_per_buffer(); |
| 122 #endif | 122 #endif |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace media | 125 } // namespace media |
| OLD | NEW |