summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_twoAudioVideoStreamsCombinedNoBundle.html
blob: 8b825db6175cc0f5e350290cb33d3e0291eac74e (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
107
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="application/javascript" src="stats.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
  bug: "1225722",
  title: "Multistream: Two audio/video streams without BUNDLE"
});

runNetworkTest(async (options = {}) => {
  // Disable platform encodre for SW MFT encoder causes some stats
  // exceeding the test thresholds.
  // E.g. inbound-rtp.packetsDiscarded value=118 >= 100.
  await matchPlatformH264CodecPrefs();

  options.bundle = false;
  const test = new PeerConnectionTest(options);
  test.setMediaConstraints(
    [{audio: true, video: true}, {audio: true, video: true}],
    [{audio: true, video: true}, {audio: true, video: true}]
  );

  // Test stats, including that codec stats do not coalesce without BUNDLE.
  const testNonBundledStats = async pc => {
    // This is basically PC_*_TEST_*_STATS fleshed out, but uses
    // sender/receiver.getStats instead of pc.getStats, since the codec stats
    // code assumes at most one sender and at most one receiver.
    await waitForSyncedRtcp(pc);
    const senderPromises = pc.getSenders().map(obj => obj.getStats());
    const receiverPromises = pc.getReceivers().map(obj => obj.getStats());
    const senderStats = await Promise.all(senderPromises);
    const receiverStats = await Promise.all(receiverPromises);
    for (const stats of [...senderStats, ...receiverStats]) {
      checkExpectedFields(stats);
      pedanticChecks(stats);
    }
    for (const stats of senderStats) {
      checkSenderStats(stats, 1);
    }
  };

  test.chain.insertAfter("PC_LOCAL_WAIT_FOR_MEDIA_FLOW", [
    async function PC_LOCAL_TEST_LOCAL_NONBUNDLED_STATS(test) {
      await testNonBundledStats(test.pcLocal._pc);
    },
  ]);

  test.chain.insertAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW", [
    async function PC_REMOTE_TEST_LOCAL_NONBUNDLED_STATS(test) {
      await testNonBundledStats(test.pcRemote._pc);
    },
  ]);

  const testNonCoalescedCodecStats = stats => {
    const codecs = [...stats.values()]
          .filter(({type}) => type == "codec");
    is([...stats.values()].filter(({type}) => type.endsWith("rtp")).length, 16,
      "Expected: 4 outbound, 4 remote-inbound, 4 inbound, 4 remote-inbound");
    const codecTypes = new Set(codecs.map(({codecType}) => codecType));
    is(codecTypes.size, 1,
      "Should have identical encode and decode configurations (and stats)");
    is(codecTypes[0], undefined,
      "Should have identical encode and decode configurations (and stats)");
    const transportIds = new Set(codecs.map(({transportId}) => transportId));
    is(transportIds.size, 4,
      "Should have registered four transports for two sendrecv streams");
    for (const transportId of transportIds) {
      is(codecs.filter(c => c.transportId == transportId).length, 1,
        "Should have registered one codec per transport without BUNDLE");
    }
    for (const prefix of ["audio", "video"]) {
      const prefixed = codecs.filter(c => c.mimeType.startsWith(prefix));
      is(prefixed.length, 2, `Should have registered two ${prefix} codecs`);
      if (prefixed.length == 2) {
        is(prefixed[0].payloadType, prefixed[1].payloadType,
          "same payloadType");
        isnot(prefixed[0].transportId, prefixed[1].transportId,
          "different transportIds");
        is(prefixed[0].mimeType, prefixed[1].mimeType, "same mimeType");
        is(prefixed[0].clockRate, prefixed[1].clockRate, "same clockRate");
        is(prefixed[0].channels, prefixed[1].channels, "same channels");
        is(prefixed[0].sdpFmtpLine, prefixed[1].sdpFmtpLine,
          "same sdpFmtpLine");
      }
    }
  };

  test.chain.append([
    async function PC_LOCAL_TEST_NON_COALESCED_CODEC_STATS() {
      testNonCoalescedCodecStats(await test.pcLocal._pc.getStats());
    },
    async function PC_REMOTE_TEST_NON_COALESCED_CODEC_STATS() {
      testNonCoalescedCodecStats(await test.pcRemote._pc.getStats());
    },
  ]);

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