summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webrtc/protocol/RTCPeerConnection-payloadTypes.html
blob: 066fc2e085e32da5c230806c4511ed52577e5048 (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
<!DOCTYPE html>
<html>
<head>
<title>RTCPeerConnection RTP payload types</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>

// Test that when creating an offer we do not run out of valid payload types.
promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());

  pc1.addTransceiver('audio', { direction: 'recvonly' });
  pc1.addTransceiver('video', { direction: 'recvonly' });
  const offer = await pc1.createOffer();

  // Extract all payload types from the m= lines.
  const payloadTypes = offer.sdp.split('\n')
    .map(line => line.trim())
    .filter(line => line.startsWith('m='))
    .map(line => line.split(' ').slice(3).join(' '))
    .join(' ')
    .split(' ')
    .map(payloadType => parseInt(payloadType, 10));

  // The list of allowed payload types is taken from here
  // https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-1.
  const forbiddenPayloadTypes = payloadTypes
    .filter(payloadType => {
      if (payloadType >= 96 && payloadType <= 127) {
        return false;
      }
      if (payloadType >= 72 && payloadType < 96) {
        return true;
      }
      if (payloadType >= 35 && payloadType < 72) {
        return false;
      }
      // TODO: Check against static payload type list.
      return false;
    });
  assert_equals(forbiddenPayloadTypes.length, 0)
}, 'createOffer with the maximum set of codecs does not generate invalid payload types');
</script>
</body>
</html>