File: rtp-stats-lifetime.https.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (102 lines) | stat: -rw-r--r-- 3,796 bytes parent folder | download | duplicates (9)
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
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.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 getInboundRtpPollUntilItExists(pc, 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 == 'inbound-rtp') {
        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(() => pc1.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(() => pc1.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();
  await sender.replaceTrack(track);
  const inboundRtp = await getInboundRtpPollUntilItExists(pc2);
  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`);
</script>