tor-browser

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

test_peerConnection_basicVideoVerifyRtpHeaderExtensions.html (3140B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="pc.js"></script>
      5  <script type="application/javascript" src="parser_rtp.js"></script>
      6  <script type="application/javascript" src="sdpUtils.js"></script>
      7 </head>
      8 <body>
      9 <pre id="test">
     10 <script type="application/javascript">
     11  createHTML({
     12    bug: "1416932",
     13    title: "Basic video-only peer connection and verify rtp header extensions"
     14  });
     15 
     16  var test;
     17  runNetworkTest(function (options) {
     18    test = new PeerConnectionTest(options);
     19    test.setMediaConstraints([{video: true}], [{video: true}]);
     20 
     21    let getRtpPacketWithExtension = (pc, extension) => {
     22      // we only examine received packets
     23      let sending = false;
     24      pc.mozEnablePacketDump(0, "rtp", sending);
     25      return new Promise((res, rej) =>
     26        pc.mozSetPacketCallback((...args) => {
     27          const packet = ParseRtpPacket(args[3]);
     28          info(`midId = ${extension} packet = ${JSON.stringify(packet, null, 2)}`);
     29          if (packet.header.extensions.find(e => e.id == extension) !== undefined) {
     30            res(packet);
     31            pc.mozSetPacketCallback(() => {});
     32            pc.mozDisablePacketDump(0, "rtp", sending);
     33          }
     34        })
     35      );
     36    }
     37 
     38    let havePacketWithMid;
     39    let sdpExtmaps;
     40 
     41    // MID can stop being sent when acked causing failures if packets are checked later.
     42    // Starting packet sniffer before PC_LOCAL_SET_REMOTE_DESCRIPTION to be ready
     43    // to inspect packets ahead of any packets arriving.
     44    test.chain.insertBefore('PC_LOCAL_SET_REMOTE_DESCRIPTION', [
     45      function PC_REMOTE_FIND_RTP_PACKETS_WITH_MIDID() {
     46 
     47        sdpExtmaps = sdputils.findExtmapIdsUrnsDirections(test.originalAnswer.sdp);
     48        const [midId] = sdpExtmaps.find(([, urn]) => urn == "urn:ietf:params:rtp-hdrext:sdes:mid");
     49        const pc = SpecialPowers.wrap(test.pcRemote._pc);
     50        havePacketWithMid = getRtpPacketWithExtension(pc, midId);
     51      }
     52    ]);
     53 
     54    test.chain.insertBefore('PC_REMOTE_WAIT_FOR_MEDIA_FLOW', [
     55      async function PC_REMOTE_CHECK_RTP_HEADER_EXTS_AGAINST_SDP() {
     56 
     57        const sdpExtmapIds = sdpExtmaps.map(e => e[0]);
     58        const packet = await havePacketWithMid;
     59        const extIds = packet.header.extensions.map(e => `${e.id}`);
     60        // make sure we got the same number of rtp header extensions in
     61        // the received packet as were negotiated in the sdp.  Then
     62        // check to make sure each of the received extension ids were in
     63        // the sdp.
     64        is(sdpExtmapIds.length, extIds.length,
     65           `number of sdp ids match received ids ` +
     66           `${JSON.stringify(sdpExtmapIds)} == ${JSON.stringify(extIds)}\n` +
     67           `sdp = ${test.originalAnswer.sdp}\n` +
     68           `packet = ${JSON.stringify(packet, null, 2)}`);
     69        // note, we are comparing a number (from the parsed rtp packet)
     70        // and a string (from the answer sdp)
     71        ok(extIds.every(id => sdpExtmapIds.includes(id)) &&
     72           sdpExtmapIds.every(id => extIds.includes(id)),
     73          `extension id arrays equivalent`);
     74      }
     75    ]);
     76 
     77    return test.run();
     78  });
     79 </script>
     80 </pre>
     81 </body>
     82 </html>