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

Method encode

src/video_encoder.ts:309–327  ·  view source on GitHub ↗

* Queues a video frame to be encoded.

(frame: VideoFrame, options?: VideoEncoderEncodeOptions)

Source from the content-addressed store, hash-verified

307 * Queues a video frame to be encoded.
308 */
309 encode(frame: VideoFrame, options?: VideoEncoderEncodeOptions) {
310 // Spec 6.5: If the value of frame's [[Detached]] internal slot is true, throw a TypeError.
311 // (VideoFramePolyfill usually throws on access if detached, but explicit check is good)
312
313 // Spec 6.5: If [[state]] is not "configured", throw an InvalidStateError.
314 if (this._state !== 'configured') {
315 throw new DOMException('Encoder is not configured', 'InvalidStateError');
316 }
317
318 // Spec 6.5: Let frameClone hold the result of running the Clone VideoFrame algorithm with frame.
319 const clonedFrame = frame.clone();
320
321 // Spec 6.5: Increment [[encodeQueueSize]].
322 this._encodeQueueSize++;
323
324 // Spec 6.5: Queue a control message to encode frameClone.
325 this.encodeInternal(clonedFrame, options)
326 .catch(e => this.handleAsyncError(e));
327 }
328
329 private outputChunk(currentConfigId: number) {
330 if (this.currentConfigId !== currentConfigId) {

Callers 2

Calls 3

encodeInternalMethod · 0.95
handleAsyncErrorMethod · 0.95
cloneMethod · 0.45

Tested by

no test coverage detected