Commit 6942572d authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Compute baseLatency at construction and cache the value

Since the baseLatency value is fixed after construction, compute the
value when the AudioContext is constructed and cache the value so that
any queries just return the value from the slot.

Bug: 1005150
Change-Id: I0a4b8c4fb42deb5721f0ecdce5a8bc3b3c4cb26e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903750Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713643}
parent 867181aa
...@@ -155,6 +155,20 @@ AudioContext::AudioContext(Document& document, ...@@ -155,6 +155,20 @@ AudioContext::AudioContext(Document& document,
} }
Initialize(); Initialize();
// Compute the base latency now and cache the value since it doesn't change
// once the context is constructed. We need the destination to be initialized
// so we have to compute it here.
//
// TODO(hongchan): Due to the incompatible constructor between
// AudioDestinationNode and RealtimeAudioDestinationNode, casting directly
// from |destination()| is impossible. This is a temporary workaround until
// the refactoring is completed.
RealtimeAudioDestinationHandler& destination_handler =
static_cast<RealtimeAudioDestinationHandler&>(
destination()->GetAudioDestinationHandler());
base_latency_ = destination_handler.GetFramesPerBuffer() /
static_cast<double>(sampleRate());
} }
void AudioContext::Uninitialize() { void AudioContext::Uninitialize() {
...@@ -359,15 +373,7 @@ double AudioContext::baseLatency() const { ...@@ -359,15 +373,7 @@ double AudioContext::baseLatency() const {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
DCHECK(destination()); DCHECK(destination());
// TODO(hongchan): Due to the incompatible constructor between return base_latency_;
// AudioDestinationNode and RealtimeAudioDestinationNode, casting directly
// from |destination()| is impossible. This is a temporary workaround until
// the refactoring is completed.
RealtimeAudioDestinationHandler& destination_handler =
static_cast<RealtimeAudioDestinationHandler&>(
destination()->GetAudioDestinationHandler());
return destination_handler.GetFramesPerBuffer() /
static_cast<double>(sampleRate());
} }
MediaElementAudioSourceNode* AudioContext::createMediaElementSource( MediaElementAudioSourceNode* AudioContext::createMediaElementSource(
......
...@@ -176,6 +176,9 @@ class MODULES_EXPORT AudioContext : public BaseAudioContext { ...@@ -176,6 +176,9 @@ class MODULES_EXPORT AudioContext : public BaseAudioContext {
// Represents whether a context is suspended by explicit |context.suspend()|. // Represents whether a context is suspended by explicit |context.suspend()|.
bool suspended_by_user_ = false; bool suspended_by_user_ = false;
// baseLatency for this context
double base_latency_ = 0;
// AudioContextManager for reporting audibility. // AudioContextManager for reporting audibility.
mojo::Remote<mojom::blink::AudioContextManager> audio_context_manager_; mojo::Remote<mojom::blink::AudioContextManager> audio_context_manager_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment