diff --git a/webcodecs/videoFrame-construction.any.js b/webcodecs/videoFrame-construction.any.js index d6374c11d181fc..893c40822f9178 100644 --- a/webcodecs/videoFrame-construction.any.js +++ b/webcodecs/videoFrame-construction.any.js @@ -755,3 +755,41 @@ test(t => { frame.close(); }, 'Test a VideoFrame constructed from canvas can drop the alpha channel.'); +promise_test(async t => { + let fmt = 'RGBA'; + const rgb_plane = [ + 0xBA, 0xDF, 0x00, 0xD0, 0xBA, 0xDF, 0x01, 0xD0, 0xBA, 0xDF, 0x02, 0xD0, + 0xBA, 0xDF, 0x03, 0xD0 + ]; + let data = new Uint8Array(rgb_plane); + let unused_buffer = new ArrayBuffer(123); + let init = { + format: fmt, + timestamp: 1234, + codedWidth: 2, + codedHeight: 2, + visibleRect: {x: 0, y: 0, width: 2, height: 2}, + transfer: [data.buffer, unused_buffer] + }; + assert_equals(data.length, 16, 'data.length'); + assert_equals(unused_buffer.byteLength, 123, 'unused_buffer.byteLength'); + + let frame = new VideoFrame(data, init); + assert_equals(frame.format, fmt, 'format'); + assert_equals(data.length, 0, 'data.length after detach'); + assert_equals(unused_buffer.byteLength, 0, 'unused_buffer after detach'); + + const options = { + rect: {x: 0, y: 0, width: init.codedWidth, height: init.codedHeight} + }; + let size = frame.allocationSize(options); + let output_data = new Uint8Array(size); + let layout = await frame.copyTo(output_data, options); + let expected_data = new Uint8Array(rgb_plane); + assert_equals(expected_data.length, size, 'expected_data size'); + for (let i = 0; i < size; i++) { + assert_equals(expected_data[i], output_data[i], `expected_data[${i}]`); + } + + frame.close(); +}, 'Test transfering ArrayBuffer to VideoFrame');