tor-browser

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

setParameters-active.https.html (4256B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>RTCPeerConnection Simulcast Tests - setParameters/active</title>
      4 <meta name="timeout" content="long">
      5 <script src="../third_party/sdp/sdp.js"></script>
      6 <script src="simulcast.js"></script>
      7 <script src="../RTCPeerConnection-helper.js"></script>
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src="/resources/testdriver.js"></script>
     11 <script src="/resources/testdriver-vendor.js"></script>
     12 <script src="../../mediacapture-streams/permission-helper.js"></script>
     13 <script>
     14 async function queryReceiverStats(pc) {
     15  const inboundStats =
     16    await Promise.all(pc.getReceivers().map(async receiver => {
     17    const receiverStats = await receiver.getStats();
     18    let inboundStat;
     19    receiverStats.forEach(stat => {
     20      if (stat.type === 'inbound-rtp') {
     21        inboundStat = stat;
     22      }
     23    });
     24    return inboundStat;
     25  }));
     26  return inboundStats.map(s => s.framesDecoded);
     27 }
     28 
     29 promise_test(async t => {
     30  const rids = [0, 1];
     31  const pc1 = new RTCPeerConnection();
     32  t.add_cleanup(() => pc1.close());
     33  const pc2 = new RTCPeerConnection();
     34  t.add_cleanup(() => pc2.close());
     35 
     36  await negotiateSimulcastAndWaitForVideo(t, await getCameraStream(t), rids, pc1, pc2);
     37 
     38  // Deactivate first sender.
     39  const parameters = pc1.getSenders()[0].getParameters();
     40  parameters.encodings[0].active = false;
     41  await pc1.getSenders()[0].setParameters(parameters);
     42 
     43  // Assert (almost) no new frames are received on the first encoding.
     44  // Without any action we would expect to have received around 30fps.
     45  await new Promise(resolve => t.step_timeout(resolve, 200)); // Wait a bit.
     46  const initialStats = await queryReceiverStats(pc2);
     47  await new Promise(resolve => t.step_timeout(resolve, 1000)); // Wait more.
     48  const subsequentStats = await queryReceiverStats(pc2);
     49 
     50  assert_equals(subsequentStats[0], initialStats[0]);
     51  assert_greater_than(subsequentStats[1], initialStats[1]);
     52 }, 'Simulcast setParameters active=false on first encoding stops sending frames for that encoding');
     53 
     54 promise_test(async t => {
     55  const rids = [0, 1];
     56  const pc1 = new RTCPeerConnection();
     57  t.add_cleanup(() => pc1.close());
     58  const pc2 = new RTCPeerConnection();
     59  t.add_cleanup(() => pc2.close());
     60 
     61  await negotiateSimulcastAndWaitForVideo(t, await getCameraStream(t), rids, pc1, pc2);
     62 
     63  // Deactivate second sender.
     64  const parameters = pc1.getSenders()[0].getParameters();
     65  parameters.encodings[1].active = false;
     66  await pc1.getSenders()[0].setParameters(parameters);
     67 
     68  // Assert (almost) no new frames are received on the second encoding.
     69  // Without any action we would expect to have received around 30fps.
     70  await new Promise(resolve => t.step_timeout(resolve, 200)); // Wait a bit.
     71  const initialStats = await queryReceiverStats(pc2);
     72  await new Promise(resolve => t.step_timeout(resolve, 1000)); // Wait more.
     73  const subsequentStats = await queryReceiverStats(pc2);
     74 
     75  assert_equals(subsequentStats[1], initialStats[1]);
     76  assert_greater_than(subsequentStats[0], initialStats[0]);
     77 }, 'Simulcast setParameters active=false on second encoding stops sending frames for that encoding');
     78 
     79 promise_test(async t => {
     80  const rids = [0, 1];
     81  const pc1 = new RTCPeerConnection();
     82  t.add_cleanup(() => pc1.close());
     83  const pc2 = new RTCPeerConnection();
     84  t.add_cleanup(() => pc2.close());
     85 
     86  await negotiateSimulcastAndWaitForVideo(t, await getCameraStream(t), rids, pc1, pc2);
     87 
     88  // Deactivate all senders.
     89  const parameters = pc1.getSenders()[0].getParameters();
     90  parameters.encodings.forEach(e => {
     91    e.active = false;
     92  });
     93  await pc1.getSenders()[0].setParameters(parameters);
     94 
     95  // Assert (almost) no new frames are received.
     96  // Without any action we would expect to have received around 30fps.
     97  await new Promise(resolve => t.step_timeout(resolve, 200)); // Wait a bit.
     98  const initialStats = await queryReceiverStats(pc2);
     99  await new Promise(resolve => t.step_timeout(resolve, 1000)); // Wait more.
    100  const subsequentStats = await queryReceiverStats(pc2);
    101 
    102  subsequentStats.forEach((framesDecoded, idx) => {
    103    assert_equals(framesDecoded, initialStats[idx]);
    104  });
    105 }, 'Simulcast setParameters active=false stops sending frames');
    106 </script>