rtp-stats-creation.html (4788B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>No RTCRtpStreamStats should exist prior to RTP/RTCP packet flow</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="../webrtc/RTCPeerConnection-helper.js"></script> 7 <script> 8 'use strict'; 9 10 promise_test(async (test) => { 11 const localPc = createPeerConnectionWithCleanup(test); 12 const remotePc = createPeerConnectionWithCleanup(test); 13 14 localPc.addTransceiver("audio"); 15 localPc.addTransceiver("video"); 16 await exchangeOfferAndListenToOntrack(test, localPc, remotePc); 17 const report = await remotePc.getStats(); 18 const rtp = [...report.values()].filter(({type}) => type.endsWith("rtp")); 19 assert_equals(rtp.length, 0, "no rtp stats with only remote description"); 20 }, "No RTCRtpStreamStats exist when only remote description is set"); 21 22 promise_test(async (test) => { 23 const localPc = createPeerConnectionWithCleanup(test); 24 const remotePc = createPeerConnectionWithCleanup(test); 25 26 localPc.addTrack(...await createTrackAndStreamWithCleanup(test, "audio")); 27 localPc.addTrack(...await createTrackAndStreamWithCleanup(test, "video")); 28 await exchangeOfferAndListenToOntrack(test, localPc, remotePc); 29 const report = await localPc.getStats(); 30 const rtp = [...report.values()].filter(({type}) => type.endsWith("rtp")); 31 assert_equals(rtp.length, 0, "no rtp stats with only local description"); 32 }, "No RTCRtpStreamStats exist when only local description is set"); 33 34 promise_test(async (test) => { 35 const localPc = createPeerConnectionWithCleanup(test); 36 const remotePc = createPeerConnectionWithCleanup(test); 37 38 localPc.addTrack(...await createTrackAndStreamWithCleanup(test, "audio")); 39 localPc.addTrack(...await createTrackAndStreamWithCleanup(test, "video")); 40 exchangeIceCandidates(localPc, remotePc); 41 42 async function countOutboundRtp() { 43 const stats = await localPc.getStats(); 44 return [...stats.values()] 45 .filter(({ type }) => type == "outbound-rtp").length; 46 } 47 48 assert_equals(await countOutboundRtp(), 0, 49 "No outbound rtp stats before setLocalDescription"); 50 await localPc.setLocalDescription(); 51 const p = remotePc.setRemoteDescription(localPc.localDescription); 52 assert_equals(await countOutboundRtp(), 0, 53 "No outbound rtp stats after setLocalDescription but before setRemoteDescription"); 54 await p; 55 await remotePc.setLocalDescription(); 56 await localPc.setRemoteDescription(remotePc.localDescription); 57 58 const start = performance.now(); 59 while (true) { 60 if (await countOutboundRtp() == 2) { 61 // One outbound stat for each track is present. We're done. 62 break; 63 } 64 if (performance.now() > start + 5000) { 65 assert_unreached("outbound stats should become available"); 66 } 67 await new Promise(r => test.step_timeout(r, 100)); 68 } 69 }, "No RTCRtpOutboundStreamStats should exist before negotiation completes"); 70 71 promise_test(async (test) => { 72 const localPc = createPeerConnectionWithCleanup(test); 73 const remotePc = createPeerConnectionWithCleanup(test); 74 75 localPc.addTrack(...await createTrackAndStreamWithCleanup(test, "audio")); 76 localPc.addTrack(...await createTrackAndStreamWithCleanup(test, "video")); 77 exchangeIceCandidates(localPc, remotePc); 78 await exchangeOfferAnswer(localPc, remotePc); 79 const start = performance.now(); 80 while (true) { 81 const report = await remotePc.getStats(); 82 const inbound = 83 [...report.values()].filter(({type}) => type == "inbound-rtp"); 84 assert_true(inbound.every(({packetsReceived}) => packetsReceived > 0), 85 "no inbound rtp stats before packets received"); 86 if (inbound.length == 2) { 87 // One inbound stat for each track is present. We're done. 88 break; 89 } 90 if (performance.now() > start + 5000) { 91 assert_unreached("inbound stats should become available"); 92 } 93 await new Promise(r => test.step_timeout(r, 100)); 94 } 95 }, "No RTCInboundRtpStreamStats exist until packets have been received"); 96 97 promise_test(async (test) => { 98 const localPc = createPeerConnectionWithCleanup(test); 99 const remotePc = createPeerConnectionWithCleanup(test); 100 101 localPc.addTrack(...await createTrackAndStreamWithCleanup(test, "audio")); 102 exchangeIceCandidates(localPc, remotePc); 103 await exchangeOfferAnswer(localPc, remotePc); 104 const start = performance.now(); 105 while (true) { 106 const report = await remotePc.getStats(); 107 const audioPlayout = 108 [...report.values()].filter(({type}) => type == "media-playout"); 109 if (audioPlayout.length == 1) { 110 break; 111 } 112 if (performance.now() > start + 5000) { 113 assert_unreached("Audio playout stats should become available"); 114 } 115 await new Promise(r => test.step_timeout(r, 100)); 116 } 117 }, "RTCAudioPlayoutStats should be present"); 118 </script>