diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-05-20 09:47:09 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-07 11:15:42 +0000 |
commit | 189d4fd8fad9e3c776873be51938cd31a42b6177 (patch) | |
tree | 6497caeff5e383937996768766ab3bb2081a40b2 /chromium/media/base/audio_latency.cc | |
parent | 8bc75099d364490b22f43a7ce366b366c08f4164 (diff) | |
download | qtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz |
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/media/base/audio_latency.cc')
-rw-r--r-- | chromium/media/base/audio_latency.cc | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/chromium/media/base/audio_latency.cc b/chromium/media/base/audio_latency.cc index b55a2da37e1..f15e8f95ba5 100644 --- a/chromium/media/base/audio_latency.cc +++ b/chromium/media/base/audio_latency.cc @@ -25,6 +25,7 @@ namespace media { namespace { + #if !defined(OS_WIN) // Taken from "Bit Twiddling Hacks" // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 @@ -39,11 +40,30 @@ uint32_t RoundUpToPowerOfTwo(uint32_t v) { return v; } #endif + +#if defined(OS_ANDROID) +// WebAudio renderer's quantum size (frames per callback) that is used for +// calculating the "interactive" buffer size. +// TODO(crbug.com/988121): This number needs to be passed down from Blink when +// user-selectable render quantum size is implemented. +const int kWebAudioRenderQuantumSize = 128; + +// From media/renderers/paint_canvas_video_renderer.cc. To calculate the optimum +// buffer size for Pixel 3/4/5 devices, which has a HW buffer size of 96 frames. +int GCD(int a, int b) { + return a == 0 ? b : GCD(b % a, a); +} + +int LCM(int a, int b) { + return a / GCD(a, b) * b; +} +#endif + } // namespace // static bool AudioLatency::IsResamplingPassthroughSupported(LatencyType type) { -#if BUILDFLAG(IS_ASH) +#if BUILDFLAG(IS_CHROMEOS_ASH) return true; #elif defined(OS_ANDROID) // Only N MR1+ has support for OpenSLES performance modes which allow for @@ -139,13 +159,28 @@ int AudioLatency::GetRtcBufferSize(int sample_rate, int hardware_buffer_size) { // static int AudioLatency::GetInteractiveBufferSize(int hardware_buffer_size) { + CHECK_GT(hardware_buffer_size, 0); + #if defined(OS_ANDROID) // Always log this because it's relatively hard to get this // information out. LOG(INFO) << "audioHardwareBufferSize = " << hardware_buffer_size; -#endif + if (hardware_buffer_size >= kWebAudioRenderQuantumSize) + return hardware_buffer_size; + + // HW buffer size is smaller than the Web Audio's render quantum size, so + // compute LCM to avoid glitches and regulate the workload per callback. + // (e.g. 96 vs 128 -> 384) Also cap the buffer size to 4 render quanta + // (512 frames ~= 10ms at 48K) if LCM goes beyond interactive latency range. + int sensible_buffer_size = std::min( + LCM(hardware_buffer_size, kWebAudioRenderQuantumSize), + kWebAudioRenderQuantumSize * 4); + + return sensible_buffer_size; +#else return hardware_buffer_size; +#endif // defined(OS_ANDROID) } int AudioLatency::GetExactBufferSize(base::TimeDelta duration, |