1import {2 MAX_FRAME_DIMENSION,3 MAX_FRAME_PIXELS,4} from './frame-envelope.mjs';56/** Build the exact low-latency WebCodecs configuration used by every codec. */7export function buildVideoDecoderConfig({ codec, width, height, description }) {8 if (typeof codec !== 'string' || codec.trim().length === 0) {9 throw new TypeError('video decoder codec must be a non-empty string');10 }11 if (12 !Number.isSafeInteger(width) ||13 !Number.isSafeInteger(height) ||14 width <= 0 ||15 height <= 0 ||16 width > MAX_FRAME_DIMENSION ||17 height > MAX_FRAME_DIMENSION ||18 width * height > MAX_FRAME_PIXELS19 ) {20 throw new RangeError(`invalid video decoder dimensions: ${width}x${height}`);21 }22 if (!(description instanceof ArrayBuffer) && !ArrayBuffer.isView(description)) {23 throw new TypeError('video decoder description must be a BufferSource');24 }2526 return {27 codec,28 codedWidth: width,29 codedHeight: height,30 description,31 optimizeForLatency: true,32 };33}