video-decoder.crossOriginIsolated.https.any.js (2182B)
1 // META: global=window,dedicatedworker 2 // META: script=/webcodecs/utils.js 3 4 const testData = { 5 src: 'h264.mp4', 6 config: { 7 codec: 'avc1.64000b', 8 description: {offset: 9490, size: 45}, 9 codedWidth: 320, 10 codedHeight: 240, 11 displayAspectWidth: 320, 12 displayAspectHeight: 240, 13 } 14 }; 15 16 // Create a view of an ArrayBuffer. 17 function view(buffer, {offset, size}) { 18 return new Uint8Array(buffer, offset, size); 19 } 20 21 function testSharedArrayBufferDescription(t, useView) { 22 const data = testData; 23 24 // Don't run test if the codec is not supported. 25 assert_equals("function", typeof VideoDecoder.isConfigSupported); 26 let supported = false; 27 return VideoDecoder.isConfigSupported({codec: data.config.codec}) 28 .catch(_ => { 29 assert_implements_optional(false, data.config.codec + ' unsupported'); 30 }) 31 .then(support => { 32 supported = support.supported; 33 assert_implements_optional( 34 supported, data.config.codec + ' unsupported'); 35 return fetch(data.src); 36 }) 37 .then(response => { 38 return response.arrayBuffer(); 39 }) 40 .then(buf => { 41 config = {...data.config}; 42 if (data.config.description) { 43 let desc = new SharedArrayBuffer(data.config.description.size); 44 let descView = new Uint8Array(desc); 45 descView.set(view(buf, data.config.description)); 46 config.description = useView ? descView : desc; 47 } 48 49 // Support was verified above, so the description shouldn't change 50 // that. 51 return VideoDecoder.isConfigSupported(config); 52 }) 53 .then(support => { 54 assert_true(support.supported); 55 56 const decoder = new VideoDecoder(getDefaultCodecInit(t)); 57 decoder.configure(config); 58 assert_equals(decoder.state, 'configured', 'state'); 59 }); 60 } 61 62 promise_test(t => { 63 return testSharedArrayBufferDescription(t, /*useView=*/ false); 64 }, 'Test isConfigSupported() and configure() using a SharedArrayBuffer'); 65 66 promise_test(t => { 67 return testSharedArrayBufferDescription(t, /*useView=*/ true); 68 }, 'Test isConfigSupported() and configure() using a Uint8Array(SharedArrayBuffer)');