| 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..959b90c23bdcd4055ed3716466f62a57a0cba6f0 100644
|
| --- a/media/base/audio_hardware_config.cc
|
| +++ b/media/base/audio_hardware_config.cc
|
| @@ -4,17 +4,40 @@
|
|
|
| #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 {
|
|
|
| +#if defined(OS_LINUX)
|
| +#define HIGH_LATENCY_AUDIO_SUPPORT 1
|
| +#endif
|
| +
|
| +#if defined(HIGH_LATENCY_AUDIO_SUPPORT)
|
| +// 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;
|
| +}
|
| +#endif
|
| +
|
| AudioHardwareConfig::AudioHardwareConfig(
|
| const AudioParameters& input_params,
|
| const AudioParameters& output_params)
|
| : input_params_(input_params),
|
| - output_params_(output_params) {
|
| -}
|
| + output_params_(output_params) {}
|
|
|
| AudioHardwareConfig::~AudioHardwareConfig() {}
|
|
|
| @@ -77,4 +100,29 @@ void AudioHardwareConfig::UpdateOutputConfig(
|
| output_params_ = output_params;
|
| }
|
|
|
| +int AudioHardwareConfig::GetHighLatencyBufferSize() const {
|
| + AutoLock auto_lock(config_lock_);
|
| +#if defined(HIGH_LATENCY_AUDIO_SUPPORT)
|
| + // 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:
|
| + //
|
| + // <= 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
|
| + // 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
|
|
|