Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ChannelMerger active processing test less flaky
Replace the offline audio context with a realtime context and an AudioWorklet. Previously, when the source stopped, the channel count change would sometimes get delayed until rendering is done, which is too late for the test. I believe this is because the main thread was previously too busy to process the messages to disable outputs and change the channel count. Using a realtime context makes the main thread less busy because the messages aren't posted as fast as possible, allowing time for them to be handled. I think this is still flaky, but much less so than before. Bug: 974258 Test: the-channelmergernode-interface/active-processing.https.html Change-Id: Id584ebfa5f54ad6870819f5242aafed5f4fc80d1
- Loading branch information
1 parent
3671eb9
commit 8880ab2
Showing
2 changed files
with
142 additions
and
87 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
webaudio/the-audio-api/the-audioworklet-interface/processors/active-processing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @class ActiveProcessingTester | ||
* @extends AudioWorkletProcessor | ||
* | ||
* This processor class sends a message to its AudioWorkletNodew whenever the | ||
* number of channels on the input changes. The message includes the actual | ||
* number of channels, the context time at which this occurred, and whether | ||
* we're done processing or not. | ||
*/ | ||
class ActiveProcessingTester extends AudioWorkletProcessor { | ||
constructor(options) { | ||
super(options); | ||
this._lastChannelCount = 0; | ||
this.port.onmessage = this.handleMessage_.bind(this); | ||
|
||
// See if user specified a value for test duration. | ||
if (options.hasOwnProperty('processorOptions') && | ||
options.processorOptions.hasOwnProperty('testDuration')) { | ||
this._testDuration = options.processorOptions.testDuration; | ||
} else { | ||
this._testDuration = 5; | ||
} | ||
|
||
// Time at which we'll signal we're done, based on the requested | ||
// |testDuration| | ||
this._endTime = currentTime + this._testDuration; | ||
} | ||
|
||
handleMessage_(event) { | ||
// We don't expect any messages from the worklet node. | ||
} | ||
|
||
process(inputs, outputs) { | ||
let input = inputs[0]; | ||
let output = outputs[0]; | ||
let inputChannelCount = input.length; | ||
let finished = currentTime > this._endTime; | ||
|
||
if (finished || (inputChannelCount != this._lastChannelCount)) { | ||
this.port.postMessage({ | ||
channelCount: inputChannelCount, | ||
finished: finished, | ||
time: currentTime | ||
}); | ||
this._lastChannelCount = inputChannelCount; | ||
} | ||
|
||
// Just copy the input to the output for no particular reason. | ||
for (let channel = 0; channel < input.length; ++channel) { | ||
output[channel].set(input[channel]); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
registerProcessor('active-processing-tester', ActiveProcessingTester); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters