Skip to content

Commit

Permalink
Add a testcase
Browse files Browse the repository at this point in the history
This patch introduces a new WPT verifying that `VideoDecoder` can decode
data without providing an image size during `configure()` step. Although
the issue was initially observed with the VP8 decoder
(FFmpegVideoDecoder via libvpx), the test applies to all supported
codecs, ensuring robust behavior across different decoder
implementations.

Differential Revision: https://phabricator.services.mozilla.com/D232914

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1928120
gecko-commit: a5f9a1eab5a88273e0a30b3610530bca0c94850e
gecko-reviewers: media-playback-reviewers, alwu
  • Loading branch information
ChunMinChang authored and moz-wptsync-bot committed Dec 31, 2024
1 parent 0669ef6 commit 58c1148
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions webcodecs/video-decoder-no-size-in-configure.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// META: global=window,dedicatedworker
// META: script=/webcodecs/video-encoder-utils.js
// META: variant=?av1
// META: variant=?vp8
// META: variant=?vp9_p0
// META: variant=?h264_avc
// META: variant=?h264_annexb

var CODEC = null;
promise_setup(async () => {
CODEC = {
'?av1': { codec: 'av01.0.04M.08' },
'?vp8': { codec: 'vp8' },
'?vp9_p0': { codec: 'vp09.00.10.08' },
'?h264_avc': { codec: 'avc1.42001E', avc: { format: 'avc' } },
'?h264_annexb': { codec: 'avc1.42001E', avc: { format: 'annexb' } },
}[location.search];
});

promise_test(async t => {
let encoderConfig = {
...CODEC,
width: 320,
height: 240,
};

const encoderSupport = await VideoEncoder.isConfigSupported(encoderConfig);
assert_implements_optional(encoderSupport.supported, `${encoderConfig.codec} encoder is unsupported`);

let encodedResult;
const encoder = new VideoEncoder({
output: (chunk, metadata) => {
encodedResult = { chunk, metadata };
},
error: e => {
t.unreached_func('Unexpected encoding error: ' + e);
},
});

encoderConfig.framerate = 30;
encoderConfig.bitrate = 3000000;
encoder.configure(encoderConfig);

let frame = createFrame(encoderConfig.width, encoderConfig.height, 0);
encoder.encode(frame);
frame.close();

await encoder.flush();
encoder.close();

let decoderConfig = encodedResult.metadata.decoderConfig;
delete decoderConfig.codedWidth;
delete decoderConfig.codedHeight;
delete decoderConfig.displayAspectWidth;
delete decoderConfig.displayAspectHeight;

const decoderSupport = await VideoDecoder.isConfigSupported(decoderConfig);
assert_implements_optional(decoderSupport.supported, `${decoderConfig.codec} decoder is unsupported`);

let decodedResult;
const decoder = new VideoDecoder({
output: frame => {
decodedResult = frame;
},
error: e => {
t.unreached_func('Unexpected decoding error: ' + e);
},
});


decoder.configure(decoderConfig);
decoder.decode(encodedResult.chunk);
await decoder.flush();

assert_equals(decodedResult.codedWidth, encoderConfig.width, 'decoded frame width');
assert_equals(decodedResult.codedHeight, encoderConfig.height, 'decoded frame height');
}, 'Test configure() without setting width and height');

0 comments on commit 58c1148

Please sign in to comment.