File: rtp-stats-lifetime.https.html

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (246 lines) | stat: -rw-r--r-- 9,819 bytes parent folder | download | duplicates (2)
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
<!doctype html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script src="third_party/sdp/sdp.js"></script>
<script src="simulcast/simulcast.js"></script>
<script>
'use strict';

async function hasStats(pc, type) {
  const report = await pc.getStats();
  for (const stats of report.values()) {
    if (stats.type == type) {
      return true;
    }
  }
  return false;
}

async function getStatsTypePollUntilItExists(pc, type, kTimeoutMs = 10000) {
  const t0 = performance.now();
  while (performance.now() - t0 < kTimeoutMs) {
    const report = await pc.getStats();
    for (const stats of report.values()) {
      if (stats.type == type) {
        return stats;
      }
    }
  }
  return null;
}

promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());

  pc.addTransceiver('video');
  assert_false(await hasStats(pc, 'outbound-rtp'),
               'outbound-rtp does not exist after addTransceiver');
  await pc.setLocalDescription();
  assert_false(await hasStats(pc, 'outbound-rtp'),
              'outbound-rtp does not exist in have-local-offer');
}, `RTCOutboundRtpStreamStats does not exist as early as have-local-offer`);

// This test does not exchange ICE candidates, meaning no packets are sent.
// We should still see outbound-rtp stats because they are created by the O/A.
promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());

  // Offer to send. See previous test for assertions that the outbound-rtp is
  // not created this early, which this test does not care about.
  pc1.addTransceiver('video');
  await pc1.setLocalDescription();

  // Answer to send.
  await pc2.setRemoteDescription(pc1.localDescription);
  const [transceiver] = pc2.getTransceivers();
  transceiver.direction = 'sendrecv';
  assert_false(await hasStats(pc2, 'outbound-rtp'),
               'outbound-rtp does not exist in has-remote-offer');
  await pc2.setLocalDescription();
  assert_true(await hasStats(pc2, 'outbound-rtp'),
              'outbound-rtp exists after answerer returns to stable');

  // Complete offerer negotiation.
  await pc1.setRemoteDescription(pc2.localDescription);
  assert_true(await hasStats(pc1, 'outbound-rtp'),
              'outbound-rtp exists after offerer returns to stable');
}, `RTCOutboundRtpStreamStats exists after returning to stable`);

promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());

  pc1.addTransceiver('video', {sendEncodings: [{rid: 'foo'}, {rid: 'bar'}]});
  // O/A with tweaks to accept simulcast.
  await doOfferToSendSimulcastAndAnswer(pc1, pc2, ['foo', 'bar']);

  // Despite not sending anything (ICE not connected) both outbound-rtp stats
  // objects should appear immediately.
  const report = await pc1.getStats();
  const outboundRtpFoo =
      report.values().find(s => s.type == 'outbound-rtp' && s.rid == 'foo');
  const outboundRtpBar =
      report.values().find(s => s.type == 'outbound-rtp' && s.rid == 'bar');
  assert_not_equals(outboundRtpFoo, undefined);
  assert_not_equals(outboundRtpFoo.ssrc, undefined);
  assert_not_equals(outboundRtpBar, undefined);
  assert_not_equals(outboundRtpBar.ssrc, undefined);
}, `RTCOutboundRtpStreamStats exists per simulcast encoding`);

promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());
  pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
  pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);

  // Negotaite to send, but don't send anything yet (track is null).
  const {sender} = pc1.addTransceiver('video');
  await pc1.setLocalDescription();
  await pc2.setRemoteDescription(pc1.localDescription);
  await pc2.setLocalDescription();
  await pc1.setRemoteDescription(pc2.localDescription);
  assert_false(await hasStats(pc2, 'inbound-rtp'),
               'inbound-rtp does not exist before packets are received');

  // Start sending. This results in inbound-rtp being created.
  const stream = await getNoiseStream({video:true});
  const [track] = stream.getTracks();
  t.add_cleanup(() => track.stop());
  await sender.replaceTrack(track);
  const inboundRtp = await getStatsTypePollUntilItExists(pc2, 'inbound-rtp');
  assert_not_equals(
      inboundRtp, null,
      'inbound-rtp should be created in response to the sender having a track');
  assert_greater_than(
      inboundRtp.packetsReceived, 0,
      'inbound-rtp must only exist after packets have been received');
}, `RTCInboundRtpStreamStats are created by packet reception`);

[{name: "pc", statsSource: pc => pc, kind: "audio"},
 {name: "sender", statsSource: pc => pc.getSenders()[0], kind: "audio"},
 {name: "pc", statsSource: pc => pc, kind: "video"},
 {name: "sender", statsSource: pc => pc.getSenders()[0], kind: "video"}
].forEach(({name, statsSource, kind}) => promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());
  pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
  pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);

  // Check statsSource for the outbound-rtp stats object.
  const getOutboundRtpStats = async () =>
    await getStatsTypePollUntilItExists(statsSource(pc1), 'outbound-rtp');

  pc1.addTransceiver(kind);
  await pc1.setLocalDescription();
  await pc2.setRemoteDescription(pc1.localDescription);
  await pc2.setLocalDescription();
  await pc1.setRemoteDescription(pc2.localDescription);

  {
    const stats = await getOutboundRtpStats();
    assert_not_equals(
      stats, null,
      `outbound-rtp should be created in ${name}.getStats() in response to the pc.addTransceiver("${kind}")`);
  }
}, `RTCOutboundRtpStreamStats exist in ${name}.getStats() after created with a null track through pc.addTransceiver("${kind}")`));

[{name: "pc", statsSource: pc => pc},
 {name: "sender", statsSource: pc => pc.getSenders()[0]}
].forEach(({name, statsSource}) => promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());
  pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
  pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);

  // Check statsSource for the outbound-rtp stats object.
  const getOutboundRtpStats = async () =>
    await getStatsTypePollUntilItExists(statsSource(pc1), 'outbound-rtp');

  const stream = await getNoiseStream({video:true});

  const {sender} = pc1.addTransceiver(stream.getTracks()[0]);
  await pc1.setLocalDescription();
  await pc2.setRemoteDescription(pc1.localDescription);
  await pc2.setLocalDescription();
  await pc1.setRemoteDescription(pc2.localDescription);

  // Wait for packets to be received
  {
    const stats = await getOutboundRtpStats();
    assert_not_equals(
      stats, null,
      `outbound-rtp should be created in ${name}.getStats() in response to the sender having a track`);
  }

  // Stop sending. This should not remove the outbound-rtp stats object.
  await sender.replaceTrack(null);
  // Check that the outbound-rtp stats object remains.
  {
    const stats = await getOutboundRtpStats();
    assert_not_equals(
        stats, null,
        `outbound-rtp should remain in ${name}.getStats() after sender.replaceTrack(null)`);
  }
}, `RTCOutboundRtpStreamStats remain in ${name}.getStats() after sender.replaceTrack(null)`));

promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());
  pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
  pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);

  // Negotiate a dummy m-section for DTLS to be established.
  pc1.addTransceiver('video', {direction:'sendonly'});
  await pc1.setLocalDescription();
  await pc2.setRemoteDescription(pc1.localDescription);
  await pc2.setLocalDescription();
  await pc1.setRemoteDescription(pc2.localDescription);

  // Offer to receive.
  pc1.addTransceiver('video', {direction:'recvonly'});
  await pc1.setLocalDescription();
  await pc2.setRemoteDescription(pc1.localDescription);
  assert_false(await hasStats(pc1, 'inbound-rtp'),
               'inbound-rtp does not exist before packets are received');
  // Answer to send.
  const transceivers = pc2.getTransceivers();
  assert_equals(transceivers.length, 2);
  const transceiver = transceivers[1];
  const stream = await getNoiseStream({video:true});
  const [track] = stream.getTracks();
  t.add_cleanup(() => track.stop());
  await transceiver.sender.replaceTrack(track);
  transceiver.direction = 'sendonly';
  await pc2.setLocalDescription();

  // We never set the remote answer.
  assert_equals(pc1.signalingState, 'have-local-offer');
  // But because of early media, we're still able to receive packets.
  // - Whether or not we unmute the track in response to this is outside the
  //   scope of this test.
  const inboundRtp = await getStatsTypePollUntilItExists(pc1, 'inbound-rtp');
  assert_not_equals(
      inboundRtp, null,
      'inbound-rtp should be created in the early media use case');
  assert_greater_than(
      inboundRtp.packetsReceived, 0,
      'inbound-rtp must only exist after packets have been received');
}, `RTCInboundRtpStreamStats exists for early media`);
</script>