Skip to content

Commit ab12fe7

Browse files
dalecurtismoz-wptsync-bot
authored andcommitted
Bug 1947322 [wpt PR 50618] - Implement orientation support for WebCodecs VideoDecoder., a=testonly
Automatic update from web-platform-tests Implement orientation support for WebCodecs VideoDecoder. This implements the current spec language by copying the provided transform from the VideoDecoderConfig to each output frame. See w3c/webcodecs#874 for spec details. As part of this, the codec specific wpt test code is split into its own file to make adding new tests (to avoid breaking interop agreements). R=eugene Bug: 327625558 Change-Id: I7c96007a27a634c8da80b72266171c8e13645e46 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6221543 Commit-Queue: Dale Curtis <[email protected]> Reviewed-by: Eugene Zemtsov <[email protected]> Reviewed-by: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1418353} -- wpt-commits: e905cf1339f0f65cbd8c063f4699aaeae4126587 wpt-pr: 50618
1 parent 7098317 commit ab12fe7

File tree

4 files changed

+285
-213
lines changed

4 files changed

+285
-213
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// META: global=window,dedicatedworker
2+
// META: script=videoDecoder-codec-specific-setup.js
3+
// META: variant=?av1
4+
// META: variant=?vp8
5+
// META: variant=?vp9
6+
// META: variant=?h264_avc
7+
// META: variant=?h264_annexb
8+
// META: variant=?h265_hevc
9+
// META: variant=?h265_annexb
10+
11+
promise_test(async t => {
12+
await checkImplements();
13+
const config = {
14+
...CONFIG,
15+
rotation: 90,
16+
flip: true,
17+
};
18+
19+
const support = await VideoDecoder.isConfigSupported(config);
20+
assert_true(support.supported, 'supported');
21+
assert_equals(support.config.rotation, config.rotation, 'rotation');
22+
assert_equals(support.config.flip, config.flip, 'flip');
23+
}, 'Test that isConfigSupported() with orientation');
24+
25+
promise_test(async t => {
26+
await checkImplements();
27+
const callbacks = {};
28+
const decoder = createVideoDecoder(t, callbacks);
29+
let active_config = {
30+
...CONFIG,
31+
rotation: 90,
32+
flip: true,
33+
};
34+
decoder.configure(active_config);
35+
decoder.decode(CHUNKS[0]);
36+
decoder.decode(CHUNKS[1]);
37+
38+
let outputs = 0;
39+
callbacks.output = frame => {
40+
outputs++;
41+
assert_equals(frame.rotation, active_config.rotation, 'rotation');
42+
assert_equals(frame.flip, active_config.flip, 'flip');
43+
frame.close();
44+
};
45+
46+
await decoder.flush();
47+
assert_equals(outputs, 2, 'outputs');
48+
49+
// Reconfigure with a different orientation.
50+
active_config = {
51+
...CONFIG,
52+
rotation: 180,
53+
flip: false,
54+
};
55+
decoder.configure(active_config);
56+
decoder.decode(CHUNKS[0]);
57+
decoder.decode(CHUNKS[1]);
58+
await decoder.flush();
59+
assert_equals(outputs, 4, 'outputs');
60+
}, 'Decode frames with orientation metadata');
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
const AV1_DATA = {
2+
src: 'av1.mp4',
3+
config: {
4+
codec: 'av01.0.04M.08',
5+
codedWidth: 320,
6+
codedHeight: 240,
7+
visibleRect: {x: 0, y: 0, width: 320, height: 240},
8+
displayWidth: 320,
9+
displayHeight: 240,
10+
},
11+
chunks: [
12+
{offset: 48, size: 1938}, {offset: 1986, size: 848},
13+
{offset: 2834, size: 3}, {offset: 2837, size: 47}, {offset: 2884, size: 3},
14+
{offset: 2887, size: 116}, {offset: 3003, size: 3},
15+
{offset: 3006, size: 51}, {offset: 3057, size: 25},
16+
{offset: 3082, size: 105}
17+
]
18+
};
19+
20+
const VP8_DATA = {
21+
src: 'vp8.webm',
22+
config: {
23+
codec: 'vp8',
24+
codedWidth: 320,
25+
codedHeight: 240,
26+
visibleRect: {x: 0, y: 0, width: 320, height: 240},
27+
displayWidth: 320,
28+
displayHeight: 240,
29+
},
30+
chunks: [
31+
{offset: 522, size: 4826}, {offset: 5355, size: 394},
32+
{offset: 5756, size: 621}, {offset: 6384, size: 424},
33+
{offset: 6815, size: 532}, {offset: 7354, size: 655},
34+
{offset: 8016, size: 670}, {offset: 8693, size: 2413},
35+
{offset: 11113, size: 402}, {offset: 11522, size: 686}
36+
]
37+
};
38+
39+
const VP9_DATA = {
40+
src: 'vp9.mp4',
41+
// TODO(sandersd): Verify that the file is actually level 1.
42+
config: {
43+
codec: 'vp09.00.10.08',
44+
codedWidth: 320,
45+
codedHeight: 240,
46+
displayAspectWidth: 320,
47+
displayAspectHeight: 240,
48+
},
49+
chunks: [
50+
{offset: 44, size: 3315}, {offset: 3359, size: 203},
51+
{offset: 3562, size: 245}, {offset: 3807, size: 172},
52+
{offset: 3979, size: 312}, {offset: 4291, size: 170},
53+
{offset: 4461, size: 195}, {offset: 4656, size: 181},
54+
{offset: 4837, size: 356}, {offset: 5193, size: 159}
55+
]
56+
};
57+
58+
const H264_AVC_DATA = {
59+
src: 'h264.mp4',
60+
config: {
61+
codec: 'avc1.64000b',
62+
description: {offset: 9490, size: 45},
63+
codedWidth: 320,
64+
codedHeight: 240,
65+
displayAspectWidth: 320,
66+
displayAspectHeight: 240,
67+
},
68+
chunks: [
69+
{offset: 48, size: 4140}, {offset: 4188, size: 604},
70+
{offset: 4792, size: 475}, {offset: 5267, size: 561},
71+
{offset: 5828, size: 587}, {offset: 6415, size: 519},
72+
{offset: 6934, size: 532}, {offset: 7466, size: 523},
73+
{offset: 7989, size: 454}, {offset: 8443, size: 528}
74+
]
75+
};
76+
77+
const H264_ANNEXB_DATA = {
78+
src: 'h264.annexb',
79+
config: {
80+
codec: 'avc1.64000b',
81+
codedWidth: 320,
82+
codedHeight: 240,
83+
displayAspectWidth: 320,
84+
displayAspectHeight: 240,
85+
},
86+
chunks: [
87+
{offset: 0, size: 4175}, {offset: 4175, size: 602},
88+
{offset: 4777, size: 473}, {offset: 5250, size: 559},
89+
{offset: 5809, size: 585}, {offset: 6394, size: 517},
90+
{offset: 6911, size: 530}, {offset: 7441, size: 521},
91+
{offset: 7962, size: 452}, {offset: 8414, size: 526}
92+
]
93+
};
94+
95+
const H265_HEVC_DATA = {
96+
src: 'h265.mp4',
97+
config: {
98+
codec: 'hev1.1.6.L60.90',
99+
description: {offset: 5821, size: 2406},
100+
codedWidth: 320,
101+
codedHeight: 240,
102+
displayAspectWidth: 320,
103+
displayAspectHeight: 240,
104+
},
105+
chunks: [
106+
{offset: 44, size: 2515}, {offset: 2559, size: 279},
107+
{offset: 2838, size: 327}, {offset: 3165, size: 329},
108+
{offset: 3494, size: 308}, {offset: 3802, size: 292},
109+
{offset: 4094, size: 352}, {offset: 4446, size: 296},
110+
{offset: 4742, size: 216}, {offset: 4958, size: 344}
111+
]
112+
};
113+
114+
const H265_ANNEXB_DATA = {
115+
src: 'h265.annexb',
116+
config: {
117+
codec: 'hev1.1.6.L60.90',
118+
codedWidth: 320,
119+
codedHeight: 240,
120+
displayAspectWidth: 320,
121+
displayAspectHeight: 240,
122+
},
123+
chunks: [
124+
{offset: 0, size: 4894}, {offset: 4894, size: 279},
125+
{offset: 5173, size: 327}, {offset: 5500, size: 329},
126+
{offset: 5829, size: 308}, {offset: 6137, size: 292},
127+
{offset: 6429, size: 352}, {offset: 6781, size: 296},
128+
{offset: 7077, size: 216}, {offset: 7293, size: 344}
129+
]
130+
};
131+
132+
// Allows mutating `callbacks` after constructing the VideoDecoder, wraps calls
133+
// in t.step().
134+
function createVideoDecoder(t, callbacks) {
135+
return new VideoDecoder({
136+
output(frame) {
137+
if (callbacks && callbacks.output) {
138+
t.step(() => callbacks.output(frame));
139+
} else {
140+
t.unreached_func('unexpected output()');
141+
}
142+
},
143+
error(e) {
144+
if (callbacks && callbacks.error) {
145+
t.step(() => callbacks.error(e));
146+
} else {
147+
t.unreached_func('unexpected error()');
148+
}
149+
}
150+
});
151+
}
152+
153+
function createCorruptChunk(index) {
154+
let bad_data = CHUNK_DATA[index];
155+
for (var i = 0; i < bad_data.byteLength; i += 4)
156+
bad_data[i] = 0xFF;
157+
return new EncodedVideoChunk(
158+
{type: 'delta', timestamp: index, data: bad_data});
159+
}
160+
161+
// Create a view of an ArrayBuffer.
162+
function view(buffer, {offset, size}) {
163+
return new Uint8Array(buffer, offset, size);
164+
}
165+
166+
async function checkImplements() {
167+
// Don't run any tests if the codec is not supported.
168+
assert_equals('function', typeof VideoDecoder.isConfigSupported);
169+
let supported = false;
170+
try {
171+
// TODO(sandersd): To properly support H.264 in AVC format, this should
172+
// include the `description`. For now this test assumes that H.264 Annex B
173+
// support is the same as H.264 AVC support.
174+
const support = await VideoDecoder.isConfigSupported({codec: CONFIG.codec});
175+
supported = support.supported;
176+
} catch (e) {
177+
}
178+
assert_implements_optional(supported, CONFIG.codec + ' unsupported');
179+
}
180+
181+
let CONFIG = null;
182+
let CHUNK_DATA = null;
183+
let CHUNKS = null;
184+
promise_setup(async () => {
185+
const data = {
186+
'?av1': AV1_DATA,
187+
'?vp8': VP8_DATA,
188+
'?vp9': VP9_DATA,
189+
'?h264_avc': H264_AVC_DATA,
190+
'?h264_annexb': H264_ANNEXB_DATA,
191+
'?h265_hevc': H265_HEVC_DATA,
192+
'?h265_annexb': H265_ANNEXB_DATA
193+
}[location.search];
194+
195+
// Fetch the media data and prepare buffers.
196+
const response = await fetch(data.src);
197+
const buf = await response.arrayBuffer();
198+
199+
CONFIG = {...data.config};
200+
if (data.config.description) {
201+
CONFIG.description = view(buf, data.config.description);
202+
}
203+
204+
CHUNK_DATA = data.chunks.map((chunk, i) => view(buf, chunk));
205+
206+
CHUNKS = CHUNK_DATA.map(
207+
(data, i) => new EncodedVideoChunk(
208+
{type: i == 0 ? 'key' : 'delta', timestamp: i, duration: 1, data}));
209+
});

0 commit comments

Comments
 (0)