tor-browser

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

RTCRtpSender-encode-same-track-twice.https.html (2582B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <meta name="timeout" content="long">
      4 <title></title>
      5 <script src=/resources/testharness.js></script>
      6 <script src=/resources/testharnessreport.js></script>
      7 <script src="RTCPeerConnection-helper.js"></script>
      8 <script>
      9  'use strict';
     10 
     11  // A generous testing duration that will not time out on bots.
     12  const kEncodeDurationMs = 10000;
     13 
     14  // The crash this test aims to repro was easy to reproduce using a normal
     15  // getUserMedia() track when running the browser normally, e.g. by navigating
     16  // to https://jsfiddle.net/henbos/fc7gk3ve/11/. But for some reason, the fake
     17  // tracks returned by getUserMedia() when inside this testing environment had
     18  // a much harder time with reproducibility.
     19  //
     20  // By creating a high FPS canvas capture track we are able to repro reliably
     21  // in this WPT environment as well.
     22  function whiteNoise(width, height) {
     23    const canvas =
     24        Object.assign(document.createElement('canvas'), {width, height});
     25    const ctx = canvas.getContext('2d');
     26    ctx.fillRect(0, 0, width, height);
     27    const p = ctx.getImageData(0, 0, width, height);
     28    requestAnimationFrame(function draw () {
     29      for (let i = 0; i < p.data.length; i++) {
     30        const color = Math.random() * 255;
     31        p.data[i++] = color;
     32        p.data[i++] = color;
     33        p.data[i++] = color;
     34      }
     35      ctx.putImageData(p, 0, 0);
     36      requestAnimationFrame(draw);
     37    });
     38    return canvas.captureStream();
     39  }
     40 
     41  promise_test(async t => {
     42    const pc1 = new RTCPeerConnection();
     43    t.add_cleanup(() => pc1.close());
     44    const pc2 = new RTCPeerConnection();
     45    t.add_cleanup(() => pc2.close());
     46 
     47    const stream = whiteNoise(640, 480);
     48    const [track] = stream.getTracks();
     49    const t1 = pc1.addTransceiver("video", {direction:"sendonly"});
     50    const t2 = pc1.addTransceiver("video", {direction:"sendonly"});
     51    await t1.sender.replaceTrack(track);
     52    await t2.sender.replaceTrack(track);
     53 
     54    exchangeIceCandidates(pc1, pc2);
     55    await pc1.setLocalDescription();
     56    await pc2.setRemoteDescription(pc1.localDescription);
     57    await pc2.setLocalDescription();
     58    await pc1.setRemoteDescription(pc2.localDescription);
     59 
     60    // In Chromium, each sender instantiates a VideoStreamEncoder during
     61    // negotiation. This test reproduces https://crbug.com/webrtc/11485 where a
     62    // race causes a crash when multiple VideoStreamEncoders are encoding the
     63    // same MediaStreamTrack.
     64    await new Promise(resolve => t.step_timeout(resolve, kEncodeDurationMs));
     65  }, "Two RTCRtpSenders encoding the same track");
     66 </script>