Skip to content

Commit

Permalink
webcodecs: Transfer array buffer into VideoFrame ctor
Browse files Browse the repository at this point in the history
Implementation for w3c/webcodecs#104

Change-Id: Ifbc1fb1739a0bc19dc6db27943fff0cecae0156d
  • Loading branch information
Djuffin authored and chromium-wpt-export-bot committed May 17, 2023
1 parent d31af2b commit 8ef3589
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions webcodecs/videoFrame-construction.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 8ef3589

Please sign in to comment.