Chromium Code Reviews| Index: media/base/audio_hardware_config.cc |
| diff --git a/media/base/audio_hardware_config.cc b/media/base/audio_hardware_config.cc |
| index d72fce7b4e234c2f225e28b528c15900dd2582d2..7f1ebf7a13ede7ed749194139d4b76948fb2b5fb 100644 |
| --- a/media/base/audio_hardware_config.cc |
| +++ b/media/base/audio_hardware_config.cc |
| @@ -4,16 +4,36 @@ |
| #include "media/base/audio_hardware_config.h" |
| +#include <algorithm> |
| + |
| +#include "base/logging.h" |
| +#include "build/build_config.h" |
| + |
| using base::AutoLock; |
| using media::AudioParameters; |
| namespace media { |
| +// Taken from "Bit Twiddling Hacks" |
| +// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 |
| +static uint32_t RoundUpToPowerOfTwo(uint32_t v) { |
| + v--; |
| + v |= v >> 1; |
| + v |= v >> 2; |
| + v |= v >> 4; |
| + v |= v >> 8; |
| + v |= v >> 16; |
| + v++; |
| + return v; |
| +} |
| + |
| AudioHardwareConfig::AudioHardwareConfig( |
| const AudioParameters& input_params, |
| const AudioParameters& output_params) |
| : input_params_(input_params), |
| output_params_(output_params) { |
| + DCHECK(input_params_.IsValid()); |
| + DCHECK(output_params_.IsValid()); |
| } |
| AudioHardwareConfig::~AudioHardwareConfig() {} |
| @@ -77,4 +97,29 @@ void AudioHardwareConfig::UpdateOutputConfig( |
| output_params_ = output_params; |
| } |
| +int AudioHardwareConfig::GetHighLatencyBufferSize() const { |
| + AutoLock auto_lock(config_lock_); |
| +#if defined(OS_LINUX) |
| + // Empirically, use the nearest higher power of two buffer size corresponding |
| + // to 20 ms worth of samples. For a given sample rate, this works out to: |
|
no longer working on chromium
2014/04/14 08:51:50
curiously, 20ms does not sound "high" latency, why
DaleCurtis
2014/04/14 18:08:18
As discussed in the meeting this morning, I choose
|
| + // |
| + // <= 3200 : 64 |
| + // <= 6400 : 128 |
| + // <= 12800 : 256 |
| + // <= 25600 : 512 |
| + // <= 51200 : 1024 |
| + // <= 102400 : 2048 |
| + // <= 204800 : 4096 |
| + // |
| + // On Linux, the minimum hardware buffer size is 512, so the lower calculated |
| + // values are unused. OSX may have a value as low as 128. Windows is device |
|
henrika (OOO until Aug 14)
2014/04/14 08:03:24
Should comments about OSX and Windows be within de
DaleCurtis
2014/04/14 18:08:18
I hope eventually this section will have all OS, s
|
| + // dependent but will generally be sample_rate() / 100. |
| + const int high_latency_buffer_size = |
| + RoundUpToPowerOfTwo(2 * output_params_.sample_rate() / 100); |
| + return std::max(output_params_.frames_per_buffer(), high_latency_buffer_size); |
| +#else |
| + return output_params_.frames_per_buffer(); |
| +#endif |
| +} |
| + |
| } // namespace media |