// The payload framings a WAI track carries (SPEC ยง5), round-tripped // (`node --test web/moq/media.test.mjs`). import test from "node:test"; import assert from "node:assert/strict"; import * as media from "./media.js"; test("an IVF file of one VP9 frame", () => { const f = Uint8Array.from([0x82, 0x49, 0x83, 0x42, 0x00]); const b = media.ivfOne(f, 320, 240, 66666); assert.equal(String.fromCharCode(...b.subarray(0, 4)), "DKIF"); assert.equal(String.fromCharCode(...b.subarray(8, 12)), "VP90"); assert.deepEqual(media.ivfFrames(b), [{ data: f, timestamp: 66666 }]); }); test("an AV1 payload of one temporal unit", () => { const tu = Uint8Array.from([0x12, 0x00, 0x0a, 0x0b]); const b = media.av1One(tu, 320, 240, 15, 1); assert.deepEqual(media.av1Units(b), [tu]); assert.throws(() => media.av1Units(Uint8Array.from([...b, 0]))); }); test("an Ogg Opus stream of one packet, its CRCs checked", () => { const pk = Uint8Array.from({ length: 300 }, (_, i) => i & 0xff); const b = media.oggOpusOne(pk, { channels: 1, samples: 960 }); assert.deepEqual(media.oggOpusPackets(b), [pk]); // The first page's CRC, for "OpusHead" with these fields, is the Ogg CRC-32 of RFC 3533. const bad = b.slice(); bad[40] ^= 1; assert.throws(() => media.oggOpusPackets(bad), /CRC/); }); test("a manifest names its capability and keeps its member order", () => { const m = JSON.parse(media.manifestFor("wai.video.vp9", { width: 320, height: 240, key: true })); assert.deepEqual(Object.keys(m), ["wai", "media", "intent", "model_requirement", "conditioning", "target"]); assert.equal(m.model_requirement.capability, "wai.video.vp9"); assert.equal(media.CAPABILITY_OF("av01.0.04M.08"), "wai.video.av1"); });