webcodecs: Implementation of VideoEncoder.isConfigSupported()
Bug: 1176442
Change-Id: I2463090994eb946284eeee1e62ed53ebd7c9584c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2823770
Commit-Queue: Eugene Zemtsov <eugene@chromium.org>
Reviewed-by: Dan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#872626}
diff --git a/webcodecs/video-encoder-config.any.js b/webcodecs/video-encoder-config.any.js
index af55716..374d1e2 100644
--- a/webcodecs/video-encoder-config.any.js
+++ b/webcodecs/video-encoder-config.any.js
@@ -4,16 +4,145 @@
const invalidConfigs = [
{
comment: 'Emtpy codec',
- config: {codec: ''},
+ config: {
+ codec: '',
+ width: 640,
+ height: 480,
+ },
},
{
comment: 'Unrecognized codec',
- config: {codec: 'bogus'},
+ config: {
+ codec: 'bogus',
+ width: 640,
+ height: 480,
+ },
},
+ {
+ comment: 'Width is too large',
+ config: {
+ codec: 'vp8',
+ width: 1000000,
+ height: 480,
+ },
+ },
+ {
+ comment: 'Height is too large',
+ config: {
+ codec: 'vp8',
+ width: 640,
+ height: 1000000,
+ },
+ },
+ {
+ comment: 'Invalid scalability mode',
+ config: {
+ codec: 'vp8',
+ width: 640,
+ height: 480,
+ scalabilityMode: "ABC"
+ }
+ },
+ {
+ comment: 'AVC not supported by VP8',
+ config: {
+ codec: 'vp8',
+ width: 640,
+ height: 480,
+ avc: {
+ format: "annexb"
+ }
+ }
+ }
];
invalidConfigs.forEach(entry => {
promise_test(t => {
return promise_rejects_js(t, TypeError, VideoEncoder.isConfigSupported(entry.config));
- }, 'Test that AudioDecoder.isConfigSupported() rejects invalid config:' + entry.comment);
-});
\ No newline at end of file
+ }, 'Test that VideoEncoder.isConfigSupported() rejects invalid config:' + entry.comment);
+});
+
+
+const validButUnsupportedConfigs = [
+ {
+ comment: 'Too strenuous accelerated encoding parameters',
+ config: {
+ codec: "vp8",
+ hardwareAcceleration: "require",
+ width: 7000,
+ height: 7000,
+ bitrate: 1,
+ framerate: 240,
+ }
+ },
+];
+
+validButUnsupportedConfigs.forEach(entry => {
+ let config = entry.config;
+ promise_test(async t => {
+ let support = await VideoEncoder.isConfigSupported(config);
+ assert_false(support.supported);
+
+ let new_config = support.config;
+ assert_equals(new_config.codec, config.codec);
+ assert_equals(new_config.width, config.width);
+ assert_equals(new_config.height, config.height);
+ if (config.bitrate)
+ assert_equals(new_config.bitrate, config.bitrate);
+ if (config.framerate)
+ assert_equals(new_config.framerate, config.framerate);
+ }, "VideoEncoder.isConfigSupported() doesn't support config:" + entry.comment);
+});
+
+const validConfigs = [
+ {
+ codec: "avc1.42001E",
+ hardwareAcceleration: "allow",
+ width: 640,
+ height: 480,
+ bitrate: 5000000,
+ framerate: 24,
+ avc: {
+ format: "annexb"
+ },
+ futureConfigFeature: 'foo',
+ },
+ {
+ codec: "vp8",
+ hardwareAcceleration: "allow",
+ width: 800,
+ height: 600,
+ bitrate: 7000000,
+ framerate: 60,
+ scalabilityMode: "L1T2",
+ futureConfigFeature: 'foo',
+ },
+ {
+ codec: "vp09.00.10.08",
+ hardwareAcceleration: "allow",
+ width: 1280,
+ height: 720,
+ bitrate: 7000000,
+ framerate: 25,
+ futureConfigFeature: 'foo',
+ }
+];
+
+validConfigs.forEach(config => {
+ promise_test(async t => {
+ let support = await VideoEncoder.isConfigSupported(config);
+ assert_true(support.supported);
+
+ let new_config = support.config;
+ assert_false(new_config.hasOwnProperty('futureConfigFeature'));
+ assert_equals(new_config.codec, config.codec);
+ assert_equals(new_config.width, config.width);
+ assert_equals(new_config.height, config.height);
+ if (config.bitrate)
+ assert_equals(new_config.bitrate, config.bitrate);
+ if (config.framerate)
+ assert_equals(new_config.framerate, config.framerate);
+ }, "VideoEncoder.isConfigSupported() supports:" + JSON.stringify(config));
+});
+
+