From 94a40780076a83c4f4dfa4223c4f1ace517d88f0 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Thu, 11 Feb 2021 20:46:18 +0100 Subject: [PATCH 1/3] Define when and how regular tasks are processed wrt the processing model This fixes #2008. --- index.bs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/index.bs b/index.bs index 6aad64bf9..59678d81e 100644 --- a/index.bs +++ b/index.bs @@ -10085,6 +10085,9 @@ Every {{AudioWorkletProcessor}} has an associated active source flag, the node to be retained in memory and perform audio processing in the absence of any connected inputs. +All tasks posted from an {{AudioWorkletNode}} are posted to the task queue of +its associated {{BaseAudioContext}}. + [Exposed=Window] interface AudioParamMap { @@ -11118,9 +11121,14 @@ in the algorithm of <a href="#rendering-a-graph">rendering a graph</a>. The audio callback is also queued as a task in the <a href="#control-message-queue">control message queue</a>. The UA MUST perform the following algorithms to process render quanta to fulfill such task by -filling up the requested buffer size. Along with the primary message queue, the -<a>rendering thread</a> has another task queue for microtasks for any microtask -operation such as resolution of {{Promise}}s in the {{AudioWorkletGlobalScope}}. +filling up the requested buffer size. Along with the primary message queue, each +{{AudioContext}} has a regular task queue for tasks that are posted to +the rendering thread from the control thread. An additional microtask checkpoint +is performed after processing a render quantum to run any microtasks that might +have been queued during the execution of the `process` methods of +{{AudioWorkletProcessor}}. + +All tasks posted from an {{AudioWorkletNode}} are posted to this task queue. <div id="rendering-initialization" algorithm="initialize rendering loop"> The following step MUST be performed once before the rendering loop starts. @@ -11131,6 +11139,8 @@ operation such as resolution of {{Promise}}s in the {{AudioWorkletGlobalScope}}. </div> <div id="rendering-a-graph" algorithm="rendering a graph"> + The following sterp MUST be performed when rendering a single render quantum. + 1. Let <var>render result</var> be <code>false</code>. 2. Process the [=control message queue=]. @@ -11147,7 +11157,15 @@ operation such as resolution of {{Promise}}s in the {{AudioWorkletGlobalScope}}. 2. Remove the [=oldest message=] of <var>Q<sub>rendering</sub></var>. - 3. Process a render quantum. + + 3. Process the regular event queue. + + 1. Let <var>task count</var> be the number of tasks in the task queue of + the task queue of the {{AudioContext}} being rendered. + + 2. Spin the event loop until <var>task count</var> tasks have been executed. + + 4. Process a render quantum. 1. If the <a>rendering thread state</a> of the {{BaseAudioContext}} is not <code>running</code>, return false. @@ -11311,9 +11329,9 @@ operation such as resolution of {{Promise}}s in the {{AudioWorkletGlobalScope}}. 7. Set <var>render result</var> to <code>true</code>. - 4. [=Perform a microtask checkpoint=]. + 5. [=Perform a microtask checkpoint=]. - 5. Return <var>render result</var>. + 6. Return <var>render result</var>. </div> <dfn id="mute">Muting</dfn> an {{AudioNode}} means that its From 2c6c1341ed102ae2b2c302b2a5d9480c1aff0cda Mon Sep 17 00:00:00 2001 From: Paul Adenot <paul@paul.cx> Date: Thu, 18 Feb 2021 18:54:11 +0100 Subject: [PATCH 2/3] Address review comments and clarify what is what with links --- index.bs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/index.bs b/index.bs index 59678d81e..643633bb8 100644 --- a/index.bs +++ b/index.bs @@ -11118,17 +11118,20 @@ in the algorithm of <a href="#rendering-a-graph">rendering a graph</a>. finished. </div> -The audio callback is also queued as a task in the -<a href="#control-message-queue">control message queue</a>. The UA MUST perform +The audio callback is also queued as a task in the <a + href="#control-message-queue">control message queue</a>. The UA MUST perform the following algorithms to process render quanta to fulfill such task by -filling up the requested buffer size. Along with the primary message queue, each -{{AudioContext}} has a regular task queue for tasks that are posted to -the rendering thread from the control thread. An additional microtask checkpoint -is performed after processing a render quantum to run any microtasks that might -have been queued during the execution of the `process` methods of -{{AudioWorkletProcessor}}. - -All tasks posted from an {{AudioWorkletNode}} are posted to this task queue. +filling up the requested buffer size. Along with the <a>control message +queue</a>, each {{AudioContext}} has a regular <a +href="https://html.spec.whatwg.org/multipage/webappapis.html#task-queue">task +queue</a>, called its <dfn for="BaseAudioContext">associated task queue</dfn> +for tasks that are posted to the rendering thread from the control thread. An +additional microtask checkpoint is performed after processing a render quantum +to run any microtasks that might have been queued during the execution of the +`process` methods of {{AudioWorkletProcessor}}. + +All tasks posted from an {{AudioWorkletNode}} are posted to the [=associated +task queue=] of its associated {{BaseAudioContext}}. <div id="rendering-initialization" algorithm="initialize rendering loop"> The following step MUST be performed once before the rendering loop starts. @@ -11139,7 +11142,7 @@ All tasks posted from an {{AudioWorkletNode}} are posted to this task queue. </div> <div id="rendering-a-graph" algorithm="rendering a graph"> - The following sterp MUST be performed when rendering a single render quantum. + The following steps MUST be performed when rendering a render quantum. 1. Let <var>render result</var> be <code>false</code>. @@ -11158,10 +11161,9 @@ All tasks posted from an {{AudioWorkletNode}} are posted to this task queue. 2. Remove the [=oldest message=] of <var>Q<sub>rendering</sub></var>. - 3. Process the regular event queue. + 3. Process the {{BaseAudioContext}}'s [=associated task queue=]. - 1. Let <var>task count</var> be the number of tasks in the task queue of - the task queue of the {{AudioContext}} being rendered. + 1. Let <var>task count</var> be the number of tasks in the task queue of the {{AudioContext}} being rendered. 2. Spin the event loop until <var>task count</var> tasks have been executed. From 61d56a4e766e8b6868a576860f08815dadb25fee Mon Sep 17 00:00:00 2001 From: Paul Adenot <paul@paul.cx> Date: Fri, 19 Feb 2021 18:42:03 +0100 Subject: [PATCH 3/3] Fix indent --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 643633bb8..7f9f006b7 100644 --- a/index.bs +++ b/index.bs @@ -11119,7 +11119,7 @@ in the algorithm of <a href="#rendering-a-graph">rendering a graph</a>. </div> The audio callback is also queued as a task in the <a - href="#control-message-queue">control message queue</a>. The UA MUST perform +href="#control-message-queue">control message queue</a>. The UA MUST perform the following algorithms to process render quanta to fulfill such task by filling up the requested buffer size. Along with the <a>control message queue</a>, each {{AudioContext}} has a regular <a