Skip to content

Commit

Permalink
VideoFrame buffer constructor doesn't respect codedWidth if visibleRe…
Browse files Browse the repository at this point in the history
…ct is present

https://bugs.webkit.org/show_bug.cgi?id=256848
rdar://109724698

Reviewed by Eric Carlson.

Use codedWidth and codedHeight instead of parsedRect.
This is coherent with the rest of the algorithm like checking the array size and is consistent with what Chrome does.
I filed w3c/webcodecs#702 to update the spec.

* LayoutTests/http/wpt/webcodecs/videoFrame-with-stride-expected.txt: Added.
* LayoutTests/http/wpt/webcodecs/videoFrame-with-stride.html: Added.
* Source/WebCore/Modules/webcodecs/WebCodecsVideoFrame.cpp:
(WebCore::WebCodecsVideoFrame::create):

Canonical link: https://commits.webkit.org/265844@main
  • Loading branch information
youennf committed Jul 7, 2023
1 parent 42d2cdb commit e919dcf
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PASS Creating video frames Creating video frames Creating video frames with codedWidth differing from visibleWidthh

63 changes: 63 additions & 0 deletions LayoutTests/http/wpt/webcodecs/videoFrame-with-stride.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script src='/webcodecs/videoFrame-utils.js'></script>
</head>
<body>
<canvas id=canvas width=100px hwight=100px></canvas>
<script>
function createVideoFrame(stride)
{
const width = 16;
const height = 16;
const size = stride * height;
const buf = new ArrayBuffer(size * 1.5);
const bytesY = new Uint8Array(buf, 0, size * 1.0);
const bytesU = new Uint8Array(buf, size * 1.0, size * 0.25);
const bytesV = new Uint8Array(buf, size * 1.25, size * 0.25);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++)
bytesY[y * stride + x] = (y << 4) | x;
}
bytesU.fill(128);
bytesV.fill(128);

return new VideoFrame(buf, {
format: "I420",
codedWidth: stride,
codedHeight: height,
timestamp: 0,
visibleRect: {
x: 0,
y: 0,
width: width,
height: height
},
colorSpace: {
primaries: 'bt709',
transfer: 'bt709',
matrix: 'bt709',
fullRange: true,
}
});
}

test(t => {
const frame1 = createVideoFrame(16);
t.add_cleanup(() => frame1.close());
const frame2 = createVideoFrame(32);
t.add_cleanup(() => frame2.close());

canvas.getContext('2d').drawImage(frame1, 0, 0);
const data1 = canvas.getContext('2d').getImageData(0, 0, 4, 2).data;

canvas.getContext('2d').drawImage(frame2, 0, 0);
const data2 = canvas.getContext('2d').getImageData(0, 0, 4, 2).data;

assert_array_equals(data1, data2);
}, 'Creating video frames Creating video frames Creating video frames with codedWidth differing from visibleWidthh');
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/webcodecs/WebCodecsVideoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ ExceptionOr<Ref<WebCodecsVideoFrame>> WebCodecsVideoFrame::create(ScriptExecutio
return parsedRectOrExtension.releaseException();

auto parsedRect = parsedRectOrExtension.releaseReturnValue();
auto layoutOrException = computeLayoutAndAllocationSize(parsedRect, init.layout, init.format);
auto layoutOrException = computeLayoutAndAllocationSize(defaultRect, init.layout, init.format);
if (layoutOrException.hasException())
return layoutOrException.releaseException();

Expand Down

0 comments on commit e919dcf

Please sign in to comment.