Commit 1a037146 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Web Audio: fix two bugs in audibility detection in BaseAudioContext.

Fixing the following issues:
 - take into account AudioContext stopping;
 - removes 10 seconds limitation.

Bug: 897451
Change-Id: I63b22fc20ded193cd032e30722ab35571adba56c
Reviewed-on: https://chromium-review.googlesource.com/c/1292378
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601415}
parent 1275ad42
...@@ -77,10 +77,6 @@ ...@@ -77,10 +77,6 @@
namespace blink { namespace blink {
// Recording of audio audibility stops after the context has been running for
// this long. We don't need this information for the lifetime of the context.
const double kStopRecordingAudibilityTime = 10;
BaseAudioContext* BaseAudioContext::Create( BaseAudioContext* BaseAudioContext::Create(
Document& document, Document& document,
const AudioContextOptions& context_options, const AudioContextOptions& context_options,
...@@ -605,6 +601,16 @@ void BaseAudioContext::SetContextState(AudioContextState new_state) { ...@@ -605,6 +601,16 @@ void BaseAudioContext::SetContextState(AudioContextState new_state) {
context_state_ = new_state; context_state_ = new_state;
// Audibility checks only happen when the context is running so manual
// notification is required when the context gets suspended or closed.
if (was_audible_ && context_state_ != kRunning) {
was_audible_ = false;
PostCrossThreadTask(
*task_runner_, FROM_HERE,
CrossThreadBind(&BaseAudioContext::NotifyAudibleAudioStopped,
WrapCrossThreadPersistent(this)));
}
// Notify context that state changed // Notify context that state changed
if (GetExecutionContext()) { if (GetExecutionContext()) {
GetExecutionContext() GetExecutionContext()
...@@ -721,14 +727,10 @@ void BaseAudioContext::HandlePostRenderTasks(const AudioBus* destination_bus) { ...@@ -721,14 +727,10 @@ void BaseAudioContext::HandlePostRenderTasks(const AudioBus* destination_bus) {
// Detect silence (or not) for MEI // Detect silence (or not) for MEI
bool is_audible = IsAudible(destination_bus); bool is_audible = IsAudible(destination_bus);
// We want to keep track of the total audible audio, but we don't need to
// record the start and stop of audible audio after
// |kStopRecordingAudibilityTime|.
if (is_audible) { if (is_audible) {
++total_audible_renders_; ++total_audible_renders_;
} }
if (currentTime() <= kStopRecordingAudibilityTime) {
if (was_audible_ != is_audible) { if (was_audible_ != is_audible) {
// Audibility changed in this render, so report the change. // Audibility changed in this render, so report the change.
was_audible_ = is_audible; was_audible_ = is_audible;
...@@ -745,7 +747,6 @@ void BaseAudioContext::HandlePostRenderTasks(const AudioBus* destination_bus) { ...@@ -745,7 +747,6 @@ void BaseAudioContext::HandlePostRenderTasks(const AudioBus* destination_bus) {
} }
} }
} }
}
} }
void BaseAudioContext::PerformCleanupOnMainThread() { void BaseAudioContext::PerformCleanupOnMainThread() {
......
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