tor-browser

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

test_MediaSource_capture_gc.html (2211B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test garbage collection of captured stream, when playing a MediaSource</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7  <script type="text/javascript" src="mediasource.js"></script>
      8 </head>
      9 <pre id="test">
     10 <script class="testbody" type="text/javascript">
     11 function forceGC() {
     12  SpecialPowers.gc();
     13  SpecialPowers.forceGC();
     14  SpecialPowers.forceCC();
     15 }
     16 
     17 SimpleTest.waitForExplicitFinish();
     18 
     19 window.onload = async function() {
     20 // Create an infinite source using a MediaSource
     21 let el = document.createElement("audio");
     22 const ms = new MediaSource();
     23 el.src = URL.createObjectURL(ms);
     24 await once(ms, "sourceopen");
     25 const sb = ms.addSourceBuffer("video/mp4");
     26 await fetchAndLoad(sb, "bipbop/bipbop_audio", ["init"], ".mp4");
     27 await fetchAndLoad(sb, "bipbop/bipbop_audio", range(1, 11), ".m4s");
     28 setInterval(async function() {
     29  sb.timestampOffset =  sb.buffered.end(sb.buffered.length - 1);
     30  await fetchAndLoad(sb, "bipbop/bipbop_audio", range(1, 11), ".m4s");
     31 }, 8000);
     32 el.play();
     33 
     34 // Analyze the media element output.
     35 const ac = new AudioContext;
     36 const analyzer = ac.createAnalyser();
     37 
     38 // bug 1703603
     39 const stream = el.mozCaptureStreamUntilEnded();
     40 const mss = ac.createMediaStreamSource(stream);
     41 const gain = ac.createGain();
     42 // compensate mochitest volume scaling, but don't connect to the AudioContext's
     43 // destination to avoid noise during the test
     44 gain.gain.value = 90;
     45 mss.connect(gain).connect(analyzer);
     46 
     47 
     48 // Drop the media element reference: it is supposed to be kept alive by the
     49 // AudioContext via the `MediaStream`.
     50 el = null;
     51 
     52 // check whether the media element is still playing using the analyzer, spam the
     53 // GC to ensure all refs are kept.
     54 const buf = new Float32Array(analyzer.frequencyBinCount);
     55 const startTime = Date.now();
     56 function checkNonSilent() {
     57  analyzer.getFloatFrequencyData(buf);
     58  forceGC();
     59  // Wait a good 20 seconds.
     60  if (Date.now() - startTime < 2000) {
     61    requestAnimationFrame(checkNonSilent);
     62  } else {
     63    ok(true, "All objects were kept alive.");
     64    SimpleTest.finish();
     65  }
     66 }
     67 checkNonSilent();
     68 }
     69 </script>
     70 </pre>
     71 </body>
     72 </html>