summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_encodingsNegotiation.html
blob: f46d7eb0d24666b8146aaa99fa09c2e7d7e6a5cd (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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="application/javascript" src="simulcast.js"></script>
  <script type="application/javascript" src="helpers_from_wpt/sdp.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
  bug: "1401592",
  title: "Simulcast negotiation tests",
  visible: true
});

// simulcast negotiation is mostly tested in wpt, but we test a few
// implementation-specific things here.
const tests = [
  async function checkVideoEncodingLimit() {
    const pc1 = new RTCPeerConnection();
    const pc2 = new RTCPeerConnection();

    const stream = await navigator.mediaDevices.getUserMedia({video: true});
    const sender = pc1.addTrack(stream.getTracks()[0]);
    pc2.addTrack(stream.getTracks()[0]);

    await doOfferToRecvSimulcast(pc2, pc1, ["1", "2", "3", "4"]);

    const {encodings} = sender.getParameters();
    const rids = encodings.map(({rid}) => rid);
    isDeeply(rids, ["1", "2", "3"]);

    pc1.close();
    pc2.close();
    stream.getTracks().forEach(track => track.stop());
  },

  // wpt currently does not assume support for 3 encodings, which limits the
  // effectiveness of its powers-of-2 test (since it can test only for 1 and 2)
  async function checkScaleResolutionDownByAutoFillPowersOf2() {
    const pc1 = new RTCPeerConnection();
    const pc2 = new RTCPeerConnection();
    const stream = await navigator.mediaDevices.getUserMedia({video: true});
    const sender = pc1.addTrack(stream.getTracks()[0]);
    pc2.addTrack(stream.getTracks()[0]);

    await doOfferToRecvSimulcast(pc2, pc1, ["1", "2", "3"]);

    const {encodings} = sender.getParameters();
    const scaleValues = encodings.map(({scaleResolutionDownBy}) => scaleResolutionDownBy);
    isDeeply(scaleValues, [4, 2, 1]);
  },

  async function checkLibwebrtcRidLengthLimit() {
    const pc1 = new RTCPeerConnection();
    const pc2 = new RTCPeerConnection();

    const stream = await navigator.mediaDevices.getUserMedia({video: true});
    const sender = pc1.addTrack(stream.getTracks()[0]);
    pc2.addTrack(stream.getTracks()[0]);

    await doOfferToRecvSimulcast(pc2, pc1, ["foo", "wibblywobblyjeremybearimy"]);
    const {encodings} = sender.getParameters();
    const rids = encodings.map(({rid}) => rid);
    isDeeply(rids, ["foo"]);

    pc1.close();
    pc2.close();
    stream.getTracks().forEach(track => track.stop());
  },
];

runNetworkTest(async () => {
  for (const test of tests) {
    info(`Running test: ${test.name}`);
    await test();
    info(`Done running test: ${test.name}`);
  }
});

</script>
</pre>
</body>
</html>