video-encoder-orientation.https.any.js (3281B)
1 // META: global=window,dedicatedworker 2 // META: script=/common/media.js 3 // META: script=/webcodecs/utils.js 4 // META: script=/webcodecs/video-encoder-utils.js 5 6 const defaultConfig = { 7 codec: 'vp8', 8 width: 640, 9 height: 480 10 }; 11 12 promise_test(async t => { 13 let output_chunks = []; 14 let codecInit = getDefaultCodecInit(t); 15 let decoderConfig = null; 16 codecInit.output = (chunk, metadata) => { 17 assert_not_equals(metadata, null); 18 if (metadata.decoderConfig) 19 decoderConfig = metadata.decoderConfig; 20 output_chunks.push(chunk); 21 } 22 23 let encoder = new VideoEncoder(codecInit); 24 let config = defaultConfig; 25 encoder.configure(config); 26 27 let frame = createFrame(640, 480, 0, {rotation: 90, flip: true}); 28 encoder.encode(frame); 29 frame.close(); 30 await encoder.flush(); 31 encoder.close(); 32 assert_equals(output_chunks.length, 1); 33 assert_equals(decoderConfig.rotation, 90); 34 assert_equals(decoderConfig.flip, true); 35 }, 'Encode video frame with orientation'); 36 37 promise_test(async t => { 38 let output_chunks = []; 39 let codecInit = getDefaultCodecInit(t); 40 let decoderConfig = null; 41 codecInit.output = (chunk, metadata) => { 42 assert_not_equals(metadata, null); 43 if (metadata.decoderConfig) 44 decoderConfig = metadata.decoderConfig; 45 output_chunks.push(chunk); 46 } 47 48 let encoder = new VideoEncoder(codecInit); 49 let config = defaultConfig; 50 encoder.configure(config); 51 52 let frame1 = createFrame(640, 480, 0, {rotation: 90, flip: true}); 53 let frame2 = createFrame(640, 480, 33333, {rotation: 90, flip: false}); 54 let frame3 = createFrame(640, 480, 66666, {rotation: 180, flip: true}); 55 let frame4 = createFrame(640, 480, 99999, {rotation: 90, flip: true}); 56 57 encoder.encode(frame1); 58 assert_throws_dom('DataError', () => encoder.encode(frame2)); 59 assert_throws_dom('DataError', () => encoder.encode(frame3)); 60 encoder.encode(frame4); 61 62 frame1.close(); 63 frame2.close(); 64 frame3.close(); 65 frame4.close(); 66 67 await encoder.flush(); 68 encoder.close(); 69 assert_equals(output_chunks.length, 2); 70 assert_equals(decoderConfig.rotation, 90); 71 assert_equals(decoderConfig.flip, true); 72 }, 'Encode video frames with different orientation has non-fatal failures'); 73 74 promise_test(async t => { 75 let output_chunks = []; 76 let codecInit = getDefaultCodecInit(t); 77 let decoderConfig = null; 78 codecInit.output = (chunk, metadata) => { 79 assert_not_equals(metadata, null); 80 if (metadata.decoderConfig) 81 decoderConfig = metadata.decoderConfig; 82 output_chunks.push(chunk); 83 } 84 85 let encoder = new VideoEncoder(codecInit); 86 let config = defaultConfig; 87 encoder.configure(config); 88 89 let frame = createFrame(640, 480, 0, {rotation: 90, flip: true}); 90 encoder.encode(frame); 91 frame.close(); 92 await encoder.flush(); 93 assert_equals(output_chunks.length, 1); 94 assert_equals(decoderConfig.rotation, 90); 95 assert_equals(decoderConfig.flip, true); 96 97 encoder.configure(config); 98 frame = createFrame(640, 480, 0, {rotation: 270, flip: false}); 99 encoder.encode(frame); 100 frame.close(); 101 await encoder.flush(); 102 assert_equals(output_chunks.length, 2); 103 assert_equals(decoderConfig.rotation, 270); 104 assert_equals(decoderConfig.flip, false); 105 106 encoder.close(); 107 }, 'Encode video frames with different orientations after reconfigure');