tor-browser

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

test_peerConnection_setParameters_scaleResolutionDownBy.html (3055B)


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