DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (4a45ed98fb43)

VCS Links

Line Code
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
<!doctype html>
<meta charset=utf-8>
<title>RTCRtpParameters codecs</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="dictionary-helper.js"></script>
<script src="RTCRtpParameters-helper.js"></script>
<script>
  'use strict';

  // Test is based on the following editor draft:
  // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html

  // The following helper functions are called from RTCRtpParameters-helper.js:
  //   doOfferAnswerExchange
  //   validateSenderRtpParameters

  /*
    5.2.  RTCRtpSender Interface
      interface RTCRtpSender {
        Promise<void>           setParameters(optional RTCRtpParameters parameters);
        RTCRtpParameters        getParameters();
      };

      dictionary RTCRtpParameters {
        DOMString                                 transactionId;
        sequence<RTCRtpEncodingParameters>        encodings;
        sequence<RTCRtpHeaderExtensionParameters> headerExtensions;
        RTCRtcpParameters                         rtcp;
        sequence<RTCRtpCodecParameters>           codecs;
        RTCDegradationPreference                  degradationPreference;
      };

      dictionary RTCRtpCodecParameters {
        [readonly]
        unsigned short payloadType;

        [readonly]
        DOMString      mimeType;

        [readonly]
        unsigned long  clockRate;

        [readonly]
        unsigned short channels;

        [readonly]
        DOMString      sdpFmtpLine;
      };

      getParameters
          - The codecs sequence is populated based on the codecs that have been negotiated
            for sending, and which the user agent is currently capable of sending.

            If setParameters has removed or reordered codecs, getParameters MUST return
            the shortened/reordered list. However, every time codecs are renegotiated by
            a new offer/answer exchange, the list of codecs MUST be restored to the full
            negotiated set, in the priority order indicated by the remote description,
            in effect discarding the effects of setParameters.

      codecs
        - When using the setParameters method, the codecs sequence from the corresponding
          call to getParameters can be reordered and entries can be removed, but entries
          cannot be added, and the RTCRtpCodecParameters dictionary members cannot be modified.
   */

  // Get the first codec from param.codecs.
  // Assert that param.codecs has at least one element
  function getFirstCodec(param) {
    const { codecs } = param;
    assert_greater_than(codecs.length, 0);
    return codecs[0];
  }

  /*
    5.2.  setParameters
      7.  If parameters.encodings.length is different from N, or if any parameter
          in the parameters argument, marked as a Read-only parameter, has a value
          that is different from the corresponding parameter value returned from
          sender.getParameters(), abort these steps and return a promise rejected
          with a newly created InvalidModificationError. Note that this also applies
          to transactionId.
   */
  promise_test(async t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());

    const { sender } = pc.addTransceiver('audio');
    await doOfferAnswerExchange(t, pc);

    const param = sender.getParameters();
    validateSenderRtpParameters(param);

    const codec = getFirstCodec(param);

    if(codec.payloadType === undefined) {
      codec.payloadType = 8;
    } else {
      codec.payloadType += 1;
    }

    return promise_rejects_dom(t, 'InvalidModificationError',
      sender.setParameters(param));
  }, 'setParameters() with codec.payloadType modified should reject with InvalidModificationError');

  promise_test(async t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());
    const { sender } = pc.addTransceiver('audio');
    await doOfferAnswerExchange(t, pc);
    const param = sender.getParameters();
    validateSenderRtpParameters(param);

    const codec = getFirstCodec(param);

    if(codec.mimeType === undefined) {
      codec.mimeType = 'audio/piedpiper';
    } else {
      codec.mimeType = `${codec.mimeType}-modified`;
    }

    return promise_rejects_dom(t, 'InvalidModificationError',
      sender.setParameters(param));
  }, 'setParameters() with codec.mimeType modified should reject with InvalidModificationError');

  promise_test(async t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());
    const { sender } = pc.addTransceiver('audio');
    await doOfferAnswerExchange(t, pc);
    const param = sender.getParameters();
    validateSenderRtpParameters(param);

    const codec = getFirstCodec(param);

    if(codec.clockRate === undefined) {
      codec.clockRate = 8000;
    } else {
      codec.clockRate += 1;
    }

    return promise_rejects_dom(t, 'InvalidModificationError',
      sender.setParameters(param));
  }, 'setParameters() with codec.clockRate modified should reject with InvalidModificationError');

  promise_test(async t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());
    const { sender } = pc.addTransceiver('audio');
    await doOfferAnswerExchange(t, pc);
    const param = sender.getParameters();
    validateSenderRtpParameters(param);

    const codec = getFirstCodec(param);

    if(codec.channels === undefined) {
      codec.channels = 6;
    } else {
      codec.channels += 1;
    }

    return promise_rejects_dom(t, 'InvalidModificationError',
      sender.setParameters(param));
  }, 'setParameters() with codec.channels modified should reject with InvalidModificationError');

  promise_test(async t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());
    const { sender } = pc.addTransceiver('audio');
    await doOfferAnswerExchange(t, pc);
    const param = sender.getParameters();
    validateSenderRtpParameters(param);

    const codec = getFirstCodec(param);

    if(codec.sdpFmtpLine === undefined) {
      codec.sdpFmtpLine = 'a=fmtp:98 0-15';
    } else {
      codec.sdpFmtpLine = `${codec.sdpFmtpLine};foo=1`;
    }

    return promise_rejects_dom(t, 'InvalidModificationError',
      sender.setParameters(param));
  }, 'setParameters() with codec.sdpFmtpLine modified should reject with InvalidModificationError');

  promise_test(async t => {
    const pc = new RTCPeerConnection();
    t.add_cleanup(() => pc.close());
    const { sender } = pc.addTransceiver('audio');
    await doOfferAnswerExchange(t, pc);
    const param = sender.getParameters();
    validateSenderRtpParameters(param);

    const { codecs } = param;

    codecs.push({
      payloadType: 2,
      mimeType: 'audio/piedpiper',
      clockRate: 1000,
      channels: 2
    });

    return promise_rejects_dom(t, 'InvalidModificationError',
      sender.setParameters(param));
  }, 'setParameters() with new codecs inserted should reject with InvalidModificationError');

</script>