Skip to content

Commit

Permalink
Implement VideoDecoder.isConfigSupported()
Browse files Browse the repository at this point in the history
API and motivations described here:
w3c/webcodecs#98

Spec PR here:
w3c/webcodecs#120

Bug: 1141707
Test: new layout tests
Change-Id: I3e53da5961119b4b36ec76666ad1a67cca19b963
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2612684
Commit-Queue: Chrome Cunningham <chcunningham@chromium.org>
Reviewed-by: Thomas Guilbert <tguilbert@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841376}
  • Loading branch information
chcunningham authored and chromium-wpt-export-bot committed Jan 8, 2021
1 parent 93c1657 commit e265ce2
Showing 1 changed file with 121 additions and 11 deletions.
132 changes: 121 additions & 11 deletions webcodecs/video-decoder.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// TODO(sandersd): Move metadata into a helper library.
// TODO(sandersd): Add H.264 decode test once there is an API to query for
// supported codecs.
let h264 = {
const h264 = {
async buffer() { return (await fetch('h264.mp4')).arrayBuffer(); },
codec: "avc1.64000c",
description: {offset: 7229, size: 46},
Expand All @@ -20,7 +20,7 @@ let h264 = {
{offset: 6429, size: 281}]
};

let vp9 = {
const vp9 = {
async buffer() { return (await fetch('vp9.mp4')).arrayBuffer(); },
// TODO(sandersd): Verify that the file is actually level 1.
codec: "vp09.00.10.08",
Expand All @@ -36,6 +36,88 @@ let vp9 = {
{offset: 5193, size: 159}]
};

const badCodecsList = [
'', // Empty codec
'bogus', // Non exsitent codec
'vorbis', // Audio codec
'vp9', // Ambiguous codec
'video/webm; codecs="vp9"' // Codec with mime type
]

const invalidConfigs = [
{
comment: 'Emtpy codec',
config: {codec: ''},
},
{
comment: 'Unrecognized codec',
config: {codec: 'bogus'},
},
{
comment: 'Audio codec',
config: {codec: 'vorbis'},
},
{
comment: 'Ambiguous codec',
config: {codec: 'vp9'},
},
{
comment: 'Codec with MIME type',
config: {codec: 'video/webm; codecs="vp8"'},
},
{
comment: 'Zero coded size',
config: {
codec: h264.codec,
codedWidth: 0,
codedHeight: 0,
},
},
{
comment: 'Out of bounds crop size caused by left/top offset',
config: {
codec: h264.codec,
codedWidth: 1920,
codedHeight: 1088,
cropLeft: 10,
cropTop: 10,
// When unspecified, these default to coded dimensions
// cropWidth: 1920,
// cropHeight: 1088
},
},
{
comment: 'Out of bounds crop size',
config: {
codec: h264.codec,
codedWidth: 1920,
codedHeight: 1088,
cropLeft: 10,
cropTop: 10,
cropWidth: 1920,
cropHeight: 1088,
},
},
{
comment: 'Way out of bounds crop size',
config: {
codec: h264.codec,
codedWidth: 1920,
codedHeight: 1088,
cropWidth: 4000,
cropHeight: 5000,
},
},
{
comment: 'Invalid display size',
config: {
codec: h264.codec,
displayWidth: 0,
displayHeight: 0,
},
},
] // invalidConfigs

function view(buffer, {offset, size}) {
return new Uint8Array(buffer, offset, size);
}
Expand All @@ -48,6 +130,40 @@ function getFakeChunk() {
});
}

invalidConfigs.forEach(entry => {
promise_test(t => {
return promise_rejects_js(t, TypeError, VideoDecoder.isConfigSupported(entry.config));
}, 'Test that VideoDecoder.isConfigSupported() rejects invalid config:' + entry.comment);
});

invalidConfigs.forEach(entry => {
async_test(t => {
let codec = new VideoDecoder(getDefaultCodecInit(t));
assert_throws_js(TypeError, () => { codec.configure(entry.config); });
t.done();
}, 'Test that VideoDecoder.configure() rejects invalid config:' + entry.comment);
});

promise_test(t => {
return VideoDecoder.isConfigSupported({codec: vp9.codec});
}, 'Test VideoDecoder.isConfigSupported() with minimal valid config');

promise_test(t => {
// This config specifies a slight crop. H264 1080p content always crops
// because H264 coded dimensions are a multiple of 16 (e.g. 1088).
return VideoDecoder.isConfigSupported({
codec: h264.codec,
codedWidth: 1920,
codedHeight: 1088,
cropLeft: 0,
cropTop: 0,
cropWidth: 1920,
cropHeight: 1080,
displayWidth: 1920,
displayHeight: 1080
});
}, 'Test VideoDecoder.isConfigSupported() with valid expanded config');

promise_test(t => {
// VideoDecoderInit lacks required fields.
assert_throws_js(TypeError, () => { new VideoDecoder({}); });
Expand All @@ -65,18 +181,12 @@ promise_test(t => {
promise_test(t => {
let decoder = new VideoDecoder(getDefaultCodecInit(t));

let badCodecsList = [
'', // Empty codec
'bogus', // Non exsitent codec
'vorbis', // Audio codec
'vp9', // Ambiguous codec
'video/webm; codecs="vp9"' // Codec with mime type
]

// TODO(chcunningham): Remove badCodecsList testing. It's now covered more
// extensively by other tests.
testConfigurations(decoder, { codec: vp9.codec }, badCodecsList);

return endAfterEventLoopTurn();
}, 'Test VideoDecoder.configure()');
}, 'Test VideoDecoder.configure() with various codec strings');

promise_test(async t => {
let buffer = await vp9.buffer();
Expand Down

0 comments on commit e265ce2

Please sign in to comment.