tor-browser

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

test_peerConnection_setParameters_scaleResolutionDownBy_oldSetParameters.html (2986B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="pc.js"></script>
      5 </head>
      6 <body>
      7 <pre id="test">
      8 <script type="application/javascript">
      9 createHTML({
     10  bug: "1253499",
     11  title: "Live-updating scaleResolutionDownBy"
     12 });
     13 
     14 let sender, localElem, remoteElem;
     15 let originalWidth, originalHeight;
     16 let resolutionAlignment = 1;
     17 
     18 async function checkScaleDownBy(scale) {
     19  sender.setParameters({ encodings: [{ scaleResolutionDownBy: scale }] });
     20  await haveEvent(remoteElem, "resize", wait(5000, new Error("Timeout")));
     21 
     22  // Find the expected resolution. Internally we floor the exact scaling, then
     23  // shrink each dimension to the alignment requested by the encoder.
     24  let expectedWidth =
     25    originalWidth / scale - (originalWidth / scale % resolutionAlignment);
     26  let expectedHeight =
     27    originalHeight / scale - (originalHeight / scale % resolutionAlignment);
     28 
     29  is(remoteElem.videoWidth, expectedWidth,
     30    `Width should have scaled down by ${scale}`);
     31  is(remoteElem.videoHeight, expectedHeight,
     32    `Height should have scaled down by ${scale}`);
     33 }
     34 
     35 runNetworkTest(async function (options) {
     36  await pushPrefs(['media.peerconnection.video.lock_scaling', true]);
     37  if (navigator.userAgent.includes("Android")) {
     38    await pushPrefs(
     39        // [TODO] re-enable HW decoder after bug 1526207 is fixed.
     40        ["media.navigator.mediadatadecoder_vpx_enabled", false],
     41        // Use libwebrtc VP8 encoder to avoid unexpected resolution alignment on
     42        // some devices.
     43        ["media.webrtc.encoder_creation_strategy", 0],
     44        ["media.webrtc.hw.h264.enabled", false],
     45      );
     46  }
     47 
     48  let test = new PeerConnectionTest(options);
     49  test.setMediaConstraints([{video: true}], []);
     50  test.chain.append([
     51    function CHECK_PRECONDITIONS() {
     52      is(test.pcLocal._pc.getSenders().length, 1,
     53          "Should have 1 local sender");
     54      is(test.pcLocal.localMediaElements.length, 1,
     55          "Should have 1 local sending media element");
     56      is(test.pcRemote.remoteMediaElements.length, 1,
     57          "Should have 1 remote media element");
     58 
     59      sender = test.pcLocal._pc.getSenders()[0];
     60      localElem = test.pcLocal.localMediaElements[0];
     61      remoteElem = test.pcRemote.remoteMediaElements[0];
     62 
     63      remoteElem.addEventListener("resize", () =>
     64        info(`Video resized to ${remoteElem.videoWidth}x${remoteElem.videoHeight}`));
     65 
     66      originalWidth = localElem.videoWidth;
     67      originalHeight = localElem.videoHeight;
     68      info(`Original width is ${originalWidth}`);
     69    },
     70    function PC_LOCAL_SCALEDOWNBY_2() {
     71      return checkScaleDownBy(2);
     72    },
     73    function PC_LOCAL_SCALEDOWNBY_4() {
     74      return checkScaleDownBy(4);
     75    },
     76    function PC_LOCAL_SCALEDOWNBY_15() {
     77      return checkScaleDownBy(15);
     78    },
     79    function PC_LOCAL_SCALEDOWNBY_8() {
     80      return checkScaleDownBy(8);
     81    },
     82    function PC_LOCAL_SCALEDOWNBY_1() {
     83      return checkScaleDownBy(1);
     84    },
     85  ]);
     86  await test.run();
     87 });
     88 </script>
     89 </pre>
     90 </body>
     91 </html>