MCPcopy Create free account
hub / github.com/Vanilagy/webcodecs-polyfill / reset

Method reset

src/audio_encoder.ts:650–683  ·  view source on GitHub ↗

* Resets the encoder to an unconfigured state.

()

Source from the content-addressed store, hash-verified

648 * Resets the encoder to an unconfigured state.
649 */
650 reset() {
651 // Spec: Reset AudioEncoder (with exception)
652 // 1. If state is "closed", throw an InvalidStateError.
653 if (this._state === 'closed') {
654 throw new DOMException('Cannot reset closed encoder', 'InvalidStateError');
655 }
656
657 // 2. Set state to "unconfigured".
658 this._state = 'unconfigured';
659
660 // 3. Signal [[codec implementation]] to cease producing output (invalidate ID).
661 this.currentConfigId++;
662
663 // 4. Remove all control messages (handled by ID check).
664
665 // 5. If [[encodeQueueSize]] is greater than zero...
666 if (this._encodeQueueSize > 0) {
667 this._encodeQueueSize = 0;
668 this.decrementQueue();
669 }
670
671 // 6. For each promise in [[pending flush promises]]: Reject promise with exception.
672 for (const p of this.pendingFlushResolvers) {
673 p.reject(new DOMException('Encoder reset', 'AbortError'));
674 }
675 this.pendingFlushResolvers = [];
676
677 this.config = null;
678 this.codecContext?.freeContext();
679 this.codecContext = null;
680 this.chunkOutputted = false;
681 this.aacAudioSpecificConfig = null;
682 this.resampledSampleCount = 0;
683 }
684
685 private handleAsyncError(e: unknown) {
686 const error = e instanceof DOMException

Callers

nothing calls this directly

Calls 1

decrementQueueMethod · 0.95

Tested by

no test coverage detected