outbound-rtp-encoding-index.https.html (3413B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="third_party/sdp/sdp.js"></script> 6 <script src="simulcast/simulcast.js"></script> 7 <script> 8 'use strict'; 9 10 async function pollUntilMultipleOutboundRtps(pc, kTimeoutMs = 10000) { 11 const t0 = performance.now(); 12 while (performance.now() - t0 < kTimeoutMs) { 13 const report = await pc.getStats(); 14 const outboundRtps = Array.from( 15 report.values().filter(s => s.type == 'outbound-rtp')); 16 if (outboundRtps.length > 1) { 17 return; 18 } 19 } 20 throw 'Timed out waiting for multple outbound-rtp stats objects'; 21 } 22 23 promise_test(async t => { 24 const pc1 = new RTCPeerConnection(); 25 t.add_cleanup(() => pc1.close()); 26 const pc2 = new RTCPeerConnection(); 27 t.add_cleanup(() => pc2.close()); 28 pc1.addTransceiver('video'); 29 30 // O/A is needed to ensure outbound-rtp exists. 31 await pc1.setLocalDescription(); 32 await pc2.setRemoteDescription(pc1.localDescription); 33 await pc2.setLocalDescription(); 34 await pc1.setRemoteDescription(pc2.localDescription); 35 36 const report = await pc1.getStats(); 37 const outboundRtp = report.values().find(s => s.type == 'outbound-rtp'); 38 assert_not_equals(outboundRtp, undefined, 'outbound-rtp exists'); 39 40 assert_equals(outboundRtp.encodingIndex, 0, 'encodingIndex is 0'); 41 }, `In singlecast, encodingIndex is 0`); 42 43 promise_test(async t => { 44 const pc1 = new RTCPeerConnection(); 45 t.add_cleanup(() => pc1.close()); 46 const pc2 = new RTCPeerConnection(); 47 t.add_cleanup(() => pc2.close()); 48 49 pc1.addTransceiver('video', {sendEncodings: [{rid: 'foo'}, {rid: 'bar'}]}); 50 // O/A with tweaks to accept simulcast. 51 await doOfferToSendSimulcastAndAnswer(pc1, pc2, ['foo', 'bar']); 52 53 const report = await pc1.getStats(); 54 // The RTP stream for sendEncodings[0]. 55 const outboundRtpFoo = report.values().find( 56 s => s.type == 'outbound-rtp' && s.rid == 'foo'); 57 assert_not_equals(outboundRtpFoo, undefined, 58 `outbound-rtp with rid:'foo' exists`); 59 assert_equals(outboundRtpFoo.encodingIndex, 0, 60 `outbound-rtp with rid:'foo' has encodingIndex 0`); 61 // The RTP stream for sendEncodings[1]. 62 const outboundRtpBar = report.values().find( 63 s => s.type == 'outbound-rtp' && s.rid == 'bar'); 64 assert_not_equals(outboundRtpBar, undefined, 65 `outbound-rtp with rid:'bar' exists`); 66 assert_equals(outboundRtpBar.encodingIndex, 1, 67 `outbound-rtp with rid:'bar' has encodingIndex 1`); 68 }, `In simulcast, encodingIndex reflects index of sendEncodings`); 69 70 promise_test(async t => { 71 const pc1 = new RTCPeerConnection(); 72 t.add_cleanup(() => pc1.close()); 73 const pc2 = new RTCPeerConnection(); 74 t.add_cleanup(() => pc2.close()); 75 76 pc1.addTransceiver('audio'); 77 // O/A is needed to ensure outbound-rtp exists. 78 await pc1.setLocalDescription(); 79 await pc2.setRemoteDescription(pc1.localDescription); 80 await pc2.setLocalDescription(); 81 await pc1.setRemoteDescription(pc2.localDescription); 82 83 const report = await pc1.getStats(); 84 const outboundRtp = report.values().find(s => s.type == 'outbound-rtp'); 85 assert_not_equals(outboundRtp, undefined, 'outbound-rtp exists'); 86 87 assert_equals(outboundRtp.encodingIndex, undefined, 88 'encodingIndex is undefined'); 89 }, `encodingIndex is undefined for audio streams`); 90 </script>