tor-browser

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

RTCRtpScriptTransform-sender-worker-single-frame.https.html (4955B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta name="timeout" content="long">
      5 <title>RTCRtpScriptTransform Insertable Streams - Worker</title>
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src=/resources/testdriver.js></script>
      9 <script src=/resources/testdriver-vendor.js></script>
     10 <script src='../../mediacapture-streams/permission-helper.js'></script>
     11 <script src="../../webrtc/RTCPeerConnection-helper.js"></script>
     12 <script src="helper.js"></script>
     13 </head>
     14 <body>
     15 <script>
     16 
     17 promise_test(async t => {
     18  const caller = new RTCPeerConnection();
     19  t.add_cleanup(() => caller.close());
     20  const callee = new RTCPeerConnection();
     21  t.add_cleanup(() => callee.close());
     22 
     23  // Video is used in a later test, so we ask for both permissions
     24  await setMediaPermission();
     25  const stream = await navigator.mediaDevices.getUserMedia({audio:true});
     26  const track = stream.getTracks()[0];
     27  t.add_cleanup(() => track.stop());
     28 
     29  const audioSender = caller.addTrack(track);
     30 
     31  const senderWorker = new Worker('RTCRtpScriptTransform-sender-worker-single-frame.js');
     32  audioSender.transform = new RTCRtpScriptTransform(senderWorker);
     33  t.add_cleanup(() => senderWorker.terminate());
     34  let expectedFrameInfo = null;
     35  let numVerifiedFrames = 0;
     36  const onmessagePromise = new Promise(resolve => {
     37    senderWorker.onmessage = t.step_func(message => {
     38      if (!(message.data instanceof RTCEncodedAudioFrame)) {
     39        // This is the first message sent from the Worker to the test.
     40        // It contains an object (not an RTCEncodedAudioFrame) with the same
     41        // fields as the RTCEncodedAudioFrame to be sent in follow-up messages.
     42        // These serve as expected values to validate that the
     43        // RTCEncodedAudioFrame is sent correctly back to the test in the next
     44        // message.
     45        expectedFrameInfo = message.data;
     46      } else {
     47        // This is the frame sent by the Worker after reading it from the
     48        // readable stream. The Worker sends it twice after sending the
     49        // verification message.
     50        const frame = message.data;
     51        assert_equals(frame.type, expectedFrameInfo.type);
     52        assert_true(areArrayBuffersEqual(frame.data, expectedFrameInfo.data));
     53        assert_equals(frame.getMetadata().synchronizationSource, expectedFrameInfo.metadata.synchronizationSource);
     54        assert_equals(frame.getMetadata().rtpTimestamp, expectedFrameInfo.metadata.rtpTimestamp);
     55 
     56        if (++numVerifiedFrames == 2)
     57          resolve();
     58      }
     59    });
     60  });
     61 
     62  exchangeIceCandidates(caller, callee);
     63  await exchangeOfferAnswer(caller, callee);
     64 
     65  return onmessagePromise;
     66 }, 'RTCRtpSender initializes its transform attribute and the Worker sends an RTCEncodedAudioFrame back');
     67 
     68 promise_test(async t => {
     69  const caller = new RTCPeerConnection();
     70  t.add_cleanup(() => caller.close());
     71  const callee = new RTCPeerConnection();
     72  t.add_cleanup(() => callee.close());
     73 
     74  const stream = await navigator.mediaDevices.getUserMedia({video:true});
     75  const videoTrack = stream.getVideoTracks()[0];
     76  t.add_cleanup(() => videoTrack.stop());
     77 
     78  const videoSender = caller.addTrack(videoTrack)
     79 
     80  const senderWorker = new Worker('RTCRtpScriptTransform-sender-worker-single-frame.js');
     81  videoSender.transform = new RTCRtpScriptTransform(senderWorker);
     82  t.add_cleanup(() => senderWorker.terminate());
     83 
     84  let expectedFrameInfo = null;
     85  let numVerifiedFrames = 0;
     86  const onmessagePromise = new Promise(resolve => {
     87    senderWorker.onmessage = t.step_func(message => {
     88      if (!(message.data instanceof RTCEncodedVideoFrame)) {
     89        // This is the first message sent from the Worker to the test.
     90        // It contains an object (not an RTCEncodedVideoFrame) with the same
     91        // fields as the RTCEncodedVideoFrame to be sent in follow-up messages.
     92        // These serve as expected values to validate that the
     93        // RTCEncodedVideoFrame is sent correctly back to the test in the next
     94        // message.
     95        expectedFrameInfo = message.data;
     96      } else {
     97        // This is the frame sent by the Worker after reading it from the
     98        // readable stream. The Worker sends it twice after sending the
     99        // verification message.
    100        const frame = message.data;
    101        assert_equals(frame.type, expectedFrameInfo.type);
    102        assert_true(areArrayBuffersEqual(frame.data, expectedFrameInfo.data));
    103        assert_equals(frame.getMetadata().synchronizationSource, expectedFrameInfo.metadata.synchronizationSource);
    104        assert_equals(frame.getMetadata().rtpTimestamp, expectedFrameInfo.metadata.rtpTimestamp);
    105        if (++numVerifiedFrames == 2)
    106          resolve();
    107      }
    108    });
    109  });
    110 
    111  exchangeIceCandidates(caller, callee);
    112  await exchangeOfferAnswer(caller, callee);
    113 
    114  return onmessagePromise;
    115 }, 'RTCRtpSender initializes its transform attribute and the Worker sends an RTCEncodedVideoFrame back');
    116 
    117 </script>
    118 </body>
    119 </html>