videoFrame-odd-size.any.js (1556B)
1 // META: global=window,dedicatedworker 2 // META: script=/webcodecs/videoFrame-utils.js 3 4 test(t => { 5 let fmt = 'I420'; 6 let vfInit = { 7 format: fmt, 8 timestamp: 1234, 9 codedWidth: 3, 10 codedHeight: 3, 11 visibleRect: {x: 0, y: 0, width: 3, height: 3}, 12 }; 13 let data = new Uint8Array([ 14 1, 2, 3, 4, 5, 6, 7, 8, 9, // y 15 1, 2, 3, 4, // u 16 1, 2, 3, 4, // v 17 ]); 18 let frame = new VideoFrame(data, vfInit); 19 assert_equals(frame.format, fmt, 'format'); 20 assert_equals(frame.visibleRect.x, 0, 'visibleRect.x'); 21 assert_equals(frame.visibleRect.y, 0, 'visibleRect.y'); 22 assert_equals(frame.visibleRect.width, 3, 'visibleRect.width'); 23 assert_equals(frame.visibleRect.height, 3, 'visibleRect.height'); 24 frame.close(); 25 }, 'Test I420 VideoFrame construction with odd coded size'); 26 27 promise_test(async t => { 28 const init = { 29 format: 'I420', 30 timestamp: 0, 31 codedWidth: 3, 32 codedHeight: 3, 33 }; 34 const buf = new Uint8Array([ 35 1, 2, 3, 4, 5, 6, 7, 8, 9, // y 36 10, 11, 12, 13, // u 37 14, 15, 16, 17, // v 38 ]); 39 const expectedLayout = [ 40 {offset: 0, stride: 3}, 41 {offset: 9, stride: 2}, 42 {offset: 13, stride: 2}, 43 ]; 44 const frame = new VideoFrame(buf, init); 45 assert_equals(frame.allocationSize(), buf.length, 'allocationSize()'); 46 const data = new Uint8Array(buf.length); 47 const layout = await frame.copyTo(data); 48 assert_layout_equals(layout, expectedLayout); 49 assert_buffer_equals(data, buf); 50 }, 'Test I420 copyTo with odd coded size.');