summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_basicVideoVerifyRtpHeaderExtensions.html
blob: 7874e52a10e1421a062dd1c994c91334a0ad19be (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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="application/javascript" src="parser_rtp.js"></script>
  <script type="application/javascript" src="sdpUtils.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1416932",
    title: "Basic video-only peer connection and verify rtp header extensions"
  });

  var test;
  runNetworkTest(function (options) {
    test = new PeerConnectionTest(options);
    test.setMediaConstraints([{video: true}], [{video: true}]);

    let getRtpPacketWithExtension = (pc, extension) => {
      // we only examine received packets
      let sending = false;
      pc.mozEnablePacketDump(0, "rtp", sending);
      return new Promise((res, rej) =>
        pc.mozSetPacketCallback((...args) => {
          const packet = ParseRtpPacket(args[3]);
          info(`midId = ${extension} packet = ${JSON.stringify(packet, null, 2)}`);
          if (packet.header.extensions.find(e => e.id == extension) !== undefined) {
            res(packet);
            pc.mozSetPacketCallback(() => {});
            pc.mozDisablePacketDump(0, "rtp", sending);
          }
        })
      );
    }

    let havePacketWithMid;
    let sdpExtmaps;

    // MID can stop being sent when acked causing failures if packets are checked later.
    // Starting packet sniffer before PC_LOCAL_SET_REMOTE_DESCRIPTION to be ready
    // to inspect packets ahead of any packets arriving.
    test.chain.insertBefore('PC_LOCAL_SET_REMOTE_DESCRIPTION', [
      function PC_REMOTE_FIND_RTP_PACKETS_WITH_MIDID() {

        sdpExtmaps = sdputils.findExtmapIdsUrnsDirections(test.originalAnswer.sdp);
        const [midId] = sdpExtmaps.find(([, urn]) => urn == "urn:ietf:params:rtp-hdrext:sdes:mid");
        const pc = SpecialPowers.wrap(test.pcRemote._pc);
        havePacketWithMid = getRtpPacketWithExtension(pc, midId);
      }
    ]);

    test.chain.insertBefore('PC_REMOTE_WAIT_FOR_MEDIA_FLOW', [
      async function PC_REMOTE_CHECK_RTP_HEADER_EXTS_AGAINST_SDP() {

        const sdpExtmapIds = sdpExtmaps.map(e => e[0]);
        const packet = await havePacketWithMid;
        const extIds = packet.header.extensions.map(e => `${e.id}`);
        // make sure we got the same number of rtp header extensions in
        // the received packet as were negotiated in the sdp.  Then
        // check to make sure each of the received extension ids were in
        // the sdp.
        is(sdpExtmapIds.length, extIds.length,
           `number of sdp ids match received ids ` +
           `${JSON.stringify(sdpExtmapIds)} == ${JSON.stringify(extIds)}\n` +
           `sdp = ${test.originalAnswer.sdp}\n` +
           `packet = ${JSON.stringify(packet, null, 2)}`);
        // note, we are comparing a number (from the parsed rtp packet)
        // and a string (from the answer sdp)
        ok(extIds.every(id => sdpExtmapIds.includes(id)) &&
           sdpExtmapIds.every(id => extIds.includes(id)),
          `extension id arrays equivalent`);
      }
    ]);

    return test.run();
  });
</script>
</pre>
</body>
</html>