From 26c516501329475f78db73ab541ab3c470d6239d Mon Sep 17 00:00:00 2001 From: Chris Cunningham Date: Fri, 4 Jun 2021 01:48:45 -0700 Subject: [PATCH] Add exceptions to pending flush() promises. This unifies on behavior with ImageDecoder in providing some indication about why the flush was aborted. Fixes #188. Fixes #136. --- index.src.html | 193 ++++++++++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 83 deletions(-) diff --git a/index.src.html b/index.src.html index 47b99cd5..64f6edb7 100644 --- a/index.src.html +++ b/index.src.html @@ -214,15 +214,7 @@ Running a control message means performing a sequence of steps specified by the method -that enqueued the message. The steps of a control message may depend on -injected state, supplied by the method that enqueued the message. - -Resetting the control message - queue means performing these steps: -1. For each [=control message=] in the [=control message queue=]: - 1. If a control message's [=injected state=] includes a promise, reject - that promise. - 2. Remove the message from the queue. +that enqueued the message. The codec processing loop must run these steps: 1. While true: @@ -270,6 +262,8 @@ :: A boolean indicating that the next chunk passed to {{AudioDecoder/decode()}} must describe a [=key chunk=] as indicated by {{EncodedAudioChunk/type}}. +: [[pending flush promises]] +:: A list of unresolved promises returned by calls to {{AudioDecoder/flush()}}. Constructors {#audiodecoder-constructors} ----------------------------------------- @@ -377,7 +371,8 @@ 2. Set {{AudioDecoder/[[key chunk required]]}} to `true`. 3. Let |promise| be a new Promise. 4. [=Queue a control message=] to flush the codec with |promise|. - 5. Return |promise|. + 5. Append |promise| to {{AudioDecoder/[[pending flush promises]]}}. + 6. Return |promise|. [=Running a control message=] to flush the codec means performing these steps with |promise|. @@ -388,7 +383,9 @@ 3. If |decoded outputs| is not empty, queue a task on the [=control thread=] event loop to run the [=Output AudioData=] algorithm with |decoded outputs|. - 4. Queue a task on the [=control thread=] event loop to resolve |promise|. + 4. Queue a task on the [=control thread=] event loop to run these steps: + 1. Remove |promise| from {{AudioDecoder/[[pending flush promises]]}}. + 2. Resolve |promise|.
reset()
@@ -397,7 +394,8 @@ [=control messages=] in the [=control message queue=], and all pending callbacks. - When invoked, run the [=Reset AudioDecoder=] algorithm. + When invoked, run the [=Reset AudioDecoder=] algorithm with an + {{AbortError}} {{DOMException}}.
close()
@@ -405,7 +403,8 @@ Immediately aborts all pending work and releases [=system resources=]. Close is final. - When invoked, run the [=Close AudioDecoder=] algorithm. + When invoked, run the [=Close AudioDecoder=] algorithm with an + {{AbortError}} {{DOMException}}.
isConfigSupported(config)
@@ -459,25 +458,28 @@ {{AudioData/[[number of channels]]}} as determined by |output|. 3. Invoke {{AudioDecoder/[[output callback]]}} with |data|. -
Reset AudioDecoder
+
Reset AudioDecoder (with |exception|)
Run these steps: 1. If {{AudioDecoder/state}} is `"closed"`, throw an {{InvalidStateError}}. 2. Set {{AudioDecoder/state}} to `"unconfigured"`. 3. Signal {{AudioDecoder/[[codec implementation]]}} to cease producing output for the previous configuration. - 4. [=Reset the control message queue=]. + 4. Remove all [=control messages=] from the [=control message queue=]. 5. Set {{AudioDecoder/decodeQueueSize}} to zero. + 6. For each |promise| in {{AudioDecoder/[[pending flush promises]]}}: + 1. Reject |promise| with |exception|. + 2. Remove |promise| from {{AudioDecoder/[[pending flush promises]]}}.
-
Close AudioDecoder (with error)
+
Close AudioDecoder (with |exception|)
Run these steps: - 1. Run the [=Reset AudioDecoder=] algorithm. + 1. Run the [=Reset AudioDecoder=] algorithm with |exception|. 2. Set {{AudioDecoder/state}} to `"closed"`. 3. Clear {{AudioDecoder/[[codec implementation]]}} and release associated [=system resources=]. - 4. If |error| is set, queue a task on the [=control thread=] event loop to - invoke the {{AudioDecoder/[[error callback]]}} with |error|. + 4. If |exception| is not an {{AbortError}} {{DOMException}}, queue a task on + the [=control thread=] event loop to invoke the {{AudioDecoder/[[error callback]]}} with |exception|.
@@ -522,6 +524,9 @@ : [[key chunk required]] :: A boolean indicating that the next chunk passed to {{VideoDecoder/decode()}} must describe a [=key chunk=] as indicated by {{EncodedVideoChunk/type}}. +: [[pending flush promises]] +:: A list of unresolved promises returned by calls to {{VideoDecoder/flush()}}. + Constructors {#videodecoder-constructors} ----------------------------------------- @@ -635,7 +640,8 @@ 2. Set {{VideoDecoder/[[key chunk required]]}} to `true`. 3. Let |promise| be a new Promise. 4. [=Queue a control message=] to flush the codec with |promise|. - 5. Return |promise|. + 5. Append |promise| to {{VideoDecoder/[[pending flush promises]]}}. + 6. Return |promise|. [=Running a control message=] to flush the codec means performing these steps with |promise|. @@ -646,7 +652,9 @@ 3. If |decoded outputs| is not empty, queue a task on the [=control thread=] event loop to run the [=Output VideoFrames=] algorithm with |decoded outputs|. - 4. Queue a task on the [=control thread=] event loop to resolve |promise|. + 4. Queue a task on the [=control thread=] event loop to run these steps: + 1. Remove |promise| from {{VideoDecoder/[[pending flush promises]]}}. + 2. Resolve |promise|.
reset()
@@ -655,7 +663,8 @@ [=control messages=] in the [=control message queue=], and all pending callbacks. - When invoked, run the [=Reset VideoDecoder=] algorithm. + When invoked, run the [=Reset VideoDecoder=] algorithm with an + {{AbortError}} {{DOMException}}.
close()
@@ -663,7 +672,8 @@ Immediately aborts all pending work and releases [=system resources=]. Close is final. - When invoked, run the [=Close VideoDecoder=] algorithm. + When invoked, run the [=Close VideoDecoder=] algorithm with an + {{AbortError}} {{DOMException}}.
isConfigSupported(config)
@@ -715,25 +725,29 @@ and |displayAspectHeight|. 5. Invoke {{VideoDecoder/[[output callback]]}} with |frame|. -
Reset VideoDecoder
+
Reset VideoDecoder (with |exception|)
Run these steps: 1. If {{VideoDecoder/state}} is `"closed"`, throw an {{InvalidStateError}}. 2. Set {{VideoDecoder/state}} to `"unconfigured"`. 3. Signal {{VideoDecoder/[[codec implementation]]}} to cease producing output for the previous configuration. - 4. [=Reset the control message queue=]. + 4. Remove all [=control messages=] from the [=control message queue=]. 5. Set {{VideoDecoder/decodeQueueSize}} to zero. + 6. For each |promise| in {{VideoDecoder/[[pending flush promises]]}}: + 1. Reject |promise| with |exception|. + 2. Remove |promise| from {{VideoDecoder/[[pending flush promises]]}}.
-
Close VideoDecoder (with |error|)
+
Close VideoDecoder (with |exception|)
Run these steps: - 1. Run the [=Reset VideoDecoder=] algorithm. + 1. Run the [=Reset VideoDecoder=] algorithm with |exception|. 2. Set {{VideoDecoder/state}} to `"closed"`. 3. Clear {{VideoDecoder/[[codec implementation]]}} and release associated [=system resources=]. - 4. If |error| is set, queue a task on the [=control thread=] event loop to - invoke the {{VideoDecoder/[[error callback]]}} with |error|. + 4. If |exception| is not an {{AbortError}} {{DOMException}}, queue a task on + the [=control thread=] event loop to invoke the + {{VideoDecoder/[[error callback]]}} with |exception|.
@@ -770,21 +784,19 @@ Internal Slots {#audioencoder-internal-slots} --------------------------------------------- -
-
[[codec implementation]]
-
Underlying encoder implementation provided by the User Agent.
-
[[output callback]]
-
Callback given at construction for encoded outputs.
-
[[error callback]]
-
Callback given at construction for encode errors.
-
[[active encoder config]]
-
The {{AudioEncoderConfig}} that is actively applied.
-
[[active output config]]
-
- The {{AudioDecoderConfig}} that describes how to decode the most recently - emitted {{EncodedAudioChunk}}. -
-
+: [[codec implementation]] +:: Underlying encoder implementation provided by the User Agent. +: [[output callback]] +:: Callback given at construction for encoded outputs. +: [[error callback]] +:: Callback given at construction for encode errors. +: [[active encoder config]] +:: The {{AudioEncoderConfig}} that is actively applied. +: [[active output config]] +:: The {{AudioDecoderConfig}} that describes how to decode the most recently + emitted {{EncodedAudioChunk}}. +: [[pending flush promises]] +:: A list of unresolved promises returned by calls to {{AudioEncoder/flush()}}. Constructors {#audioencoder-constructors} ----------------------------------------- @@ -885,7 +897,8 @@ [=a promise rejected with=] {{InvalidStateError}} {{DOMException}}. 2. Let |promise| be a new Promise. 3. [=Queue a control message=] to flush the codec with |promise|. - 4. Return |promise|. + 4. Append |promise| to {{AudioEncoder/[[pending flush promises]]}}. + 5. Return |promise|. [=Running a control message=] to flush the codec means performing these steps with |promise|. @@ -893,10 +906,12 @@ pending outputs=]. 2. Let |encoded outputs| be a [=list=] of encoded audio data outputs emitted by {{AudioEncoder/[[codec implementation]]}}. - 5. If |encoded outputs| is not empty, queue a task on the [=control thread=] + 3. If |encoded outputs| is not empty, queue a task on the [=control thread=] event loop to run the [=Output EncodedAudioChunks=] algorithm with |encoded outputs|. - 3. Queue a task on the [=control thread=] event loop to resolve |promise|. + 4. Queue a task on the [=control thread=] event loop to run these steps: + 1. Remove |promise| from {{AudioEncoder/[[pending flush promises]]}}. + 2. Resolve |promise|.
reset()
@@ -905,7 +920,8 @@ [=control messages=] in the [=control message queue=], and all pending callbacks. - When invoked, run the [=Reset AudioEncoder=] algorithm. + When invoked, run the [=Reset AudioEncoder=] algorithm with an + {{AbortError}} {{DOMException}}.
close()
@@ -913,7 +929,8 @@ Immediately aborts all pending work and releases [=system resources=]. Close is final. - When invoked, run the [=Close AudioEncoder=] algorithm. + When invoked, run the [=Close AudioEncoder=] algorithm with an + {{AbortError}} {{DOMException}}.
isConfigSupported(config)
@@ -994,7 +1011,7 @@ 7. Invoke {{AudioEncoder/[[output callback]]}} with |chunk| and |chunkMetadata|. -
Reset AudioEncoder
+
Reset AudioEncoder (with |exception|)
Run these steps: 1. If {{AudioEncoder/state}} is `"closed"`, throw an {{InvalidStateError}}. @@ -1003,18 +1020,22 @@ 4. Set {{AudioEncoder/[[active output config]]}} to `null`. 5. Signal {{AudioEncoder/[[codec implementation]]}} to cease producing output for the previous configuration. - 6. [=Reset the control message queue=]. + 6. Remove all [=control messages=] from the [=control message queue=]. 7. Set {{AudioEncoder/encodeQueueSize}} to zero. + 8. For each |promise| in {{AudioEncoder/[[pending flush promises]]}}: + 1. Reject |promise| with |exception|. + 2. Remove |promise| from {{AudioEncoder/[[pending flush promises]]}}.
-
Close AudioEncoder (with |error|)
+
Close AudioEncoder (with |exception|)
Run these steps: - 1. Run the [=Reset AudioEncoder=] algorithm. + 1. Run the [=Reset AudioEncoder=] algorithm with |exception|. 2. Set {{AudioEncoder/state}} to `"closed"`. 3. Clear {{AudioEncoder/[[codec implementation]]}} and release associated [=system resources=]. - 4. If |error| is set, queue a task on the [=control thread=] event loop - invoke the {{AudioEncoder/[[error callback]]}} with |error|. + 4. If |exception| is not an {{AbortError}} {{DOMException}}, queue a task on + the [=control thread=] event loop to invoke the + {{AudioDecoder/[[error callback]]}} with |exception|.
@@ -1067,21 +1088,19 @@ Internal Slots {#videoencoder-internal-slots} --------------------------------------------- -
-
[[codec implementation]]
-
Underlying encoder implementation provided by the User Agent.
-
[[output callback]]
-
Callback given at construction for encoded outputs.
-
[[error callback]]
-
Callback given at construction for encode errors.
-
[[active encoder config]]
-
The {{VideoEncoderConfig}} that is actively applied.
-
[[active output config]]
-
- The {{VideoDecoderConfig}} that describes how to decode the most recently - emitted {{EncodedVideoChunk}}. -
-
+: [[codec implementation]] +:: Underlying encoder implementation provided by the User Agent. +: [[output callback]] +:: Callback given at construction for encoded outputs. +: [[error callback]] +:: Callback given at construction for encode errors. +: [[active encoder config]] +:: The {{VideoEncoderConfig}} that is actively applied. +: [[active output config]] +:: The {{VideoDecoderConfig}} that describes how to decode the most recently + emitted {{EncodedVideoChunk}}. +: [[pending flush promises]] +:: A list of unresolved promises returned by calls to {{VideoEncoder/flush()}}. Constructors {#videoencoder-constructors} ----------------------------------------- @@ -1181,7 +1200,8 @@ [=a promise rejected with=] {{InvalidStateError}} {{DOMException}}. 2. Let |promise| be a new Promise. 3. [=Queue a control message=] to flush the codec with |promise|. - 4. Return |promise|. + 4. Append |promise| to {{VideoEncoder/[[pending flush promises]]}}. + 5. Return |promise|. [=Running a control message=] to flush the codec means performing these steps with |promise|. @@ -1189,10 +1209,12 @@ pending outputs=]. 2. Let |encoded outputs| be a [=list=] of encoded video data outputs emitted by {{VideoEncoder/[[codec implementation]]}}. - 5. If |encoded outputs| is not empty, queue a task on the [=control thread=] + 3. If |encoded outputs| is not empty, queue a task on the [=control thread=] event loop to run the [=Output EncodedVideoChunks=] algorithm with |encoded outputs|. - 3. Queue a task on the [=control thread=] event loop to resolve |promise|. + 4. Queue a task on the [=control thread=] event loop to run these steps: + 1. Remove |promise| from {{VideoEncoder/[[pending flush promises]]}}. + 2. Resolve |promise|.
reset()
@@ -1201,7 +1223,8 @@ [=control messages=] in the [=control message queue=], and all pending callbacks. - When invoked, run the [=Reset VideoEncoder=] algorithm. + When invoked, run the [=Reset VideoEncoder=] algorithm with an + {{AbortError}} {{DOMException}}.
close()
@@ -1209,7 +1232,8 @@ Immediately aborts all pending work and releases [=system resources=]. Close is final. - When invoked, run the [=Close VideoEncoder=] algorithm. + When invoked, run the [=Close VideoEncoder=] algorithm with an + {{AbortError}} {{DOMException}}.
isConfigSupported(config)
@@ -1299,7 +1323,7 @@ 8. Invoke {{VideoEncoder/[[output callback]]}} with |chunk| and |chunkMetadata|. -
Reset VideoEncoder
+
Reset VideoEncoder (with |exception|)
Run these steps: 1. If {{VideoEncoder/state}} is `"closed"`, throw an {{InvalidStateError}}. @@ -1308,18 +1332,21 @@ 4. Set {{VideoEncoder/[[active output config]]}} to `null`. 5. Signal {{VideoEncoder/[[codec implementation]]}} to cease producing output for the previous configuration. - 6. [=Reset the control message queue=]. + 6. Remove all [=control messages=] from the [=control message queue=]. 7. Set {{VideoEncoder/encodeQueueSize}} to zero. + 8. For each |promise| in {{VideoEncoder/[[pending flush promises]]}}: + 1. Reject |promise| with |exception|. + 2. Remove |promise| from {{VideoEncoder/[[pending flush promises]]}}.
-
Close VideoEncoder (with |error|)
+
Close VideoEncoder (with |exception|)
Run these steps: - 1. Run the [=Reset VideoEncoder=] algorithm. + 1. Run the [=Reset VideoEncoder=] algorithm with |exception|. 2. Set {{VideoEncoder/state}} to `"closed"`. 3. Clear {{VideoEncoder/[[codec implementation]]}} and release associated [=system resources=]. - 4. If |error| is set, queue a task on the [=control thread=] event loop - invoke the {{VideoEncoder/[[error callback]]}} with |error|. + 4. If |exception| is not an {{AbortError}} {{DOMException}}, queue a task on + the [=control thread=] event loop to invoke the {{AudioDecoder/[[error callback]]}} with |exception|.
@@ -3221,14 +3248,14 @@ :: Immediately aborts all pending work. When invoked, run the [=ImageDecoder/Reset ImageDecoder=] algorithm with - and {{AbortError}} {{DOMException}}. + an {{AbortError}} {{DOMException}}. : close() :: Immediately aborts all pending work and releases system resources. Close is final. When invoked, run the [=ImageDecoder/Close ImageDecoder=] algorithm with - and {{AbortError}} {{DOMException}}. + an {{AbortError}} {{DOMException}}. : isTypeSupported(type) :: Returns a promise indicating whether the provided config is supported by the