forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add currentFrame in AudioWorkletGlobalScope
This CL adds |currentFrame| property to AudioWorkletGlobalScope according to: WebAudio/web-audio-api#1493. 1. Previously the time stamp (currentTime) was updated when the first worklet processor gets called, and it was inconsistent with how it is updated in the other nodes. Now updating the frame number is streamlined, so the worklet processor also gets the same treatment. 2. In order to streamline this process, WorkerThread reference was added to BaseAudioContext. Due to the GC rule, BaseAudioContext cannot keep a reference of WorkletGlobalScope, so it always derives the global scope from the worker thread. Bug: 814794 Test: http/tests/webaudio/audio-worklet/timing-info.html Change-Id: I4b313377d80f8678c473cf788211e373fd1644cb Reviewed-on: https://chromium-review.googlesource.com/935157 Commit-Queue: Hongchan Choi <[email protected]> Reviewed-by: Kentaro Hara <[email protected]> Reviewed-by: Raymond Toy <[email protected]> Cr-Commit-Position: refs/heads/master@{#539300}
- Loading branch information
Showing
17 changed files
with
151 additions
and
27 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
third_party/WebKit/LayoutTests/http/tests/webaudio/audio-worklet/timing-info-processor.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,25 @@ | ||
/** | ||
* @class TimingInfoProcessor | ||
* @extends AudioWorkletProcessor | ||
* | ||
* This processor class is to test the timing information in AWGS. | ||
*/ | ||
class TimingInfoProcessor extends AudioWorkletProcessor { | ||
constructor() { | ||
super(); | ||
this.port.onmessage = this.echoMessage.bind(this); | ||
} | ||
|
||
echoMessage(event) { | ||
this.port.postMessage({ | ||
currentTime: currentTime, | ||
currentFrame: currentFrame | ||
}); | ||
} | ||
|
||
process() { | ||
return true; | ||
} | ||
} | ||
|
||
registerProcessor('timing-info-processor', TimingInfoProcessor); |
59 changes: 59 additions & 0 deletions
59
third_party/WebKit/LayoutTests/http/tests/webaudio/audio-worklet/timing-info.html
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,59 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title> | ||
Test currentTime and currentFrame in AudioWorkletGlobalScope | ||
</title> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
<script src="../../../webaudio-resources/audit.js"></script> | ||
<script src="audio-worklet-common.js"></script> | ||
</head> | ||
<body> | ||
<script id="layout-test-code"> | ||
// TODO(hongchan): remove this assertion when AudioWorklet shipped. | ||
assertAudioWorklet(); | ||
|
||
let audit = Audit.createTaskRunner(); | ||
|
||
let sampleRate = 48000; | ||
let renderLength = 512; | ||
let context = new OfflineAudioContext(1, renderLength, sampleRate); | ||
|
||
audit.define( | ||
'Check the timing information from AudioWorkletProcessor', | ||
(task, should) => { | ||
let portWorkletNode = | ||
new AudioWorkletNode(context, 'timing-info-processor'); | ||
portWorkletNode.connect(context.destination); | ||
|
||
// Suspend at render quantum boundary and check the timing | ||
// information between the main thread and the rendering thread. | ||
[0, 128, 256, 384].map((suspendFrame) => { | ||
context.suspend(suspendFrame/sampleRate).then(() => { | ||
portWorkletNode.port.onmessage = (event) => { | ||
should(event.data.currentFrame, | ||
'currentFrame from the processor at ' + suspendFrame) | ||
.beEqualTo(suspendFrame); | ||
should(event.data.currentTime, | ||
'currentTime from the processor at ' | ||
+ context.currentTime) | ||
.beEqualTo(context.currentTime); | ||
context.resume(); | ||
}; | ||
|
||
portWorkletNode.port.postMessage('query-timing-info'); | ||
}); | ||
}); | ||
|
||
context.startRendering().then(() => { | ||
task.done(); | ||
}); | ||
}); | ||
|
||
context.audioWorklet.addModule('timing-info-processor.js').then(() => { | ||
audit.run(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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