Issue #2332 - Hyphenate rtc stats type as per spec

Backport of https://bugzilla.mozilla.org/show_bug.cgi?id=1322503
This commit is contained in:
Basilisk-Dev 2023-10-18 16:30:27 -04:00 committed by roytam1
commit 9f63203a43
7 changed files with 57 additions and 42 deletions

View file

@ -1417,12 +1417,12 @@ PeerConnectionWrapper.prototype = {
waitForRtpFlow(track) {
var hasFlow = stats => {
var rtp = stats.get([...stats.keys()].find(key =>
!stats.get(key).isRemote && stats.get(key).type.endsWith("boundrtp")));
!stats.get(key).isRemote && stats.get(key).type.endsWith("bound-rtp")));
ok(rtp, "Should have RTP stats for track " + track.id);
if (!rtp) {
return false;
}
var nrPackets = rtp[rtp.type == "outboundrtp" ? "packetsSent"
var nrPackets = rtp[rtp.type == "outbound-rtp" ? "packetsSent"
: "packetsReceived"];
info("Track " + track.id + " has " + nrPackets + " " +
rtp.type + " RTP packets.");
@ -1559,15 +1559,15 @@ PeerConnectionWrapper.prototype = {
counters[res.type] = (counters[res.type] || 0) + 1;
switch (res.type) {
case "inboundrtp":
case "outboundrtp": {
case "inbound-rtp":
case "outbound-rtp": {
// ssrc is a 32 bit number returned as a string by spec
ok(res.ssrc.length > 0, "Ssrc has length");
ok(res.ssrc.length < 11, "Ssrc not lengthy");
ok(!/[^0-9]/.test(res.ssrc), "Ssrc numeric");
ok(parseInt(res.ssrc) < Math.pow(2,32), "Ssrc within limits");
if (res.type == "outboundrtp") {
if (res.type == "outbound-rtp") {
ok(res.packetsSent !== undefined, "Rtp packetsSent");
// We assume minimum payload to be 1 byte (guess from RFC 3550)
ok(res.bytesSent >= res.packetsSent, "Rtp bytesSent");
@ -1576,11 +1576,11 @@ PeerConnectionWrapper.prototype = {
ok(res.bytesReceived >= res.packetsReceived, "Rtp bytesReceived");
}
if (res.remoteId) {
var rem = stats[res.remoteId];
var rem = stats.get(res.remoteId);
ok(rem.isRemote, "Remote is rtcp");
ok(rem.remoteId == res.id, "Remote backlink match");
if(res.type == "outboundrtp") {
ok(rem.type == "inboundrtp", "Rtcp is inbound");
if(res.type == "outbound-rtp") {
ok(rem.type == "inbound-rtp", "Rtcp is inbound");
ok(rem.packetsReceived !== undefined, "Rtcp packetsReceived");
ok(rem.packetsLost !== undefined, "Rtcp packetsLost");
ok(rem.bytesReceived >= rem.packetsReceived, "Rtcp bytesReceived");
@ -1593,7 +1593,7 @@ PeerConnectionWrapper.prototype = {
ok(rem.mozRtt >= 0, "Rtcp rtt " + rem.mozRtt + " >= 0");
ok(rem.mozRtt < 60000, "Rtcp rtt " + rem.mozRtt + " < 1 min");
} else {
ok(rem.type == "outboundrtp", "Rtcp is outbound");
ok(rem.type == "outbound-rtp", "Rtcp is outbound");
ok(rem.packetsSent !== undefined, "Rtcp packetsSent");
// We may have received more than outdated Rtcp packetsSent
ok(rem.bytesSent >= rem.packetsSent, "Rtcp bytesSent");
@ -1607,6 +1607,13 @@ PeerConnectionWrapper.prototype = {
}
}
var legacyToSpecMapping = {
'inboundrtp':'inbound-rtp',
'outboundrtp':'outbound-rtp',
'candidatepair':'candidate-pair',
'localcandidate':'local-candidate',
'remotecandidate':'remote-candidate'
};
// Use legacy way of enumerating stats
var counters2 = {};
for (let key in stats) {
@ -1614,8 +1621,9 @@ PeerConnectionWrapper.prototype = {
continue;
}
var res = stats[key];
var type = legacyToSpecMapping[res.type] || res.type;
if (!res.isRemote) {
counters2[res.type] = (counters2[res.type] || 0) + 1;
counters2[type] = (counters2[type] || 0) + 1;
}
}
is(JSON.stringify(counters), JSON.stringify(counters2),
@ -1624,21 +1632,21 @@ PeerConnectionWrapper.prototype = {
var nout = Object.keys(this.expectedLocalTrackInfoById).length;
var ndata = this.dataChannels.length;
// TODO(Bug 957145): Restore stronger inboundrtp test once Bug 948249 is fixed
//is((counters["inboundrtp"] || 0), nin, "Have " + nin + " inboundrtp stat(s)");
ok((counters.inboundrtp || 0) >= nin, "Have at least " + nin + " inboundrtp stat(s) *");
// TODO(Bug 957145): Restore stronger inbound-rtp test once Bug 948249 is fixed
//is((counters["inbound-rtp"] || 0), nin, "Have " + nin + " inbound-rtp stat(s)");
ok((counters["inbound-rtp"] || 0) >= nin, "Have at least " + nin + " inbound-rtp stat(s) *");
is(counters.outboundrtp || 0, nout, "Have " + nout + " outboundrtp stat(s)");
is(counters["outbound-rtp"] || 0, nout, "Have " + nout + " outbound-rtp stat(s)");
var numLocalCandidates = counters.localcandidate || 0;
var numRemoteCandidates = counters.remotecandidate || 0;
var numLocalCandidates = counters["local-candidate"] || 0;
var numRemoteCandidates = counters["remote-candidate"] || 0;
// If there are no tracks, there will be no stats either.
if (nin + nout + ndata > 0) {
ok(numLocalCandidates, "Have localcandidate stat(s)");
ok(numRemoteCandidates, "Have remotecandidate stat(s)");
ok(numLocalCandidates, "Have local-candidate stat(s)");
ok(numRemoteCandidates, "Have remote-candidate stat(s)");
} else {
is(numLocalCandidates, 0, "Have no localcandidate stats");
is(numRemoteCandidates, 0, "Have no remotecandidate stats");
is(numLocalCandidates, 0, "Have no local-candidate stats");
is(numRemoteCandidates, 0, "Have no remote-candidate stats");
}
},
@ -1653,7 +1661,7 @@ PeerConnectionWrapper.prototype = {
let lId;
let rId;
for (let stat of stats.values()) {
if (stat.type == "candidatepair" && stat.selected) {
if (stat.type == "candidate-pair" && stat.selected) {
lId = stat.localCandidateId;
rId = stat.remoteCandidateId;
break;
@ -1704,8 +1712,8 @@ PeerConnectionWrapper.prototype = {
checkStatsIceConnections : function(stats,
offerConstraintsList, offerOptions, testOptions) {
var numIceConnections = 0;
Object.keys(stats).forEach(key => {
if ((stats[key].type === "candidatepair") && stats[key].selected) {
stats.forEach(stat => {
if ((stat.type === "candidate-pair") && stat.selected) {
numIceConnections += 1;
}
});

View file

@ -90,12 +90,12 @@ function checkTrackStats(pc, rtpSenderOrReceiver, outbound) {
(audio ? "audio" : "video") + " rtp track id " + track.id;
return pc.getStats(track).then(stats => {
ok(pc.hasStat(stats, {
type: outbound ? "outboundrtp" : "inboundrtp",
type: outbound ? "outbound-rtp" : "inbound-rtp",
isRemote: false,
mediaType: audio ? "audio" : "video"
}), msg + " - found expected stats");
ok(!pc.hasStat(stats, {
type: outbound ? "inboundrtp" : "outboundrtp",
type: outbound ? "inbound-rtp" : "outbound-rtp",
isRemote: false
}), msg + " - did not find extra stats with wrong direction");
ok(!pc.hasStat(stats, {