Chromium Code Reviews| Index: third_party/WebKit/Source/platform/audio/AudioDestination.cpp |
| diff --git a/third_party/WebKit/Source/platform/audio/AudioDestination.cpp b/third_party/WebKit/Source/platform/audio/AudioDestination.cpp |
| index 39903c682010aa23536b1e7061ebce9d5a012e0b..803ad39bc11ccd7dfe4e8e2a01ae87382b3b69fe 100644 |
| --- a/third_party/WebKit/Source/platform/audio/AudioDestination.cpp |
| +++ b/third_party/WebKit/Source/platform/audio/AudioDestination.cpp |
| @@ -34,6 +34,7 @@ |
| #include "platform/audio/AudioUtilities.h" |
| #include "platform/weborigin/SecurityOrigin.h" |
| #include "public/platform/Platform.h" |
| +#include "public/platform/WebAudioLatencyHint.h" |
| #include "public/platform/WebSecurityOrigin.h" |
| #include "wtf/PtrUtil.h" |
| #include <memory> |
| @@ -49,18 +50,18 @@ std::unique_ptr<AudioDestination> AudioDestination::create( |
| const String& inputDeviceId, |
| unsigned numberOfInputChannels, |
| unsigned numberOfOutputChannels, |
| - float sampleRate, |
| + const WebAudioLatencyHint& latencyHint, |
| PassRefPtr<SecurityOrigin> securityOrigin) { |
| return wrapUnique(new AudioDestination( |
| callback, inputDeviceId, numberOfInputChannels, numberOfOutputChannels, |
| - sampleRate, std::move(securityOrigin))); |
| + latencyHint, std::move(securityOrigin))); |
| } |
| AudioDestination::AudioDestination(AudioIOCallback& callback, |
| const String& inputDeviceId, |
| unsigned numberOfInputChannels, |
| unsigned numberOfOutputChannels, |
| - float sampleRate, |
| + const WebAudioLatencyHint& latencyHint, |
| PassRefPtr<SecurityOrigin> securityOrigin) |
| : m_callback(callback), |
| m_numberOfOutputChannels(numberOfOutputChannels), |
| @@ -69,7 +70,6 @@ AudioDestination::AudioDestination(AudioIOCallback& callback, |
| m_renderBus(AudioBus::create(numberOfOutputChannels, |
| AudioUtilities::kRenderQuantumFrames, |
| false)), |
| - m_sampleRate(sampleRate), |
| m_isPlaying(false) { |
| // Histogram for audioHardwareBufferSize |
| DEFINE_STATIC_LOCAL(SparseHistogram, hardwareBufferSizeHistogram, |
| @@ -80,41 +80,21 @@ AudioDestination::AudioDestination(AudioIOCallback& callback, |
| DEFINE_STATIC_LOCAL(SparseHistogram, callbackBufferSizeHistogram, |
| ("WebAudio.AudioDestination.CallbackBufferSize")); |
| - // Use the optimal buffer size recommended by the audio backend. |
| - size_t recommendedHardwareBufferSize = |
| - Platform::current()->audioHardwareBufferSize(); |
| - m_callbackBufferSize = recommendedHardwareBufferSize; |
| - |
| -#if OS(ANDROID) |
| - // The optimum low-latency hardware buffer size is usually too small on |
| - // Android for WebAudio to render without glitching. So, if it is small, use |
| - // a larger size. If it was already large, use the requested size. |
| - // |
| - // Since WebAudio renders in 128-frame blocks, the small buffer sizes (144 |
| - // for a Galaxy Nexus), cause significant processing jitter. Sometimes |
| - // multiple blocks will processed, but other times will not be since the FIFO |
| - // can satisfy the request. By using a larger callbackBufferSize, we smooth |
| - // out the jitter. |
| - const size_t kSmallBufferSize = 1024; |
| - const size_t kDefaultCallbackBufferSize = 2048; |
| - |
| - if (m_callbackBufferSize <= kSmallBufferSize) |
| - m_callbackBufferSize = kDefaultCallbackBufferSize; |
| -#endif |
| + m_audioDevice = wrapUnique(Platform::current()->createAudioDevice( |
| + numberOfInputChannels, numberOfOutputChannels, latencyHint, this, |
| + inputDeviceId, std::move(securityOrigin))); |
| + DCHECK(m_audioDevice); |
| + m_callbackBufferSize = m_audioDevice->framesPerBuffer(); |
| // Quick exit if the requested size is too large. |
| DCHECK_LE(m_callbackBufferSize + AudioUtilities::kRenderQuantumFrames, |
| fifoSize); |
| if (m_callbackBufferSize + AudioUtilities::kRenderQuantumFrames > fifoSize) |
| return; |
| - m_audioDevice = wrapUnique(Platform::current()->createAudioDevice( |
| - m_callbackBufferSize, numberOfInputChannels, numberOfOutputChannels, |
| - sampleRate, this, inputDeviceId, std::move(securityOrigin))); |
| - ASSERT(m_audioDevice); |
| - |
| // Record the sizes if we successfully created an output device. |
| - hardwareBufferSizeHistogram.sample(recommendedHardwareBufferSize); |
| + hardwareBufferSizeHistogram.sample( |
| + Platform::current()->audioHardwareBufferSize()); |
| callbackBufferSizeHistogram.sample(m_callbackBufferSize); |
|
o1ka
2016/12/07 20:56:01
rtoy@ - callback buffer size will be different for
Raymond Toy
2016/12/08 16:24:50
Good point. It probably would be a good idea to ad
|
| // Create a FIFO to handle the possibility of the callback size |