// META: global=window,dedicatedworker // META: script=/webcodecs/utils.js // META: script=/webcodecs/videoFrame-utils.js test(t => { let image = makeImageBitmap(32, 16); let frame = new VideoFrame(image, {timestamp: 10}); assert_equals(frame.timestamp, 10, 'timestamp'); assert_equals(frame.duration, null, 'duration'); assert_equals(frame.visibleRect.width, 32, 'visibleRect.width'); assert_equals(frame.visibleRect.height, 16, 'visibleRect.height'); assert_equals(frame.displayWidth, 32, 'displayWidth'); assert_equals(frame.displayHeight, 16, 'displayHeight'); frame.close(); }, 'Test we can construct a VideoFrame.'); test(t => { let image = makeImageBitmap(32, 16); let frame = new VideoFrame(image, {timestamp: 10, duration: 15}); frame.close(); assert_equals(frame.format, null, 'format') assert_equals(frame.timestamp, 10, 'timestamp'); assert_equals(frame.duration, 15, 'duration'); assert_equals(frame.codedWidth, 0, 'codedWidth'); assert_equals(frame.codedHeight, 0, 'codedHeight'); assert_equals(frame.visibleRect, null, 'visibleRect'); assert_equals(frame.displayWidth, 0, 'displayWidth'); assert_equals(frame.displayHeight, 0, 'displayHeight'); assert_equals(frame.colorSpace.primaries, null, 'colorSpace.primaries'); assert_equals(frame.colorSpace.transfer, null, 'colorSpace.transfer'); assert_equals(frame.colorSpace.matrix, null, 'colorSpace.matrix'); assert_equals(frame.colorSpace.fullRange, null, 'colorSpace.fullRange'); assert_true(isFrameClosed(frame)); assert_throws_dom('InvalidStateError', () => frame.clone()); }, 'Test closed VideoFrame.'); test(t => { let image = makeImageBitmap(32, 16); let frame = new VideoFrame(image, {timestamp: -10}); assert_equals(frame.timestamp, -10, 'timestamp'); frame.close(); }, 'Test we can construct a VideoFrame with a negative timestamp.'); promise_test(async t => { verifyTimestampRequiredToConstructFrame(makeImageBitmap(1, 1)); }, 'Test that timestamp is required when constructing VideoFrame from ImageBitmap'); promise_test(async t => { verifyTimestampRequiredToConstructFrame(makeOffscreenCanvas(16, 16)); }, 'Test that timestamp is required when constructing VideoFrame from OffscreenCanvas'); promise_test(async t => { let init = { format: 'I420', timestamp: 1234, codedWidth: 4, codedHeight: 2 }; let data = new Uint8Array([ 1, 2, 3, 4, 5, 6, 7, 8, // y 1, 2, // u 1, 2, // v ]); let i420Frame = new VideoFrame(data, init); let validFrame = new VideoFrame(i420Frame); validFrame.close(); }, 'Test that timestamp is NOT required when constructing VideoFrame from another VideoFrame'); test(t => { let image = makeImageBitmap(1, 1); let frame = new VideoFrame(image, {timestamp: 10}); assert_equals(frame.visibleRect.width, 1, 'visibleRect.width'); assert_equals(frame.visibleRect.height, 1, 'visibleRect.height'); assert_equals(frame.displayWidth, 1, 'displayWidth'); assert_equals(frame.displayHeight, 1, 'displayHeight'); frame.close(); }, 'Test we can construct an odd-sized VideoFrame.'); test(t => { // Test only valid for Window contexts. if (!('document' in self)) return; let video = document.createElement('video'); assert_throws_dom('InvalidStateError', () => { let frame = new VideoFrame(video, {timestamp: 10}); }) }, 'Test constructing w/ unusable image argument throws: HAVE_NOTHING