tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RTCRtpParameters-scalability.html (3605B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <meta name="timeout" content="long">
      4 <title>RTCRtpParameters encodings</title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/webrtc/dictionary-helper.js"></script>
      8 <script src="/webrtc/RTCRtpParameters-helper.js"></script>
      9 <script src="../webrtc/RTCPeerConnection-helper.js"></script>
     10 <script>
     11  'use strict';
     12 
     13  // Test is based on the following editor draft:
     14  // https://w3c.github.io/webrtc-svc/
     15 
     16  promise_test(async t => {
     17    const pc = new RTCPeerConnection();
     18    t.add_cleanup(() => pc.close());
     19    const { sender } = pc.addTransceiver('video', {
     20      sendEncodings: [{scalabilityMode: 'L1T3'}],
     21    });
     22 
     23    const param = sender.getParameters();
     24    const encoding = param.encodings[0];
     25 
     26    assert_equals(encoding.scalabilityMode, 'L1T3');
     27 
     28    encoding.scalabilityMode = 'L1T2';
     29    await sender.setParameters(param);
     30 
     31    const updatedParam = sender.getParameters();
     32    const updatedEncoding = updatedParam.encodings[0];
     33 
     34    assert_equals(updatedEncoding.scalabilityMode, 'L1T2');
     35  }, `Setting and updating scalabilityMode to a legal value should be accepted`);
     36 
     37  promise_test(async t => {
     38    const pc = new RTCPeerConnection();
     39    t.add_cleanup(() => pc.close());
     40    const { sender } = pc.addTransceiver('video');
     41    const param = sender.getParameters();
     42    const encoding = param.encodings[0];
     43    assert_true(!('scalabilityMode' in encoding));
     44  }, 'Not setting sendEncodings results in no mode info before negotiation');
     45 
     46  promise_test(async t => {
     47    const pc = new RTCPeerConnection();
     48    t.add_cleanup(() => pc.close());
     49    const { sender } = pc.addTransceiver('video', {
     50      sendEncodings: [{}],
     51    });
     52    const param = sender.getParameters();
     53    const encoding = param.encodings[0];
     54    assert_true(!('scalabilityMode' in encoding));
     55  }, 'Not setting a scalability mode results in no mode set before negotiation');
     56 
     57  promise_test(async t => {
     58      const pc = new RTCPeerConnection();
     59    t.add_cleanup(() => pc.close());
     60    assert_throws_dom('OperationError', () => {
     61      pc.addTransceiver('video', {
     62        sendEncodings: [{scalabilityMode: 'TotalNonsense'}],
     63      });
     64    });
     65  }, 'Setting a scalability mode to nonsense throws an exception');
     66 
     67  promise_test(async t => {
     68    const v = document.createElement('video');
     69    v.autoplay = true;
     70    const pc1 = new RTCPeerConnection();
     71    const pc2 = new RTCPeerConnection();
     72    t.add_cleanup(() => pc1.close());
     73    t.add_cleanup(() => pc2.close());
     74    const transceiver = pc1.addTransceiver('video', {
     75      sendEncodings: [{ scalabilityMode: 'L3T3' }],
     76    });
     77    // Before negotiation, the mode should be preserved.
     78    const param = transceiver.sender.getParameters();
     79    const encoding = param.encodings[0];
     80    assert_true('scalabilityMode' in encoding);
     81 
     82    // If L3T3 is not supported at all, abort test.
     83    assert_implements_optional(encoding.scalabilityMode === 'L3T3');
     84 
     85    pc2.ontrack = e => {
     86      // Pick a codec known to not have L3T3 support.
     87      const capabilities = RTCRtpReceiver.getCapabilities('video');
     88      const codec = capabilities.codecs.find(c => c.mimeType === 'video/VP8');
     89      assert_true(codec !== undefined);
     90      e.transceiver.setCodecPreferences([codec]);
     91    }
     92    exchangeIceCandidates(pc1, pc2);
     93    await exchangeOfferAnswer(pc1, pc2);
     94    const sendParams = pc1.getSenders()[0].getParameters();
     95    assert_not_equals(sendParams.encodings[0].scalabilityMode, 'L3T3');
     96  }, 'L3T3 on VP8 should return something other than L3T3');
     97 </script>