summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webrtc/simulcast/setParameters-active.https.html
blob: 54191059a0628a50eb96f1b631b5ce4e1fabaf23 (plain)
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
<!doctype html>
<meta charset=utf-8>
<title>RTCPeerConnection Simulcast Tests - setParameters/active</title>
<meta name="timeout" content="long">
<script src="../third_party/sdp/sdp.js"></script>
<script src="simulcast.js"></script>
<script src="../RTCPeerConnection-helper.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="../../mediacapture-streams/permission-helper.js"></script>
<script>
async function queryReceiverStats(pc) {
  const inboundStats =
    await Promise.all(pc.getReceivers().map(async receiver => {
    const receiverStats = await receiver.getStats();
    let inboundStat;
    receiverStats.forEach(stat => {
      if (stat.type === 'inbound-rtp') {
        inboundStat = stat;
      }
    });
    return inboundStat;
  }));
  return inboundStats.map(s => s.framesDecoded);
}

promise_test(async t => {
  const rids = [0, 1];
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());

  await negotiateSimulcastAndWaitForVideo(t, rids, pc1, pc2);

  // Deactivate first sender.
  const parameters = pc1.getSenders()[0].getParameters();
  parameters.encodings[0].active = false;
  await pc1.getSenders()[0].setParameters(parameters);

  // Assert (almost) no new frames are received on the first encoding.
  // Without any action we would expect to have received around 30fps.
  await new Promise(resolve => t.step_timeout(resolve, 200)); // Wait a bit.
  const initialStats = await queryReceiverStats(pc2);
  await new Promise(resolve => t.step_timeout(resolve, 1000)); // Wait more.
  const subsequentStats = await queryReceiverStats(pc2);

  assert_equals(subsequentStats[0], initialStats[0]);
  assert_greater_than(subsequentStats[1], initialStats[1]);
}, 'Simulcast setParameters active=false on first encoding stops sending frames for that encoding');

promise_test(async t => {
  const rids = [0, 1];
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());

  await negotiateSimulcastAndWaitForVideo(t, rids, pc1, pc2);

  // Deactivate second sender.
  const parameters = pc1.getSenders()[0].getParameters();
  parameters.encodings[1].active = false;
  await pc1.getSenders()[0].setParameters(parameters);

  // Assert (almost) no new frames are received on the second encoding.
  // Without any action we would expect to have received around 30fps.
  await new Promise(resolve => t.step_timeout(resolve, 200)); // Wait a bit.
  const initialStats = await queryReceiverStats(pc2);
  await new Promise(resolve => t.step_timeout(resolve, 1000)); // Wait more.
  const subsequentStats = await queryReceiverStats(pc2);

  assert_equals(subsequentStats[1], initialStats[1]);
  assert_greater_than(subsequentStats[0], initialStats[0]);
}, 'Simulcast setParameters active=false on second encoding stops sending frames for that encoding');

promise_test(async t => {
  const rids = [0, 1];
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());

  await negotiateSimulcastAndWaitForVideo(t, rids, pc1, pc2);

  // Deactivate all senders.
  const parameters = pc1.getSenders()[0].getParameters();
  parameters.encodings.forEach(e => {
    e.active = false;
  });
  await pc1.getSenders()[0].setParameters(parameters);

  // Assert (almost) no new frames are received.
  // Without any action we would expect to have received around 30fps.
  await new Promise(resolve => t.step_timeout(resolve, 200)); // Wait a bit.
  const initialStats = await queryReceiverStats(pc2);
  await new Promise(resolve => t.step_timeout(resolve, 1000)); // Wait more.
  const subsequentStats = await queryReceiverStats(pc2);

  subsequentStats.forEach((framesDecoded, idx) => {
    assert_equals(framesDecoded, initialStats[idx]);
  });
}, 'Simulcast setParameters active=false stops sending frames');
</script>