Skip to content

Commit

Permalink
webcodecs: Validate decoding results in encode-and-decode GPU test
Browse files Browse the repository at this point in the history
Also run with various sources and and acceleration preferences.

Change-Id: I37367ce817f59ecad50e374f4312e450a3c1f7c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3646273
Reviewed-by: Brian Sheedy <bsheedy@chromium.org>
Commit-Queue: Eugene Zemtsov <eugene@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1055875}
  • Loading branch information
Djuffin authored and Chromium LUCI CQ committed Oct 6, 2022
1 parent b916f02 commit 517bee9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
29 changes: 23 additions & 6 deletions content/test/data/gpu/webcodecs/encode-decode.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
<script src="webcodecs_common.js"></script>
<script type="text/javascript">
'use strict';
const acceleration = 'prefer-hardware';
function showFrameForDebug(frame) {
const cnv = document.getElementById('debug_cnv');
var ctx = cnv.getContext('2d');
ctx.drawImage(frame, 0, 0);
}

async function main(arg) {
const width = 640;
const height = 480;
Expand All @@ -21,7 +26,7 @@

const encoder_config = {
codec: arg.codec,
hardwareAcceleration: acceleration,
hardwareAcceleration: arg.acceleration,
width: width,
height: height,
bitrate: 5000000,
Expand All @@ -39,6 +44,15 @@

let decoder = new VideoDecoder({
output(frame) {
let dots = frames_decoded;
// Check that we have intended number of dots and no more.
// Completely black frame shouldn't pass the test.
if(!validateBlackDots(frame, dots) ||
validateBlackDots(frame, dots + 1)) {
showFrameForDebug(frame);
TEST.reportFailure(
`Unexpected dot count ts:${frame.timestamp} dots:${dots}`);
}
frames_decoded++;
frame.close();
},
Expand All @@ -54,9 +68,6 @@
output(chunk, metadata) {
let config = metadata.decoderConfig;
if (config) {
// Here we assume that if accelerated encoding is supported,
// accelerated decoding should be supported too.
config.hardwareAcceleration = acceleration;
decoder.configure(config);
}
decoder.decode(chunk);
Expand All @@ -76,7 +87,12 @@

let encoder = new VideoEncoder(encoder_init);
encoder.configure(encoder_config);
let source = new CanvasSource(width, height);

let source = await createFrameSource(arg.source_type, width, height);
if (!source) {
TEST.skip('Unsupported source: ' + arg.source_type);
return;
}

for (let i = 0; i < frames_to_encode; i++) {
let frame = await source.getNextFrame();
Expand Down Expand Up @@ -106,6 +122,7 @@
</head>

<body>
<canvas id="debug_cnv" width="640" height="480"></canvas>
</body>

</html>
3 changes: 2 additions & 1 deletion content/test/data/gpu/webcodecs/webcodecs_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TestHarness {
reportSuccess() {
this.finished = true;
this.success = true;
this.log('Test completed');
}

reportFailure(error) {
Expand Down Expand Up @@ -329,7 +330,7 @@ function createCanvasCaptureSource(width, height) {
async function prepareDecoderSource(
frames_to_encode, width, height, codec, acceleration) {
if (!acceleration)
acceleration = 'allow';
acceleration = 'no-preference';
const encoder_config = {
codec: codec,
width: width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ crbug.com/1311091 WebCodecs_WebRTCPeerConnection_* [ Skip ]

crbug.com/1338968 [ android android-nexus-5x ] WebCodecs_TexImage2d_hw_decoder [ Failure ]

# Conservatively expect all macs to fail, I'm not sure if our try bots run arm64
# devices. A later commit needs to put mac-x86_64 here, or better still fix the
# bug and remove this expectation.
crbug.com/1371749 [ mac ] WebCodecs_EncodeDecode_offscreen_avc1.42001E_prefer-hardware [ Failure ]
#######################################################################
# Automated Entries After This Point - Do Not Manually Add Below Here #
#######################################################################
15 changes: 10 additions & 5 deletions content/test/gpu/gpu_tests/webcodecs_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@ def GenerateVideoTests(cls) -> ct.TestGenerator:
'use_worker': True
}])

for codec in video_codecs:
yield ('WebCodecs_EncodeDecode_' + codec, 'encode-decode.html', [{
'codec':
codec
}])
for source_type in ['offscreen', 'arraybuffer']:
for codec in video_codecs:
for acc in accelerations:
args = (source_type, codec, acc)
yield ('WebCodecs_EncodeDecode_%s_%s_%s' % args, 'encode-decode.html',
[{
'source_type': source_type,
'codec': codec,
'acceleration': acc
}])

for source_type in frame_sources:
for codec in video_codecs:
Expand Down

0 comments on commit 517bee9

Please sign in to comment.