Skip to content

Commit

Permalink
[webcodecs] Rename regions concepts
Browse files Browse the repository at this point in the history
This CL renames "Region" to "Rect" and readInto() to copyTo().

Bug: 1176464
Change-Id: Ic2c494a54d9755f96272eecddb427ae4324f5099
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2961677
Commit-Queue: Dan Sanders <sandersd@chromium.org>
Reviewed-by: Chrome Cunningham <chcunningham@chromium.org>
Cr-Commit-Position: refs/heads/master@{#892753}
  • Loading branch information
Dan Sanders authored and chromium-wpt-export-bot committed Jun 15, 2021
1 parent 38ba3d8 commit f93078f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 93 deletions.
8 changes: 4 additions & 4 deletions webcodecs/video-frame-serialization.any.js
Expand Up @@ -20,10 +20,10 @@ test(t => {

assert_equals(frame.timestamp, clone.timestamp);
assert_equals(frame.duration, clone.duration);
assert_equals(frame.visibleRegion.left, clone.visibleRegion.left);
assert_equals(frame.visibleRegion.top, clone.visibleRegion.top);
assert_equals(frame.visibleRegion.width, clone.visibleRegion.width);
assert_equals(frame.visibleRegion.height, clone.visibleRegion.height);
assert_equals(frame.visibleRect.left, clone.visibleRect.left);
assert_equals(frame.visibleRect.top, clone.visibleRect.top);
assert_equals(frame.visibleRect.width, clone.visibleRect.width);
assert_equals(frame.visibleRect.height, clone.visibleRect.height);

frame.close();
clone.close();
Expand Down
24 changes: 12 additions & 12 deletions webcodecs/video-frame.any.js
Expand Up @@ -7,8 +7,8 @@ test(t => {

assert_equals(frame.timestamp, 10, 'timestamp');
assert_equals(frame.duration, null, 'duration');
assert_equals(frame.visibleRegion.width, 32, 'visibleRegion.width');
assert_equals(frame.visibleRegion.height, 16, 'visibleRegion.height');
assert_equals(frame.visibleRect.width, 32, 'visibleRect.width');
assert_equals(frame.visibleRect.height, 16, 'visibleRect.height');
assert_equals(frame.displayWidth, 32, 'displayWidth');
assert_equals(frame.displayHeight, 16, 'displayHeight');

Expand All @@ -26,8 +26,8 @@ test(t => {
let image = makeImageBitmap(1, 1);
let frame = new VideoFrame(image, {timestamp: 10});

assert_equals(frame.visibleRegion.width, 1, 'visibleRegion.width');
assert_equals(frame.visibleRegion.height, 1, 'visibleRegion.height');
assert_equals(frame.visibleRect.width, 1, 'visibleRect.width');
assert_equals(frame.visibleRect.height, 1, 'visibleRect.height');
assert_equals(frame.displayWidth, 1, 'displayWidth');
assert_equals(frame.displayHeight, 1, 'displayHeight');

Expand Down Expand Up @@ -145,31 +145,31 @@ test(t => {
timestamp: 1234,
codedWidth: 4,
codedHeight: 2,
visibleRegion: {left: 100, top: 100, width: 1,
height: 1}
visibleRect: {left: 100, top: 100, width: 1,
height: 1}
})},
'invalid visible left/right');
assert_throws_dom(
'ConstraintError',
() => {constructFrame(
{timestamp: 1234, codedWidth: 4, codedHeight: 2,
visibleRegion: {left: 0, top: 0, width: 0, height: 2}})},
visibleRect: {left: 0, top: 0, width: 0, height: 2}})},
'invalid visible width');
assert_throws_dom(
'ConstraintError',
() => {constructFrame(
{timestamp: 1234, codedWidth: 4, codedHeight: 2,
visibleRegion: {left: 0, top: 0, width: 2, height: 0}})},
visibleRect: {left: 0, top: 0, width: 2, height: 0}})},
'invalid visible height');
assert_throws_js(
TypeError,
() => constructFrame({timestamp: 1234,
codedWidth: 4,
codedHeight: 2,
visibleRegion: {left: 0,
top: 0,
width: -100,
height: -100}}),
visibleRect: {left: 0,
top: 0,
width: -100,
height: -100}}),
'invalid negative visible size');
assert_throws_js(
TypeError, () => {constructFrame({
Expand Down
4 changes: 2 additions & 2 deletions webcodecs/videoDecoder-codec-specific.any.js
Expand Up @@ -11,7 +11,7 @@ const AV1_DATA = {
codec: 'av01.0.04M.08',
codedWidth: 320,
codedHeight: 240,
visibleRegion: {left: 0, top: 0, width: 320, height: 240},
visibleRect: {left: 0, top: 0, width: 320, height: 240},
displayWidth: 320,
displayHeight: 240,
},
Expand All @@ -30,7 +30,7 @@ const VP8_DATA = {
codec: 'vp8',
codedWidth: 320,
codedHeight: 240,
visibleRegion: {left: 0, top: 0, width: 320, height: 240},
visibleRect: {left: 0, top: 0, width: 320, height: 240},
displayWidth: 320,
displayHeight: 240,
},
Expand Down
Expand Up @@ -76,7 +76,7 @@ promise_test(async t => {
]);
assert_equals(frame.allocationSize(), expectedData.length, 'allocationSize()');
const data = new Uint8Array(expectedData.length);
const layout = await frame.readInto(data);
const layout = await frame.copyTo(data);
assert_layout_equals(layout, expectedLayout);
assert_buffer_equals(data, expectedData);
}, 'Test I420 frame.');
Expand All @@ -92,48 +92,25 @@ promise_test(async t => {
]);
assert_equals(frame.allocationSize(), expectedData.length, 'allocationSize()');
const data = new Uint8Array(expectedData.length);
const layout = await frame.readInto(data);
const layout = await frame.copyTo(data);
assert_layout_equals(layout, expectedLayout);
assert_buffer_equals(data, expectedData);
}, 'Test RGBA frame.');

promise_test(async t => {
const frame = makeI420_4x2();
const data = new Uint8Array(11);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data));
await promise_rejects_dom(t, 'ConstraintError', frame.copyTo(data));
}, 'Test undersized buffer.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
layout: [{}, {}, {}],
};
const expectedLayout = [
{offset: 0, stride: 4},
{offset: 8, stride: 2},
{offset: 10, stride: 2},
];
const expectedData = new Uint8Array([
1, 2, 3, 4, // y
5, 6, 7, 8,
9, 10, // u
11, 12 // v
]);
assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');
const data = new Uint8Array(expectedData.length);
const layout = await frame.readInto(data, options);
assert_layout_equals(layout, expectedLayout);
assert_buffer_equals(data, expectedData);
}, 'Test layout can be empty.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
layout: [{}],
layout: [{offset: 0, stride: 4}],
};
assert_throws_dom('ConstraintError', () => frame.allocationSize(options));
const data = new Uint8Array(12);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data, options));
await promise_rejects_dom(t, 'ConstraintError', frame.copyTo(data, options));
}, 'Test incorrect plane count.');

promise_test(async t => {
Expand All @@ -153,7 +130,7 @@ promise_test(async t => {
]);
assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');
const data = new Uint8Array(expectedData.length);
const layout = await frame.readInto(data, options);
const layout = await frame.copyTo(data, options);
assert_layout_equals(layout, options.layout);
assert_buffer_equals(data, expectedData);
}, 'Test stride and offset work.');
Expand All @@ -178,7 +155,7 @@ promise_test(async t => {
]);
assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');
const data = new Uint8Array(expectedData.length);
const layout = await frame.readInto(data, options);
const layout = await frame.copyTo(data, options);
assert_layout_equals(layout, options.layout);
assert_buffer_equals(data, expectedData);
}, 'Test stride and offset with padding.');
Expand All @@ -194,38 +171,9 @@ promise_test(async t => {
};
assert_throws_dom('ConstraintError', () => frame.allocationSize(options));
const data = new Uint8Array(12);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data, options));
await promise_rejects_dom(t, 'ConstraintError', frame.copyTo(data, options));
}, 'Test invalid stride.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
layout: [
{offset: 0, stride: 4},
{offset: 8, stride: 2},
{offset: 10},
],
};
assert_throws_dom('ConstraintError', () => frame.allocationSize(options));
const data = new Uint8Array(12);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data, options));
}, 'Test missing stride.');


promise_test(async t => {
const frame = makeI420_4x2();
const options = {
layout: [
{offset: 0, stride: 4},
{offset: 8, stride: 2},
{stride: 2},
],
};
assert_throws_dom('ConstraintError', () => frame.allocationSize(options));
const data = new Uint8Array(12);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data, options));
}, 'Test missing offset.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
Expand All @@ -237,13 +185,13 @@ promise_test(async t => {
};
assert_throws_dom('ConstraintError', () => frame.allocationSize(options));
const data = new Uint8Array(12);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data, options));
await promise_rejects_dom(t, 'ConstraintError', frame.copyTo(data, options));
}, 'Test address overflow.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
region: frame.codedRegion,
rect: frame.codedRect,
};
const expectedLayout = [
{offset: 0, stride: 4},
Expand All @@ -257,35 +205,35 @@ promise_test(async t => {
]);
assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');
const data = new Uint8Array(expectedData.length);
const layout = await frame.readInto(data, options);
const layout = await frame.copyTo(data, options);
assert_layout_equals(layout, expectedLayout);
assert_buffer_equals(data, expectedData);
}, 'Test codedRegion.');
}, 'Test codedRect.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
region: {left: 0, top: 0, width: 4, height: 0},
rect: {left: 0, top: 0, width: 4, height: 0},
};
assert_throws_dom('ConstraintError', () => frame.allocationSize(options));
const data = new Uint8Array(12);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data, options));
}, 'Test empty region.');
await promise_rejects_dom(t, 'ConstraintError', frame.copyTo(data, options));
}, 'Test empty rect.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
region: {left: 0, top: 0, width: 4, height: 1},
rect: {left: 0, top: 0, width: 4, height: 1},
};
assert_throws_dom('ConstraintError', () => frame.allocationSize(options));
const data = new Uint8Array(12);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data, options));
}, 'Test unaligned region.');
await promise_rejects_dom(t, 'ConstraintError', frame.copyTo(data, options));
}, 'Test unaligned rect.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
region: {left: 2, top: 0, width: 2, height: 2},
rect: {left: 2, top: 0, width: 2, height: 2},
};
const expectedLayout = [
{offset: 0, stride: 2},
Expand All @@ -300,17 +248,17 @@ promise_test(async t => {
]);
assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');
const data = new Uint8Array(expectedData.length);
const layout = await frame.readInto(data, options);
const layout = await frame.copyTo(data, options);
assert_layout_equals(layout, expectedLayout);
assert_buffer_equals(data, expectedData);
}, 'Test left crop.');

promise_test(async t => {
const frame = makeI420_4x2();
const options = {
region: {left: 0, top: 0, width: 4, height: 4},
rect: {left: 0, top: 0, width: 4, height: 4},
};
assert_throws_dom('ConstraintError', () => frame.allocationSize(options));
const data = new Uint8Array(12);
await promise_rejects_dom(t, 'ConstraintError', frame.readInto(data, options));
}, 'Test invalid region.');
await promise_rejects_dom(t, 'ConstraintError', frame.copyTo(data, options));
}, 'Test invalid rect.');

0 comments on commit f93078f

Please sign in to comment.