Skip to content

Commit

Permalink
Correct WebRTC getStats WPT to wait for remote stats before comparing
Browse files Browse the repository at this point in the history
If care is not taken to wait for remote stats on senders and receivers, then the contents
of the stats reports will not be stable. Waiting for this stability should fix our
intermittent failures checking that RTCRtpSender/Receiver.getStats() returns the
same dictionaries that RTCPeerConnection.getStats(sender/receiver.track) does.

Differential Revision: https://phabricator.services.mozilla.com/D5804

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1457129
gecko-commit: 0874b793fc046bf31ca80c673d5dfa0bb38ea343
gecko-integration-branch: autoland
gecko-reviewers: jib
  • Loading branch information
na-g authored and moz-wptsync-bot committed Nov 6, 2018
1 parent f77ee36 commit e26e776
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions webrtc/RTCPeerConnection-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ function createDataChannelPair(
});
}

// Wait for RTP and RTCP stats to arrive
async function waitForRtpAndRtcpStats(pc) {
while (true) {
const report = await pc.getStats();
const stats = [...report.values()].filter(({type}) => type.endsWith("bound-rtp"));
// Each RTP and RTCP stat has a reference
// to the matching stat in the other direction
if (stats.length && stats.every(({localId, remoteId}) => localId || remoteId)) {
break;
}
}
}

// Wait for a single message event and return
// a promise that resolve when the event fires
function awaitMessage(channel) {
Expand Down
10 changes: 10 additions & 0 deletions webrtc/RTCPeerConnection-track-stats.https.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!doctype html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>RTCPeerConnection.prototype.getStats</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand All @@ -12,6 +13,7 @@
// The following helper functions are called from RTCPeerConnection-helper.js:
// doSignalingHandshake
// getUserMediaTracksAndStreams
// waitForRtpAndRtcpStats

// The following helper functions are called from RTCStats-helper.js
// (depends on dictionary-helper.js):
Expand Down Expand Up @@ -504,6 +506,10 @@
await doSignalingHandshake(caller, callee);
await onIceConnectionStateCompleted(caller);

// Wait until RTCP has arrived so that it can not arrive between
// the two get stats calls.
await waitForRtpAndRtcpStats(caller);

let senderReport = await sender.getStats();
let trackReport = await caller.getStats(sender.track);

Expand Down Expand Up @@ -532,6 +538,10 @@
await onIceConnectionStateCompleted(caller);
let receiver = caller.getReceivers()[0];

// Wait until RTCP has arrived so that it can not arrive between
// the two get stats calls.
await waitForRtpAndRtcpStats(caller);

let receiverReport = await receiver.getStats();
let trackReport = await caller.getStats(receiver.track);

Expand Down

0 comments on commit e26e776

Please sign in to comment.