Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(865)

Unified Diff: third_party/WebKit/Source/platform/audio/AudioDestination.cpp

Issue 2501863003: Support for AudioContextOptions latencyHint. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 4cccdd9a4682f2157244b6b2ac7c8a6278c20819..8882377a67983c4c1fc322b4cd365ebf14d801dd 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),
Raymond Toy 2016/11/15 18:16:17 Where is this initialized now? It's really import
Andrew MacPherson 2016/11/16 10:58:30 Based on an earlier suggestion from o1ka@ I change
m_isPlaying(false) {
// Histogram for audioHardwareBufferSize
DEFINE_STATIC_LOCAL(SparseHistogram, hardwareBufferSizeHistogram,
@@ -80,41 +80,20 @@ 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);
hongchan 2016/11/15 23:46:01 So I guess now we have to query the sample rate vi
Andrew MacPherson 2016/11/16 10:58:29 Yes, this was the intention but I will let o1ka@ c
+ m_callbackBufferSize = m_audioDevice->framesPerBuffer();
hongchan 2016/11/15 23:46:01 o1ka@ If we do this, is this going to be an IPC c
o1ka 2016/11/17 17:37:25 No extra IPC, the value is cached in audio device.
// 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(m_callbackBufferSize);
o1ka 2016/11/15 22:44:28 I'm not sure if these two histograms have the righ
hongchan 2016/11/15 23:46:01 I think o1ka is right. This seems wrong and we mig
Raymond Toy 2016/11/15 23:50:38 Yeah, but I think we really want this somewhere. I
Andrew MacPherson 2016/11/16 10:58:30 Let me know if you'd like me to move this elsewher
callbackBufferSizeHistogram.sample(m_callbackBufferSize);
// Create a FIFO to handle the possibility of the callback size

Powered by Google App Engine
This is Rietveld 408576698