Skip to content

Commit

Permalink
webcodecs: Fix plane size for VideoFrames that transfer ArrayBuffers
Browse files Browse the repository at this point in the history
Before this change we would lose the last row of I420 frames with an odd
number of rows.

Bug: 379066963
Change-Id: I19c1459984645eda718e7e84fd3ccb773fea1f45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026685
Reviewed-by: Dale Curtis <[email protected]>
Commit-Queue: Eugene Zemtsov <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1383923}
  • Loading branch information
Djuffin authored and chromium-wpt-export-bot committed Nov 16, 2024
1 parent 7ada545 commit 100af9e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions webcodecs/transfering.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,44 @@ promise_test(async t => {
}, 'Test transfering ArrayBuffer to VideoFrame');


promise_test(async t => {
let fmt = 'I420';
const i420_planes = [0xAA, 0xBB, 0xCC];
let data = new Uint8Array(i420_planes);
let init = {
format: fmt,
timestamp: 1234,
codedWidth: 1,
codedHeight: 1,
visibleRect: {x: 0, y: 0, width: 1, height: 1},
transfer: [data.buffer]
};

let frame = new VideoFrame(data, init);
assert_equals(data.length, 0, 'data.length 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(i420_planes);
assert_equals(expected_data.length, size, 'expected_data size');
assert_equals(layout[0].stride, 1, 'layout[0].stride');
assert_equals(layout[0].offset, 0, 'layout[0].offset');
assert_equals(layout[1].stride, 1, 'layout[1].stride');
assert_equals(layout[1].offset, 1, 'layout[1].offset');
assert_equals(layout[2].stride, 1, 'layout[2].stride');
assert_equals(layout[2].offset, 2, 'layout[2].offset');
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 buffers to VideoFrame with uneven samples');

promise_test(async t => {
const rgb_plane = [
0xBA, 0xDF, 0x00, 0xD0, 0xBA, 0xDF, 0x01, 0xD0, 0xBA, 0xDF, 0x02, 0xD0,
Expand Down

0 comments on commit 100af9e

Please sign in to comment.