summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_rtcp_rsize.html
blob: 25270984ea54aef4bce2fe5b287328c475d677d0 (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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="application/javascript" src="stats.js"></script>
  <script type="application/javascript" src="sdpUtils.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1279153",
    title: "rtcp-rsize",
    visible: true
  });

  // 0) Use webrtc-sdp
  // 1) ADD RTCP-RISZE to all video m-sections
  // 2) Check for RTCP-RSIZE in ANSWER
  // 3) Wait for media to flow
  // 4) Wait for RTCP stats

  runNetworkTest(async function (options) {
    const test = new PeerConnectionTest(options);

    let mSectionsAltered = 0;

    test.chain.insertAfter("PC_LOCAL_CREATE_OFFER", [
      function PC_LOCAL_ADD_RTCP_RSIZE(test) {
        const lines = test.originalOffer.sdp.split("\r\n");
        info(`SDP before rtcp-rsize: ${lines.join('\n')}`);
        // Insert an rtcp-rsize for each m section
        const rsizeAdded = lines.flatMap(line => {
          if (line.startsWith("m=video")) {
            mSectionsAltered = mSectionsAltered + 1;
            return [line, "a=rtcp-rsize"];
          }
          return [line];
        });
        test.originalOffer.sdp = rsizeAdded.join("\r\n");
        info(`SDP with rtcp-rsize: ${rsizeAdded.join("\n")}`);
        is(mSectionsAltered, 1, "We only altered 1 msection")
    }]);

    // Check that the rtcp-rsize makes into the answer
    test.chain.insertAfter("PC_LOCAL_SET_REMOTE_DESCRIPTION", [
      function PC_LOCAL_CHECK_RTCP_RSIZE(test) {
        const msections = sdputils.getMSections(test.pcLocal._pc.currentRemoteDescription.sdp);
        var alteredMSectionsFound = 0;
        for (msection of msections) {
          if (msection.startsWith("m=video")) {
            ok(msection.includes("\r\na=rtcp-rsize\r\n"), "video m-section includes RTCP-RSIZE");
            alteredMSectionsFound = alteredMSectionsFound + 1;
          } else {
            ok(!msection.includes("\r\na=rtcp-rsize\r\n"), "audio m-section does not include RTCP-RSIZE");
          }
        }
        is(alteredMSectionsFound, mSectionsAltered, "correct number of msections found");
      }
    ]);

    // Make sure that we are still getting RTCP stats
    test.chain.insertAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW",
      async function PC_LOCAL_AND_REMOTE_CHECK_FOR_RTCP_STATS(test) {
        await Promise.all([
          waitForSyncedRtcp(test.pcLocal._pc),
          waitForSyncedRtcp(test.pcRemote._pc),
        ]);
        // The work is done by waitForSyncedRtcp which will throw if
        // RTCP stats are not received.
        info("RTCP stats received!");
      },
    );
    test.setMediaConstraints([{audio: true}, {video: true}], []);
    await test.run();
  });

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