-
Notifications
You must be signed in to change notification settings - Fork 54
/
RTCPeerConnection-mandatory-getStats.https.html
266 lines (251 loc) · 7.17 KB
/
RTCPeerConnection-mandatory-getStats.https.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!doctype html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Mandatory-to-implement stats compliance (a subset of webrtc-stats)</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="RTCPeerConnection-helper.js"></script>
<script src="dictionary-helper.js"></script>
<script src="RTCStats-helper.js"></script>
<script>
'use strict';
// From https://w3c.github.io/webrtc-pc/#mandatory-to-implement-stats
const mandatory = {
RTCRtpStreamStats: [
"ssrc",
"kind",
"transportId",
"codecId",
],
RTCReceivedRtpStreamStats: [
"packetsReceived",
"packetsLost",
"jitter",
"packetsDiscarded",
],
RTCInboundRtpStreamStats: [
"trackId",
"receiverId",
"remoteId",
"framesDecoded",
],
RTCRemoteInboundRtpStreamStats: [
"localId",
"roundTripTime",
],
RTCSentRtpStreamStats: [
"packetsSent",
"bytesSent"
],
RTCOutboundRtpStreamStats: [
"trackId",
"senderId",
"remoteId",
"framesEncoded",
],
RTCRemoteOutboundRtpStreamStats: [
"localId",
"remoteTimestamp",
],
RTCPeerConnectionStats: [
"dataChannelsOpened",
"dataChannelsClosed",
],
RTCDataChannelStats: [
"protocol",
"dataChannelIdentifier",
"state",
"messagesSent",
"bytesSent",
"messagesReceived",
"bytesReceived",
],
RTCMediaStreamStats: [
"streamIdentifer",
"trackIds",
],
RTCMediaHandlerStats: [
"trackIdentifier",
"remoteSource",
"ended",
],
RTCAudioHandlerStats: [
"audioLevel",
],
RTCVideoHandlerStats: [
"frameWidth",
"frameHeight",
"framesPerSecond",
],
RTCVideoSenderStats: [
"framesSent",
],
RTCVideoReceiverStats: [
"framesReceived",
"framesDecoded",
"framesDropped",
"partialFramesLost",
],
RTCCodecStats: [
"payloadType",
"codecType",
"clockRate",
"channels",
"sdpFmtpLine",
],
RTCTransportStats: [
"bytesSent",
"bytesReceived",
"rtcpTransportStatsId",
"selectedCandidatePairId",
"localCertificateId",
"remoteCertificateId",
],
RTCIceCandidatePairStats: [
"transportId",
"localCandidateId",
"remoteCandidateId",
"state",
"priority",
"nominated",
"bytesSent",
"bytesReceived",
"totalRoundTripTime",
"currentRoundTripTime",
],
RTCIceCandidateStats: [
"address",
"port",
"protocol",
"candidateType",
"url",
],
RTCCertificateStats: [
"fingerprint",
"fingerprintAlgorithm",
"base64Certificate",
"issuerCertificateId",
],
};
// From https://w3c.github.io/webrtc-stats/webrtc-stats.html#rtcstatstype-str*
const dictionaryNames = {
"codec": "RTCCodecStats",
"inbound-rtp": "RTCInboundRtpStreamStats",
"outbound-rtp": "RTCOutboundRtpStreamStats",
"remote-inbound-rtp": "RTCRemoteInboundRtpStreamStats",
"remote-outbound-rtp": "RTCRemoteOutboundRtpStreamStats",
"csrc": "RTCRtpContributingSourceStats",
"peer-connection": "RTCPeerConnectionStats",
"data-channel": "RTCDataChannelStats",
"stream": "RTCMediaStreamStats",
"track": {
video: "RTCSenderVideoTrackAttachmentStats",
audio: "RTCSenderAudioTrackAttachmentStats"
},
"sender": {
audio: "RTCAudioSenderStats",
video: "RTCVideoSenderStats"
},
"receiver": {
audio: "RTCAudioReceiverStats",
video: "RTCVideoReceiverStats",
},
"transport": "RTCTransportStats",
"candidate-pair": "RTCIceCandidatePairStats",
"local-candidate": "RTCIceCandidateStats",
"remote-candidate": "RTCIceCandidateStats",
"certificate": "RTCCertificateStats",
};
// From https://w3c.github.io/webrtc-stats/webrtc-stats.html (webidl)
const parents = {
RTCVideoHandlerStats: "RTCMediaHandlerStats",
RTCVideoSenderStats: "RTCVideoHandlerStats",
RTCSenderVideoTrackAttachmentStats: "RTCVideoSenderStats",
RTCVideoReceiverStats: "RTCVideoHandlerStats",
RTCAudioHandlerStats: "RTCMediaHandlerStats",
RTCAudioSenderStats: "RTCAudioHandlerStats",
RTCSenderAudioTrackAttachmentStats: "RTCAudioSenderStats",
RTCAudioReceiverStats: "RTCAudioHandlerStats",
RTCReceivedRtpStreamStats: "RTCRtpStreamStats",
RTCInboundRtpStreamStats: "RTCReceivedRtpStreamStats",
RTCRemoteInboundRtpStreamStats: "RTCReceivedRtpStreamStats",
RTCSentRtpStreamStats: "RTCRtpStreamStats",
RTCOutboundRtpStreamStats: "RTCSentRtpStreamStats",
RTCRemoteOutboundRtpStreamStats : "RTCSentRtpStreamStats",
};
const remaining = JSON.parse(JSON.stringify(mandatory));
for (const dictName in remaining) {
remaining[dictName] = new Set(remaining[dictName]);
}
async function getAllStats(t, pc) {
// Try to obtain as many stats as possible, waiting up to 20 seconds for
// roundTripTime which can take several RTCP messages to calculate.
let stats;
for (let i = 0; i < 20; i++) {
stats = await pc.getStats();
const values = [...stats.values()];
const [audio, video] = ["audio", "video"].map(kind =>
values.find(s => s.type == "remote-inbound-rtp" && s.kind == kind));
if (audio && "roundTripTime" in audio &&
video && "roundTripTime" in video) {
return stats;
}
await new Promise(r => t.step_timeout(r, 1000));
}
return stats;
}
let succeed;
const success = new Promise(r => succeed = r);
promise_test(async t => {
const pc1 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc2.close());
pc1.createDataChannel("dummy", {negotiated: true, id: 0});
pc2.createDataChannel("dummy", {negotiated: true, id: 0});
const stream = await getNoiseStream({video: true, audio:true});
for (const track of stream.getTracks()) {
pc1.addTrack(track, stream);
pc2.addTrack(track, stream);
t.add_cleanup(() => track.stop());
}
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
const stats = await getAllStats(t, pc1);
// The focus of this test is not API correctness, but rather to provide an
// accessible metric of implementation progress by dictionary member. We count
// whether we've seen each dictionary's mandatory members in getStats().
for (const stat of stats.values()) {
let dictName = dictionaryNames[stat.type];
if (!dictName) continue;
if (typeof dictName == "object") {
dictName = dictName[stat.kind];
}
assert_equals(typeof dictName, "string", "Test error. String.");
if (dictName && mandatory[dictName]) {
do {
const memberNames = mandatory[dictName];
const remainingNames = remaining[dictName];
assert_true(memberNames.length > 0, "Test error. Parent not found.");
for (const memberName of memberNames) {
if (memberName in stat) {
assert_not_equals(stat[memberName], undefined, "Not undefined");
remainingNames.delete(memberName);
}
}
dictName = parents[dictName];
} while (dictName);
}
}
succeed();
}, 'getStats succeeds');
for (const dictName in mandatory) {
for (const memberName of mandatory[dictName]) {
promise_test(async t => {
await success;
assert_true(!remaining[dictName].has(memberName),
`Is ${memberName} present`);
}, `${dictName}'s ${memberName}`);
}
}
</script>