File: RTCRtpParameters-encodings.html

package info (click to toggle)
thunderbird 1%3A60.9.0-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,339,492 kB
  • sloc: cpp: 5,457,040; ansic: 2,360,385; python: 596,167; asm: 340,963; java: 326,296; xml: 258,830; sh: 84,445; makefile: 23,705; perl: 17,317; objc: 3,768; yacc: 1,766; ada: 1,681; lex: 1,364; pascal: 1,264; cs: 879; exp: 527; php: 436; lisp: 258; ruby: 153; awk: 152; sed: 53; csh: 27
file content (396 lines) | stat: -rw-r--r-- 13,175 bytes parent folder | download | duplicates (2)
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<!doctype html>
<meta charset=utf-8>
<title>RTCRtpParameters encodings</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:
  //   validateSenderRtpParameters

  /*
    5.1.  RTCPeerConnection Interface Extensions
      partial interface RTCPeerConnection {
        RTCRtpTransceiver           addTransceiver((MediaStreamTrack or DOMString) trackOrKind,
                                                   optional RTCRtpTransceiverInit init);
        ...
      };

      dictionary RTCRtpTransceiverInit {
        RTCRtpTransceiverDirection         direction = "sendrecv";
        sequence<MediaStream>              streams;
        sequence<RTCRtpEncodingParameters> sendEncodings;
      };

    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 RTCRtpEncodingParameters {
        [readonly]
        unsigned long       ssrc;

        [readonly]
        RTCRtpRtxParameters rtx;

        [readonly]
        RTCRtpFecParameters fec;

        RTCDtxStatus        dtx;
        boolean             active;
        RTCPriorityType     priority;
        unsigned long       ptime;
        unsigned long       maxBitrate;
        double              maxFramerate;

        [readonly]
        DOMString           rid;

        double              scaleResolutionDownBy;
      };

      dictionary RTCRtpRtxParameters {
        [readonly]
        unsigned long ssrc;
      };

      dictionary RTCRtpFecParameters {
        [readonly]
        unsigned long ssrc;
      };

      enum RTCDtxStatus {
        "disabled",
        "enabled"
      };

      enum RTCPriorityType {
        "very-low",
        "low",
        "medium",
        "high"
      };

      getParameters
        - encodings is set to the value of the [[send encodings]] internal slot.
   */

  // Get the first encoding in param.encodings.
  // Asserts that param.encodings has at least one element.
  function getFirstEncoding(param) {
    const { encodings } = param;
    assert_equals(encodings.length, 1);
    return encodings[0];
  }

  /*
    5.1.  addTransceiver
      7. Create an RTCRtpSender with track, streams and sendEncodings and let sender
         be the result.

    5.2.  create an RTCRtpSender
      5.  Let sender have a [[send encodings]] internal slot, representing a list
          of RTCRtpEncodingParameters dictionaries.
      6.  If sendEncodings is given as input to this algorithm, and is non-empty,
          set the [[send encodings]] slot to sendEncodings.

          Otherwise, set it to a list containing a single RTCRtpEncodingParameters
          with active set to true.
   */
  test(() => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio');
    const param = transceiver.sender.getParameters();
    validateSenderRtpParameters(param);
    const { encodings } = param;
    const encoding = getFirstEncoding(param);

    assert_equals(encoding.active, true);
  }, 'addTransceiver() with undefined sendEncodings should have default encoding parameter with active set to true');

  test(() => {
    const pc = new RTCPeerConnection();
    const transceiver = pc.addTransceiver('audio', { sendEncodings: [] });

    const param = transceiver.sender.getParameters();
    validateSenderRtpParameters(param);
    const { encodings } = param;
    const encoding = getFirstEncoding(param);

    assert_equals(encoding.active, true);
  }, 'addTransceiver() with empty list sendEncodings should have default encoding parameter with active set to true');

  /*
    5.2.  create an RTCRtpSender
      To create an RTCRtpSender with a MediaStreamTrack , track, a list of MediaStream
      objects, streams, and optionally a list of RTCRtpEncodingParameters objects,
      sendEncodings, run the following steps:
        5.  Let sender have a [[send encodings]] internal slot, representing a list
            of RTCRtpEncodingParameters dictionaries.

        6.  If sendEncodings is given as input to this algorithm, and is non-empty,
            set the [[send encodings]] slot to sendEncodings.

    5.2.  getParameters
      - encodings is set to the value of the [[send encodings]] internal slot.
   */
  test(() => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio', {
      sendEncodings: [{
        dtx: 'enabled',
        active: false,
        priority: 'low',
        ptime: 5,
        maxBitrate: 8,
        maxFramerate: 25,
        rid: 'foo'
      }]
    });

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

    assert_equals(encoding.dtx, 'enabled');
    assert_equals(encoding.active, false);
    assert_equals(encoding.priority, 'low');
    assert_equals(encoding.ptime, 5);
    assert_equals(encoding.maxBitrate, 8);
    assert_equals(encoding.maxFramerate, 25);
    assert_equals(encoding.rid, 'foo');

  }, `sender.getParameters() should return sendEncodings set by addTransceiver()`);

  /*
    5.2.  setParameters
      3.  Let N be the number of RTCRtpEncodingParameters stored in sender's internal
          [[send encodings]] slot.
      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(t => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio');
    const param = sender.getParameters();
    validateSenderRtpParameters(param);

    const { encodings } = param;
    assert_equals(encodings.length, 1);

    // {} is valid RTCRtpEncodingParameters because all fields are optional
    encodings.push({});
    assert_equals(param.encodings.length, 2);

    return promise_rejects(t, 'InvalidModificationError',
      sender.setParameters(param));

  }, `sender.setParameters() with mismatch number of encodings should reject with InvalidModificationError`);

  promise_test(t => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio');
    const param = sender.getParameters();
    validateSenderRtpParameters(param);

    param.encodings = undefined;

    return promise_rejects(t, 'InvalidModificationError',
      sender.setParameters(param));

  }, `sender.setParameters() with encodings unset should reject with InvalidModificationError`);

  promise_test(t => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio');

    const param = sender.getParameters();
    validateSenderRtpParameters(param);
    const encoding = getFirstEncoding(param);
    const { ssrc } = encoding;

    // ssrc may not be set since it is optional
    if(ssrc === undefined) {
      encoding.ssrc = 2;
    } else {
      // If it is set, increase the number by 1 to make it different from original
      encoding.ssrc = ssrc + 1;
    }

    return promise_rejects(t, 'InvalidModificationError',
      sender.setParameters(param));

  }, `setParameters() with modified encoding.ssrc field should reject with InvalidModificationError`);

  promise_test(t => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio');

    const param = sender.getParameters();
    validateSenderRtpParameters(param);
    const encoding = getFirstEncoding(param);
    const { rtx } = encoding;

    if(rtx === undefined) {
      encoding.rtx = { ssrc: 2 };
    } else if(rtx.ssrc === undefined) {
      rtx.ssrc = 2;
    } else {
      rtx.ssrc += 1;
    }

    return promise_rejects(t, 'InvalidModificationError',
      sender.setParameters(param));

  }, `setParameters() with modified encoding.rtx field should reject with InvalidModificationError`);

  promise_test(t => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio');

    const param = sender.getParameters();
    validateSenderRtpParameters(param);
    const encoding = getFirstEncoding(param);
    const { fec } = encoding;

    if(fec === undefined) {
      encoding.fec = { ssrc: 2 };
    } else if(fec.ssrc === undefined) {
      fec.ssrc = 2;
    } else {
      fec.ssrc += 1;
    }

    return promise_rejects(t, 'InvalidModificationError',
      sender.setParameters(param));

  }, `setParameters() with modified encoding.fec field should reject with InvalidModificationError`);

  promise_test(t => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio', {
      sendEncodings: [{ rid: 'foo' }],
    });

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

    assert_equals(encoding.rid, 'foo');

    encoding.rid = 'bar';
    return promise_rejects(t, 'InvalidModificationError',
      sender.setParameters(param));

  }, `setParameters() with modified encoding.rid field should reject with InvalidModificationError`);

  /*
    5.2.  setParameters
      8.  If the scaleResolutionDownBy parameter in the parameters argument has a
          value less than 1.0, abort these steps and return a promise rejected with
          a newly created RangeError.
   */
  promise_test(t => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio');

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

    encoding.scaleResolutionDownBy = 0.5;
    return promise_rejects(t, 'RangeError',
      sender.setParameters(param));

  }, `setParameters() with encoding.scaleResolutionDownBy field set to less than 1.0 should reject with RangeError`);

  promise_test(t => {
    const pc = new RTCPeerConnection();
    const { sender } = pc.addTransceiver('audio');

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

    encoding.scaleResolutionDownBy = 1.5;
    return sender.setParameters(param)
    .then(() => {
      const param = sender.getParameters();
      validateSenderRtpParameters(param);
      const encoding = getFirstEncoding(param);

      assert_approx_equals(encoding.scaleResolutionDownBy, 1.5, 0.01);
    });

  }, `setParameters() with encoding.scaleResolutionDownBy field set to greater than 1.0 should succeed`);

  // Helper function to test that modifying an encoding field should succeed
  function test_modified_encoding(field, value1, value2, desc) {
    promise_test(t => {
      const pc = new RTCPeerConnection();
      const { sender } = pc.addTransceiver('audio', {
        sendEncodings: [{
          [field]: value1
        }]
      });

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

      assert_equals(encoding[field], value1);
      encoding[field] = value2;

      return sender.setParameters(param)
      .then(() => {
        const param = sender.getParameters();
        validateSenderRtpParameters(param);
        const encoding = getFirstEncoding(param);
        assert_equals(encoding[field], value2);
      });
    }, desc);
  }

  test_modified_encoding('dtx', 'enabled', 'disabled',
    'setParameters() with modified encoding.dtx should succeed');

  test_modified_encoding('dtx', 'enabled', undefined,
    'setParameters() with unset encoding.dtx should succeed');

  test_modified_encoding('active', true, false,
    'setParameters() with modified encoding.active should succeed');

  test_modified_encoding('priority', 'very-low', 'high',
    'setParameters() with modified encoding.priority should succeed');

  test_modified_encoding('ptime', 2, 4,
    'setParameters() with modified encoding.ptime should succeed');

  test_modified_encoding('maxBitrate', 2, 4,
    'setParameters() with modified encoding.maxBitrate should succeed');

  test_modified_encoding('maxBitrate', 24, 16,
    'setParameters() with modified encoding.maxFramerate should succeed');

</script>