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

Method close

src/video_encoder.ts:632–659  ·  view source on GitHub ↗

* Closes the encoder and releases all resources.

()

Source from the content-addressed store, hash-verified

630 * Closes the encoder and releases all resources.
631 */
632 close() {
633 // Spec 6.6: Close VideoEncoder (with exception)
634 // 1. Run the Reset VideoEncoder algorithm with exception.
635 // 2. Set state to "closed".
636 // 3. Clear [[codec implementation]] and release associated system resources.
637 // 4. If exception is not an AbortError DOMException, invoke the [[error callback]] with exception.
638
639 this._state = 'closed';
640 this.currentConfigId++;
641
642 if (this._encodeQueueSize > 0) {
643 this._encodeQueueSize = 0;
644 this.decrementQueue();
645 }
646
647 for (const p of this.pendingFlushResolvers) {
648 p.reject(new DOMException('Encoder closed', 'AbortError'));
649 }
650 this.pendingFlushResolvers = [];
651
652 this.codecContext?.freeContext();
653 this.codecContext = null;
654 this.ondequeue = null;
655 this.frame.free();
656 this.packet.free();
657 this.scaler?.freeContext();
658 this.dstFrame?.free();
659 }
660
661 /**
662 * Resets the encoder to an unconfigured state.

Callers 2

handleAsyncErrorMethod · 0.95
encodeInternalMethod · 0.45

Calls 1

decrementQueueMethod · 0.95

Tested by

no test coverage detected