summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-04-17 15:05:56 +0200
committerMichal Klocek <michal.klocek@qt.io>2020-06-10 07:07:50 +0000
commit8dc8aecf84bfae65a724fa3de71b27f8b5ea7957 (patch)
tree84f1a754daa34c04e2fe19e44483701045c1da72
parent04567666daee8f710dbae83173e5d7e1d5cccf29 (diff)
downloadqtwebengine-chromium-8dc8aecf84bfae65a724fa3de71b27f8b5ea7957.tar.gz
[Backport] When suspending context, don't clear handlers
AudioContext.suspend() would call StopRendering(). This stops the audio thread from pulling the graph (eventually) but it also clears out any handlers, including those associated with automatic pull nodes for any AnalyserNode that isn't connected to the destination. When the context is resumed, the AnalyserNode isn't pulled anymore, so the output never changes. Add a SuspendRendering() method to handle AudioContext.suspend() which doesn't clear the handlers. Then when the context is resumed, AnalyserNodes will get pulled again. Then StopRendering() is used only for AudioContext.close() where it is ok to clear out the handlers since we can't resume a closed context. Bug: 1018499 Change-Id: I4b4ccf688b37e6b81d310d2596cfff9603048876 Reviewed-by: Hongchan Choi <hongchan@chromium.org> Commit-Queue: Raymond Toy <rtoy@chromium.org> Cr-Commit-Position: refs/heads/master@{#723609} Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--chromium/third_party/blink/renderer/modules/webaudio/audio_context.cc14
-rw-r--r--chromium/third_party/blink/renderer/modules/webaudio/audio_context.h7
2 files changed, 17 insertions, 4 deletions
diff --git a/chromium/third_party/blink/renderer/modules/webaudio/audio_context.cc b/chromium/third_party/blink/renderer/modules/webaudio/audio_context.cc
index 71a1013fdb2..d2ced26b77b 100644
--- a/chromium/third_party/blink/renderer/modules/webaudio/audio_context.cc
+++ b/chromium/third_party/blink/renderer/modules/webaudio/audio_context.cc
@@ -177,7 +177,7 @@ ScriptPromise AudioContext::suspendContext(ScriptState* script_state) {
} else {
// Stop rendering now.
if (destination())
- StopRendering();
+ SuspendRendering();
// Since we don't have any way of knowing when the hardware actually stops,
// we'll just resolve the promise now.
@@ -333,12 +333,22 @@ void AudioContext::StopRendering() {
// the AudioContext is already unreachable from the user code.
if (ContextState() != kClosed) {
destination()->GetAudioDestinationHandler().StopRendering();
- SetContextState(kSuspended);
+ SetContextState(kClosed);
GetDeferredTaskHandler().ClearHandlersToBeDeleted();
keep_alive_.Clear();
}
}
+void AudioContext::SuspendRendering() {
+ DCHECK(IsMainThread());
+ DCHECK(destination());
+
+ if (ContextState() == kRunning) {
+ destination()->GetAudioDestinationHandler().StopRendering();
+ SetContextState(kSuspended);
+ }
+}
+
double AudioContext::baseLatency() const {
DCHECK(IsMainThread());
DCHECK(destination());
diff --git a/chromium/third_party/blink/renderer/modules/webaudio/audio_context.h b/chromium/third_party/blink/renderer/modules/webaudio/audio_context.h
index 9680cfdc3e4..b4a3c4c2c90 100644
--- a/chromium/third_party/blink/renderer/modules/webaudio/audio_context.h
+++ b/chromium/third_party/blink/renderer/modules/webaudio/audio_context.h
@@ -110,10 +110,13 @@ class MODULES_EXPORT AudioContext : public BaseAudioContext {
void StartRendering() override;
// Called when the context is being closed to stop rendering audio and clean
- // up handlers. This clears the self-referencing pointer, making this object
- // available for the potential GC.
+ // up handlers.
void StopRendering();
+ // Called when suspending the context to stop reundering audio, but don't
+ // clean up handlers because we expect to be resuming where we left off.
+ void SuspendRendering();
+
void DidClose();
unsigned context_id_;