summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBasilisk-Dev <basiliskdev@protonmail.com>2023-10-18 16:30:27 -0400
committerBasilisk-Dev <basiliskdev@protonmail.com>2023-10-18 16:30:27 -0400
commit5b5672fd5601074dbd06fc077b57879f534b82b6 (patch)
tree81eac0c2148f5cf401ee470f3d3f954164c82b15
parent087febcc4b017a0af4ec82b1283341c8d979a17e (diff)
downloaduxp-5b5672fd5601074dbd06fc077b57879f534b82b6.tar.gz
Issue #2332 - Hyphenate rtc stats type as per spec
Backport of https://bugzilla.mozilla.org/show_bug.cgi?id=1322503
-rw-r--r--dom/media/PeerConnection.js11
-rw-r--r--dom/media/tests/mochitest/pc.js54
-rw-r--r--dom/media/tests/mochitest/templates.js4
-rw-r--r--dom/media/webrtc/WebrtcGlobal.h2
-rw-r--r--dom/webidl/RTCStatsReport.webidl10
-rw-r--r--media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp16
-rw-r--r--media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp2
7 files changed, 57 insertions, 42 deletions
diff --git a/dom/media/PeerConnection.js b/dom/media/PeerConnection.js
index e4612f8316..784ba822b3 100644
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -308,13 +308,20 @@ RTCStatsReport.prototype = {
// Since maplike is recent, we still also make the stats available as legacy
// enumerable read-only properties directly on our content-facing object.
// Must be called after our webidl sandwich is made.
+ _specToLegacyFieldMapping: {
+ 'inbound-rtp' : 'inboundrtp',
+ 'outbound-rtp':'outboundrtp',
+ 'candidate-pair':'candidatepair',
+ 'local-candidate':'localcandidate',
+ 'remote-candidate':'remotecandidate'
+ },
makeStatsPublic: function(warnNullable) {
let legacyProps = {};
for (let key in this._report) {
+ this.setInternal(key, Cu.cloneInto(this._report[key], this._win));
let value = Cu.cloneInto(this._report[key], this._win);
- this.setInternal(key, value);
-
+ value.type = this._specToLegacyFieldMapping[value.type] || value.type;
legacyProps[key] = {
enumerable: true, configurable: false,
get: Cu.exportFunction(function() {
diff --git a/dom/media/tests/mochitest/pc.js b/dom/media/tests/mochitest/pc.js
index 4363841da7..ed6f76edb7 100644
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -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;
}
});
diff --git a/dom/media/tests/mochitest/templates.js b/dom/media/tests/mochitest/templates.js
index 7a149c146e..89204888a5 100644
--- a/dom/media/tests/mochitest/templates.js
+++ b/dom/media/tests/mochitest/templates.js
@@ -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, {
diff --git a/dom/media/webrtc/WebrtcGlobal.h b/dom/media/webrtc/WebrtcGlobal.h
index 8ab10cb0dd..7a8611afef 100644
--- a/dom/media/webrtc/WebrtcGlobal.h
+++ b/dom/media/webrtc/WebrtcGlobal.h
@@ -72,7 +72,7 @@ template<>
struct ParamTraits<mozilla::dom::RTCStatsType> :
public ContiguousEnumSerializer<
mozilla::dom::RTCStatsType,
- mozilla::dom::RTCStatsType::Inboundrtp,
+ mozilla::dom::RTCStatsType::Inbound_rtp,
mozilla::dom::RTCStatsType::EndGuard_>
{};
diff --git a/dom/webidl/RTCStatsReport.webidl b/dom/webidl/RTCStatsReport.webidl
index 04c683e9a1..6a7d5bbc0d 100644
--- a/dom/webidl/RTCStatsReport.webidl
+++ b/dom/webidl/RTCStatsReport.webidl
@@ -9,14 +9,14 @@
*/
enum RTCStatsType {
- "inboundrtp",
- "outboundrtp",
+ "inbound-rtp",
+ "outbound-rtp",
"session",
"track",
"transport",
- "candidatepair",
- "localcandidate",
- "remotecandidate"
+ "candidate-pair",
+ "local-candidate",
+ "remote-candidate"
};
dictionary RTCStats {
diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
index ad87fa1f91..894a3a9a2d 100644
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -3602,7 +3602,7 @@ static void ToRTCIceCandidateStats(
cand.mPortNumber.Construct(c->cand_addr.port);
cand.mTransport.Construct(
NS_ConvertASCIItoUTF16(c->cand_addr.transport.c_str()));
- if (candidateType == RTCStatsType::Localcandidate) {
+ if (candidateType == RTCStatsType::Local_candidate) {
cand.mMozLocalTransport.Construct(
NS_ConvertASCIItoUTF16(c->local_addr.transport.c_str()));
}
@@ -3636,7 +3636,7 @@ static void RecordIceStats_s(
s.mId.Construct(codeword);
s.mComponentId.Construct(componentId);
s.mTimestamp.Construct(now);
- s.mType.Construct(RTCStatsType::Candidatepair);
+ s.mType.Construct(RTCStatsType::Candidate_pair);
s.mLocalCandidateId.Construct(localCodeword);
s.mRemoteCandidateId.Construct(remoteCodeword);
s.mNominated.Construct(p->nominated);
@@ -3649,7 +3649,7 @@ static void RecordIceStats_s(
std::vector<NrIceCandidate> candidates;
if (NS_SUCCEEDED(mediaStream.GetLocalCandidates(&candidates))) {
ToRTCIceCandidateStats(candidates,
- RTCStatsType::Localcandidate,
+ RTCStatsType::Local_candidate,
componentId,
now,
report);
@@ -3658,7 +3658,7 @@ static void RecordIceStats_s(
if (NS_SUCCEEDED(mediaStream.GetRemoteCandidates(&candidates))) {
ToRTCIceCandidateStats(candidates,
- RTCStatsType::Remotecandidate,
+ RTCStatsType::Remote_candidate,
componentId,
now,
report);
@@ -3710,7 +3710,7 @@ PeerConnectionImpl::ExecuteStatsQuery_s(RTCStatsQuery *query) {
RTCInboundRTPStreamStats s;
s.mTimestamp.Construct(timestamp);
s.mId.Construct(remoteId);
- s.mType.Construct(RTCStatsType::Inboundrtp);
+ s.mType.Construct(RTCStatsType::Inbound_rtp);
if (ssrc.Length()) {
s.mSsrc.Construct(ssrc);
}
@@ -3731,7 +3731,7 @@ PeerConnectionImpl::ExecuteStatsQuery_s(RTCStatsQuery *query) {
RTCOutboundRTPStreamStats s;
s.mTimestamp.Construct(query->now);
s.mId.Construct(localId);
- s.mType.Construct(RTCStatsType::Outboundrtp);
+ s.mType.Construct(RTCStatsType::Outbound_rtp);
if (ssrc.Length()) {
s.mSsrc.Construct(ssrc);
}
@@ -3784,7 +3784,7 @@ PeerConnectionImpl::ExecuteStatsQuery_s(RTCStatsQuery *query) {
RTCOutboundRTPStreamStats s;
s.mTimestamp.Construct(timestamp);
s.mId.Construct(remoteId);
- s.mType.Construct(RTCStatsType::Outboundrtp);
+ s.mType.Construct(RTCStatsType::Outbound_rtp);
if (ssrc.Length()) {
s.mSsrc.Construct(ssrc);
}
@@ -3801,7 +3801,7 @@ PeerConnectionImpl::ExecuteStatsQuery_s(RTCStatsQuery *query) {
RTCInboundRTPStreamStats s;
s.mTimestamp.Construct(query->now);
s.mId.Construct(localId);
- s.mType.Construct(RTCStatsType::Inboundrtp);
+ s.mType.Construct(RTCStatsType::Inbound_rtp);
if (ssrc.Length()) {
s.mSsrc.Construct(ssrc);
}
diff --git a/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp b/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
index 2f860cac60..8f3c29f116 100644
--- a/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
+++ b/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
@@ -1066,7 +1066,7 @@ static void StoreLongTermICEStatisticsImpl_m(
uint32_t candBitmask = GetCandidateIpAndTransportMask(&cand);
// Note: shift values need to result in the above enum table
- if (cand.mType.Value() == RTCStatsType::Localcandidate) {
+ if (cand.mType.Value() == RTCStatsType::Local_candidate) {
candBitmask <<= kLocalShift;
}