Skip to content

Commit 893864c

Browse files
Dan Sanderschromium-wpt-export-bot
Dan Sanders
authored andcommitted
[webcodecs] Support odd visibleRects
Per w3c/webcodecs#348 (comment), Allow visibleRect to have odd size but not offset. Continue to restrict copyTo() to even sizes. Bug: 1205166 Change-Id: If6541a16a3852545634407c314530aaf40dc8e93 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3293782 Reviewed-by: Chrome Cunningham Reviewed-by: Dale Curtis Commit-Queue: Dan Sanders Cr-Commit-Position: refs/heads/main@{#966946}
1 parent c41961a commit 893864c

File tree

1 file changed

+93
-48
lines changed

1 file changed

+93
-48
lines changed

webcodecs/videoFrame-construction.any.js

Lines changed: 93 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -113,68 +113,85 @@ test(t => {
113113

114114
assert_throws_js(
115115
TypeError,
116-
() => new VideoFrame(image, {timestamp: 10, visibleRect: {x: -1, y: 0, width: 10, height: 10}}),
117-
'negative visibleRect x');
116+
() => new VideoFrame(
117+
image,
118+
{timestamp: 10, visibleRect: {x: -1, y: 0, width: 10, height: 10}}),
119+
'negative visibleRect x');
118120

119-
assert_throws_js(
121+
assert_throws_js(
120122
TypeError,
121-
() => new VideoFrame(image, {timestamp: 10, visibleRect: {x: 0, y: 0, width: -10, height: 10}}),
122-
'negative visibleRect width');
123+
() => new VideoFrame(
124+
image,
125+
{timestamp: 10, visibleRect: {x: 0, y: 0, width: -10, height: 10}}),
126+
'negative visibleRect width');
123127

124-
assert_throws_js(
128+
assert_throws_js(
125129
TypeError,
126-
() => new VideoFrame(image, {timestamp: 10, visibleRect: {x: 0, y: 0, width: 10, height: 0}}),
127-
'zero visibleRect height');
130+
() => new VideoFrame(
131+
image,
132+
{timestamp: 10, visibleRect: {x: 0, y: 0, width: 10, height: 0}}),
133+
'zero visibleRect height');
128134

129-
assert_throws_js(
130-
TypeError,
131-
() => new VideoFrame(image, {timestamp: 10, visibleRect: {x: 0, y: Infinity, width: 10, height: 10}}),
132-
'non finite visibleRect y');
135+
assert_throws_js(
136+
TypeError, () => new VideoFrame(image, {
137+
timestamp: 10,
138+
visibleRect: {x: 0, y: Infinity, width: 10, height: 10}
139+
}),
140+
'non finite visibleRect y');
133141

134-
assert_throws_js(
135-
TypeError,
136-
() => new VideoFrame(image, {timestamp: 10, visibleRect: {x: 0, y: 0, width: 10, height: Infinity}}),
137-
'non finite visibleRect height');
142+
assert_throws_js(
143+
TypeError, () => new VideoFrame(image, {
144+
timestamp: 10,
145+
visibleRect: {x: 0, y: 0, width: 10, height: Infinity}
146+
}),
147+
'non finite visibleRect height');
138148

139-
assert_throws_js(
149+
assert_throws_js(
140150
TypeError,
141-
() => new VideoFrame(image, {timestamp: 10, visibleRect: {x: 0, y: 0, width: 33, height: 17}}),
142-
'visibleRect area exceeds coded size');
151+
() => new VideoFrame(
152+
image,
153+
{timestamp: 10, visibleRect: {x: 0, y: 0, width: 33, height: 17}}),
154+
'visibleRect area exceeds coded size');
143155

144-
assert_throws_js(
156+
assert_throws_js(
145157
TypeError,
146-
() => new VideoFrame(image, {timestamp: 10, visibleRect: {x: 2, y: 2, width: 32, height: 16}}),
147-
'visibleRect outside coded size');
158+
() => new VideoFrame(
159+
image,
160+
{timestamp: 10, visibleRect: {x: 2, y: 2, width: 32, height: 16}}),
161+
'visibleRect outside coded size');
148162

149-
assert_throws_js(
163+
assert_throws_js(
150164
TypeError,
151165
() => new VideoFrame(image, {timestamp: 10, displayHeight: 10}),
152-
'displayHeight provided without displayWidth');
166+
'displayHeight provided without displayWidth');
153167

154-
assert_throws_js(
155-
TypeError,
156-
() => new VideoFrame(image, {timestamp: 10, displayWidth: 10}),
157-
'displayWidth provided without displayHeight');
168+
assert_throws_js(
169+
TypeError, () => new VideoFrame(image, {timestamp: 10, displayWidth: 10}),
170+
'displayWidth provided without displayHeight');
158171

159-
assert_throws_js(
172+
assert_throws_js(
160173
TypeError,
161-
() => new VideoFrame(image, {timestamp: 10, displayWidth: 0, displayHeight: 10}),
162-
'displayWidth is zero');
174+
() => new VideoFrame(
175+
image, {timestamp: 10, displayWidth: 0, displayHeight: 10}),
176+
'displayWidth is zero');
163177

164-
assert_throws_js(
178+
assert_throws_js(
165179
TypeError,
166-
() => new VideoFrame(image, {timestamp: 10, displayWidth: 10, displayHeight: 0}),
167-
'displayHeight is zero');
180+
() => new VideoFrame(
181+
image, {timestamp: 10, displayWidth: 10, displayHeight: 0}),
182+
'displayHeight is zero');
168183

169-
assert_throws_js(
184+
assert_throws_js(
170185
TypeError,
171-
() => new VideoFrame(i420Frame, {visibleRect: {x: 1, y: 0, width: 2, height: 2}}),
186+
() => new VideoFrame(
187+
i420Frame, {visibleRect: {x: 1, y: 0, width: 2, height: 2}}),
172188
'visibleRect x is not sample aligned');
173189

174-
assert_throws_js(
175-
TypeError,
176-
() => new VideoFrame(i420Frame, {visibleRect: {x: 0, y: 0, width: 1, height: 2}}),
177-
'visibleRect width is not sample aligned');
190+
assert_throws_js(
191+
TypeError,
192+
() => new VideoFrame(
193+
i420Frame, {visibleRect: {x: 0, y: 1, width: 2, height: 2}}),
194+
'visibleRect y is not sample aligned');
178195

179196
}, 'Test invalid CanvasImageSource constructed VideoFrames');
180197

@@ -192,7 +209,8 @@ test(t => {
192209
]);
193210
let origFrame = new VideoFrame(data, init);
194211

195-
let cropLeftHalf = new VideoFrame(origFrame, {visibleRect : {x: 0, y: 0, width: 2, height: 2}});
212+
let cropLeftHalf = new VideoFrame(
213+
origFrame, {visibleRect: {x: 0, y: 0, width: 2, height: 2}});
196214
assert_equals(cropLeftHalf.codedWidth, origFrame.codedWidth);
197215
assert_equals(cropLeftHalf.codedHeight, origFrame.codedHeight);
198216
assert_equals(cropLeftHalf.visibleRect.x, 0);
@@ -219,7 +237,8 @@ test(t => {
219237
]);
220238
let anamorphicFrame = new VideoFrame(data, init);
221239

222-
let cropRightFrame = new VideoFrame(anamorphicFrame, {visibleRect : {x: 2, y: 0, width: 2, height: 2}});
240+
let cropRightFrame = new VideoFrame(
241+
anamorphicFrame, {visibleRect: {x: 2, y: 0, width: 2, height: 2}});
223242
assert_equals(cropRightFrame.codedWidth, anamorphicFrame.codedWidth);
224243
assert_equals(cropRightFrame.codedHeight, anamorphicFrame.codedHeight);
225244
assert_equals(cropRightFrame.visibleRect.x, 2);
@@ -246,7 +265,8 @@ test(t => {
246265
]);
247266
let scaledFrame = new VideoFrame(data, init);
248267

249-
let cropRightFrame = new VideoFrame(scaledFrame, {visibleRect : {x: 2, y: 0, width: 2, height: 2}});
268+
let cropRightFrame = new VideoFrame(
269+
scaledFrame, {visibleRect: {x: 2, y: 0, width: 2, height: 2}});
250270
assert_equals(cropRightFrame.codedWidth, scaledFrame.codedWidth);
251271
assert_equals(cropRightFrame.codedHeight, scaledFrame.codedHeight);
252272
assert_equals(cropRightFrame.visibleRect.x, 2);
@@ -260,11 +280,12 @@ test(t => {
260280
test(t => {
261281
let image = makeImageBitmap(32, 16);
262282

263-
let scaledFrame = new VideoFrame(image,
264-
{ visibleRect : {x: 0, y: 0, width: 2, height: 2},
265-
displayWidth: 10, displayHeight: 20,
266-
timestamp: 0
267-
});
283+
let scaledFrame = new VideoFrame(image, {
284+
visibleRect: {x: 0, y: 0, width: 2, height: 2},
285+
displayWidth: 10,
286+
displayHeight: 20,
287+
timestamp: 0
288+
});
268289
assert_equals(scaledFrame.codedWidth, 32);
269290
assert_equals(scaledFrame.codedHeight, 16);
270291
assert_equals(scaledFrame.visibleRect.x, 0);
@@ -553,6 +574,30 @@ test(t => {
553574
frame.close();
554575
}, 'Test we can construct a VideoFrame from an offscreen canvas.');
555576

577+
test(t => {
578+
let fmt = 'I420';
579+
let vfInit = {
580+
format: fmt,
581+
timestamp: 1234,
582+
codedWidth: 4,
583+
codedHeight: 2,
584+
visibleRect: {x: 0, y: 0, width: 1, height: 1},
585+
};
586+
let data = new Uint8Array([
587+
1, 2, 3, 4, 5, 6, 7, 8, // y
588+
1, 2, // u
589+
1, 2, // v
590+
8, 7, 6, 5, 4, 3, 2, 1, // a
591+
]);
592+
let frame = new VideoFrame(data, vfInit);
593+
assert_equals(frame.format, fmt, 'format');
594+
assert_equals(frame.visibleRect.x, 0, 'visibleRect.x');
595+
assert_equals(frame.visibleRect.y, 0, 'visibleRect.y');
596+
assert_equals(frame.visibleRect.width, 1, 'visibleRect.width');
597+
assert_equals(frame.visibleRect.height, 1, 'visibleRect.height');
598+
frame.close();
599+
}, 'Test I420 VideoFrame with odd visible size');
600+
556601
test(t => {
557602
let fmt = 'I420A';
558603
let vfInit = {format: fmt, timestamp: 1234, codedWidth: 4, codedHeight: 2};

0 commit comments

Comments
 (0)