video-decoder.https.any.js (5134B)
1 // META: global=window,dedicatedworker 2 // META: script=/webcodecs/utils.js 3 4 const detachedArrayBuffer = new ArrayBuffer(4); 5 var b = detachedArrayBuffer.transferToFixedLength(); 6 7 const invalidConfigs = [ 8 { 9 comment: 'Missing codec', 10 config: {}, 11 }, 12 { 13 comment: 'Empty codec', 14 config: {codec: ''}, 15 }, 16 { 17 comment: 'Valid codec, detached description', 18 config: {codec: 'vp8', description: detachedArrayBuffer}, 19 }, 20 ]; // invalidConfigs 21 22 invalidConfigs.forEach(entry => { 23 promise_test( 24 t => { 25 return promise_rejects_js( 26 t, TypeError, VideoDecoder.isConfigSupported(entry.config)); 27 }, 28 'Test that VideoDecoder.isConfigSupported() rejects invalid config:' + 29 entry.comment); 30 }); 31 32 invalidConfigs.forEach(entry => { 33 async_test( 34 t => { 35 let codec = new VideoDecoder(getDefaultCodecInit(t)); 36 assert_throws_js(TypeError, () => { 37 codec.configure(entry.config); 38 }); 39 t.done(); 40 }, 41 'Test that VideoDecoder.configure() rejects invalid config:' + 42 entry.comment); 43 }); 44 45 const arrayBuffer = new ArrayBuffer(12583); 46 const arrayBufferView = new DataView(arrayBuffer); 47 48 const validButUnsupportedConfigs = [ 49 { 50 comment: 'Unrecognized codec', 51 config: {codec: 'bogus'}, 52 }, 53 { 54 comment: 'Unrecognized codec with dataview description', 55 config: { 56 codec: '7ﷺ۹.9', 57 description: arrayBufferView, 58 }, 59 }, 60 { 61 comment: 'Audio codec', 62 config: {codec: 'vorbis'}, 63 }, 64 { 65 comment: 'Ambiguous codec', 66 config: {codec: 'vp9'}, 67 }, 68 { 69 comment: 'Codec with bad casing', 70 config: {codec: 'Vp09.00.10.08'}, 71 }, 72 { 73 comment: 'Codec with MIME type', 74 config: {codec: 'video/webm; codecs="vp8"'}, 75 }, 76 { 77 comment: 'Possible future H264 codec string', 78 config: {codec: 'avc1.FF000b'}, 79 }, 80 { 81 comment: 'Possible future H264 codec string (level 2.9)', 82 config: {codec: 'avc1.4D401D'}, 83 }, 84 { 85 comment: 'Possible future HEVC codec string', 86 config: {codec: 'hvc1.C99.6FFFFFF.L93'}, 87 }, 88 { 89 comment: 'Possible future VP9 codec string', 90 config: {codec: 'vp09.99.99.08'}, 91 }, 92 { 93 comment: 'Possible future AV1 codec string', 94 config: {codec: 'av01.9.99M.08'}, 95 }, 96 { 97 comment: 'codec with spaces', 98 config: {codec: ' vp09.00.10.08 '}, 99 }, 100 ]; // validButUnsupportedConfigs 101 102 validButUnsupportedConfigs.forEach(entry => { 103 promise_test( 104 t => { 105 return VideoDecoder.isConfigSupported(entry.config).then(support => { 106 assert_false(support.supported); 107 }); 108 }, 109 'Test that VideoDecoder.isConfigSupported() doesn\'t support config: ' + 110 entry.comment); 111 }); 112 113 validButUnsupportedConfigs.forEach(entry => { 114 promise_test( 115 t => { 116 let isErrorCallbackCalled = false; 117 let codec = new VideoDecoder({ 118 output: t.unreached_func('unexpected output'), 119 error: t.step_func(e => { 120 isErrorCallbackCalled = true; 121 assert_true(e instanceof DOMException); 122 assert_equals(e.name, 'NotSupportedError'); 123 assert_equals(codec.state, 'closed', 'state'); 124 }) 125 }); 126 codec.configure(entry.config); 127 return codec.flush() 128 .then(t.unreached_func('flush succeeded unexpectedly')) 129 .catch(t.step_func(e => { 130 assert_true(isErrorCallbackCalled, "isErrorCallbackCalled"); 131 assert_true(e instanceof DOMException); 132 assert_equals(e.name, 'NotSupportedError'); 133 assert_equals(codec.state, 'closed', 'state'); 134 })); 135 }, 136 'Test that VideoDecoder.configure() doesn\'t support config: ' + 137 entry.comment); 138 }); 139 140 promise_test(t => { 141 // VideoDecoderInit lacks required fields. 142 assert_throws_js(TypeError, () => { 143 new VideoDecoder({}); 144 }); 145 146 // VideoDecoderInit has required fields. 147 let decoder = new VideoDecoder(getDefaultCodecInit(t)); 148 149 assert_equals(decoder.state, 'unconfigured'); 150 151 decoder.close(); 152 153 return endAfterEventLoopTurn(); 154 }, 'Test VideoDecoder construction'); 155 156 const validConfigs = [ 157 { 158 comment: 'variant 1 of h264 codec string', 159 config: {codec: 'avc3.42001E'}, 160 }, 161 { 162 comment: 'variant 2 of h264 codec string', 163 config: {codec: 'avc1.42001E'}, 164 }, 165 ]; // validConfigs 166 167 validConfigs.forEach(entry => { 168 promise_test(async t => { 169 try { 170 await VideoDecoder.isConfigSupported(entry.config); 171 var decoder = new VideoDecoder(getDefaultCodecInit(t)); 172 // Something that works with all codecs: 173 entry.config.width = 1280; 174 entry.config.height = 720; 175 decoder.configure(entry.config); 176 return decoder 177 .flush() 178 .then( 179 t.step_func(e => { 180 assert_equals(decoder.state, 'configured', 'codec is configured'); 181 }) 182 ) 183 .catch(t.unreached_func('flush succeeded unexpectedly')); 184 } catch (e) { 185 assert_true(false, entry.comment + ' should not throw'); 186 } 187 }, 'Test that VideoDecoder.isConfigSupported() accepts config:' + entry.comment); 188 });