Commit d09644db authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

WebAudio: Fix OscillatorNode liveness

Canonical fix:
- Model liveness through OscillatorNode (AudioNode), i.e., keep alive
  listener from there.
- Change off-thread handler to use a weak root

This works as AudioNode disposes the handler in the pre-finalizer.

This fixes webaudio/Oscillator/osc-low-freq.html for unified heap
running with leak detection.

Bug: 928781, 843903
Change-Id: I58a76bb0d5a47e65e91516cde6c4fe77044cb8ae
Reviewed-on: https://chromium-review.googlesource.com/c/1488922
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635594}
parent 277b8dd4
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
*/ */
#include <algorithm> #include <algorithm>
#include <limits>
#include "third_party/blink/renderer/modules/webaudio/audio_node_output.h" #include "third_party/blink/renderer/modules/webaudio/audio_node_output.h"
#include "third_party/blink/renderer/modules/webaudio/oscillator_node.h" #include "third_party/blink/renderer/modules/webaudio/oscillator_node.h"
...@@ -525,7 +526,8 @@ OscillatorNode::OscillatorNode(BaseAudioContext& context, ...@@ -525,7 +526,8 @@ OscillatorNode::OscillatorNode(BaseAudioContext& context,
AudioParamHandler::AutomationRate::kAudio, AudioParamHandler::AutomationRate::kAudio,
AudioParamHandler::AutomationRateMode::kVariable, AudioParamHandler::AutomationRateMode::kVariable,
-1200 * log2f(std::numeric_limits<float>::max()), -1200 * log2f(std::numeric_limits<float>::max()),
1200 * log2f(std::numeric_limits<float>::max()))) { 1200 * log2f(std::numeric_limits<float>::max()))),
periodic_wave_(wave_table) {
SetHandler(OscillatorHandler::Create( SetHandler(OscillatorHandler::Create(
*this, context.sampleRate(), oscillator_type, wave_table, *this, context.sampleRate(), oscillator_type, wave_table,
frequency_->Handler(), detune_->Handler())); frequency_->Handler(), detune_->Handler()));
...@@ -568,6 +570,7 @@ OscillatorNode* OscillatorNode::Create(BaseAudioContext* context, ...@@ -568,6 +570,7 @@ OscillatorNode* OscillatorNode::Create(BaseAudioContext* context,
void OscillatorNode::Trace(blink::Visitor* visitor) { void OscillatorNode::Trace(blink::Visitor* visitor) {
visitor->Trace(frequency_); visitor->Trace(frequency_);
visitor->Trace(detune_); visitor->Trace(detune_);
visitor->Trace(periodic_wave_);
AudioScheduledSourceNode::Trace(visitor); AudioScheduledSourceNode::Trace(visitor);
} }
...@@ -593,6 +596,7 @@ AudioParam* OscillatorNode::detune() { ...@@ -593,6 +596,7 @@ AudioParam* OscillatorNode::detune() {
} }
void OscillatorNode::setPeriodicWave(PeriodicWave* wave) { void OscillatorNode::setPeriodicWave(PeriodicWave* wave) {
periodic_wave_ = wave;
GetOscillatorHandler().SetPeriodicWave(wave); GetOscillatorHandler().SetPeriodicWave(wave);
} }
......
...@@ -106,10 +106,8 @@ class OscillatorHandler final : public AudioScheduledSourceHandler { ...@@ -106,10 +106,8 @@ class OscillatorHandler final : public AudioScheduledSourceHandler {
AudioFloatArray phase_increments_; AudioFloatArray phase_increments_;
AudioFloatArray detune_values_; AudioFloatArray detune_values_;
// This Persistent doesn't make a reference cycle including the owner // PeriodicWave is held alive by OscillatorNode.
// OscillatorNode. It is cross-thread, as it will be accessed by the audio CrossThreadWeakPersistent<PeriodicWave> periodic_wave_;
// thread.
CrossThreadPersistent<PeriodicWave> periodic_wave_;
}; };
class OscillatorNode final : public AudioScheduledSourceNode { class OscillatorNode final : public AudioScheduledSourceNode {
...@@ -140,6 +138,9 @@ class OscillatorNode final : public AudioScheduledSourceNode { ...@@ -140,6 +138,9 @@ class OscillatorNode final : public AudioScheduledSourceNode {
private: private:
Member<AudioParam> frequency_; Member<AudioParam> frequency_;
Member<AudioParam> detune_; Member<AudioParam> detune_;
// This PeriodicWave is held alive here to allow referencing it from
// OscillatorHandler via weak reference.
Member<PeriodicWave> periodic_wave_;
}; };
} // namespace blink } // namespace blink
......
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