| 14 | * Corresponds to the WebCodecs EncodedVideoChunk API. |
| 15 | */ |
| 16 | export class EncodedVideoChunkPolyfill { |
| 17 | /** |
| 18 | * Whether this chunk is a key frame ("key") or delta frame ("delta"). |
| 19 | */ |
| 20 | readonly type: EncodedVideoChunkType; |
| 21 | /** |
| 22 | * The timestamp in integer microseconds. |
| 23 | */ |
| 24 | readonly timestamp: number; |
| 25 | /** |
| 26 | * The duration in integer microseconds, or null if not specified. |
| 27 | */ |
| 28 | readonly duration: number | null; |
| 29 | /** |
| 30 | * The size of the encoded data in bytes. |
| 31 | */ |
| 32 | readonly byteLength: number; |
| 33 | |
| 34 | private data: Uint8Array; |
| 35 | |
| 36 | /** |
| 37 | * Creates a new EncodedVideoChunk. |
| 38 | */ |
| 39 | constructor(init: EncodedVideoChunkInit) { |
| 40 | if (init.type !== 'key' && init.type !== 'delta') { |
| 41 | throw new TypeError(`type must be 'key' or 'delta'.`); |
| 42 | } |
| 43 | if (!Number.isFinite(init.timestamp)) { |
| 44 | throw new TypeError(`timestamp must be a finite number.`); |
| 45 | } |
| 46 | if (init.duration !== undefined && !Number.isFinite(init.duration)) { |
| 47 | throw new TypeError(`duration must be a finite number if specified.`); |
| 48 | } |
| 49 | if (!( |
| 50 | init.data instanceof ArrayBuffer |
| 51 | || (typeof SharedArrayBuffer !== 'undefined' && init.data instanceof SharedArrayBuffer) |
| 52 | || ArrayBuffer.isView(init.data)) |
| 53 | ) { |
| 54 | throw new TypeError(`data must be an ArrayBuffer, SharedArrayBuffer, or ArrayBufferView.`); |
| 55 | } |
| 56 | |
| 57 | this.type = init.type; |
| 58 | this.timestamp = Math.trunc(init.timestamp); |
| 59 | this.duration = init.duration !== undefined |
| 60 | ? Math.trunc(init.duration) |
| 61 | : null; |
| 62 | this.byteLength = init.data.byteLength; |
| 63 | this.data = toUint8Array(init.data).slice(); // Clone the data |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Copies the encoded chunk data to a destination buffer. |
| 68 | */ |
| 69 | copyTo(destination: AllowSharedBufferSource) { |
| 70 | if (destination.byteLength < this.data.byteLength) { |
| 71 | throw new TypeError('Destination buffer is too small.'); |
| 72 | } |
| 73 |
nothing calls this directly
no outgoing calls
no test coverage detected