Bug 1382855: added mochitest to verify RTP framemarking draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Mon, 24 Jul 2017 21:51:33 -0700
changeset 615412 76387ac31c63937c5c423c53a0a163a5608d0ed7
parent 615411 fb67d624f9c174898e0dbf9fa17e317ee8c197fc
child 639167 518a659060af0489a46b7c36b13e5c9ec5cdc360
push id70348
push userdrno@ohlmeier.org
push dateTue, 25 Jul 2017 22:40:28 +0000
bugs1382855
milestone56.0a1
Bug 1382855: added mochitest to verify RTP framemarking MozReview-Commit-ID: KUa87t09B0G
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/sdpUtils.js
dom/media/tests/mochitest/test_peerConnection_frameMarkingOffer.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -185,16 +185,17 @@ skip-if = toolkit == 'android'
 [test_peerConnection_restartIceNoRtcpMux.html]
 skip-if = toolkit == 'android'
 [test_peerConnection_restartIceLocalRollback.html]
 skip-if = toolkit == 'android'
 [test_peerConnection_restartIceLocalAndRemoteRollback.html]
 skip-if = toolkit == 'android'
 [test_peerConnection_scaleResolution.html]
 skip-if = (android_version == '18') # android(Bug 1189784, timeouts on 4.3 emulator)
+[test_peerConnection_frameMarkingOffer.html]
 [test_peerConnection_simulcastOffer.html]
 skip-if = android_version # no simulcast support on android
 [test_peerConnection_simulcastAnswer.html]
 skip-if = android_version # no simulcast support on android
 #[test_peerConnection_relayOnly.html]
 [test_peerConnection_callbacks.html]
 skip-if = toolkit == 'android' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_replaceTrack.html]
--- a/dom/media/tests/mochitest/sdpUtils.js
+++ b/dom/media/tests/mochitest/sdpUtils.js
@@ -75,16 +75,23 @@ addTiasBps: function(sdp, bps) {
 },
 
 removeSimulcastProperties: function(sdp) {
   return sdp.replace(/a=simulcast:.*\r\n/g, "")
             .replace(/a=rid:.*\r\n/g, "")
             .replace(/a=extmap:[^\s]* urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id.*\r\n/g, "");
 },
 
+transferFrameMarkingExtmap: function(offer_sdp, answer_sdp) {
+  var extmap_id = offer_sdp.match("a=extmap:([0-9+])/sendonly urn:ietf:params:rtp-hdrext:framemarking");
+  ok(extmap_id != null, "Offer contains FrameMarking RTP header extension");
+  new_answer_sdp = answer_sdp + "a=extmap:" + extmap_id[1] + "/recvonly urn:ietf:params:rtp-hdrext:framemarking\r\n";
+  return new_answer_sdp;
+},
+
 transferSimulcastProperties: function(offer_sdp, answer_sdp) {
   if (!offer_sdp.includes("a=simulcast:")) {
     return answer_sdp;
   }
   ok(offer_sdp.includes("a=simulcast: send rid"), "Offer contains simulcast attribute");
   var o_simul = offer_sdp.match(/simulcast: send rid=(.*)([\n$])*/i);
   var new_answer_sdp = answer_sdp + "a=simulcast: recv rid=" + o_simul[1] + "\r\n";
   ok(offer_sdp.includes("a=rid:"), "Offer contains RID attribute");
copy from dom/media/tests/mochitest/test_peerConnection_simulcastOffer.html
copy to dom/media/tests/mochitest/test_peerConnection_frameMarkingOffer.html
--- a/dom/media/tests/mochitest/test_peerConnection_simulcastOffer.html
+++ b/dom/media/tests/mochitest/test_peerConnection_frameMarkingOffer.html
@@ -4,151 +4,39 @@
   <script type="application/javascript" src="pc.js"></script>
   <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
 </head>
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "1231507",
-    title: "Basic video-only peer connection with Simulcast offer",
+    title: "Basic video-only peer connection with FrameMarking offer",
     visible: true
   });
 
-  const pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
-
-  function addRIDExtension(pc, extensionId) {
-    const receivers = pc._pc.getReceivers();
-    is(receivers.length, 1, "We have exactly one RTP receiver");
-    const receiver = receivers[0];
-
-    SpecialPowers.wrap(pc._pc).mozAddRIDExtension(receiver, extensionId);
-  }
-
-  function selectRecvRID(pc, rid) {
-    const receivers = pc._pc.getReceivers();
-    is(receivers.length, 1, "We have exactly one RTP receiver");
-    const receiver = receivers[0];
-
-    SpecialPowers.wrap(pc._pc).mozAddRIDFilter(receiver, rid);
-  }
-
-  runNetworkTest(() =>
-    pushPrefs(['media.peerconnection.simulcast', true],
-              // 180Kbps was determined empirically, set well-higher than
-              // the 80Kbps+overhead needed for the two simulcast streams.
-              // 100Kbps was apparently too low.
-              ['media.peerconnection.video.min_bitrate_estimate', 180*1000]).then(() => {
-      let emitter, helper;
-
-      const test = new PeerConnectionTest({bundle: false});
-      test.setMediaConstraints([{video: true}], []);
-
-      test.chain.replace("PC_LOCAL_GUM", [
-        function PC_LOCAL_CANVAS_CAPTURESTREAM(test) {
-          emitter = new VideoFrameEmitter();
-          helper = new VideoStreamHelper();
-          test.pcLocal.attachLocalStream(emitter.stream());
-          emitter.start();
-        }
-      ]);
-
-      test.chain.insertBefore('PC_LOCAL_CREATE_OFFER', [
-        function PC_LOCAL_SET_RIDS(test) {
-          const senders = test.pcLocal._pc.getSenders();
-          is(senders.length, 1, "We have exactly one RTP sender");
-          const sender = senders[0];
-          ok(sender.track, "Sender has a track");
-
-          return sender.setParameters({
-            encodings: [{ rid: "foo", maxBitrate: 40000 },
-                        { rid: "bar", maxBitrate: 40000, scaleResolutionDownBy: 2 }]
-          });
-        }
-      ]);
-
-      test.chain.insertAfter('PC_LOCAL_GET_ANSWER', [
-        function PC_LOCAL_ADD_RIDS_TO_ANSWER(test) {
-          test._remote_answer.sdp = sdputils.transferSimulcastProperties(
-            test.originalOffer.sdp, test._remote_answer.sdp);
-          info("Answer with RIDs: " + JSON.stringify(test._remote_answer));
-          ok(test._remote_answer.sdp.match(/a=simulcast:/), "Modified answer has simulcast");
-          ok(test._remote_answer.sdp.match(/a=rid:foo/), "Modified answer has rid foo");
-          ok(test._remote_answer.sdp.match(/a=rid:bar/), "Modified answer has rid bar");
-          ok(test._remote_answer.sdp.match(/urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id/), "Modified answer has RID");
-        }
-      ]);
+  runNetworkTest(function (options) {
+    test = new PeerConnectionTest(options);
+    test.setMediaConstraints([{video: true}], []);
 
-      // do this after set local description so the MediaPipeline
-      // has been created.
-      test.chain.insertAfter('PC_REMOTE_SET_LOCAL_DESCRIPTION',[
-        function PC_REMOTE_SET_RTP_FIRST_RID(test) {
-          const extmap_id = test.originalOffer.sdp.match(
-              "a=extmap:([0-9+])/sendonly urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id");
-          ok(extmap_id, "Original offer has extmap id for simulcast: " + extmap_id[1]);
-          // Cause pcRemote to filter out everything but RID "foo", only
-          // allowing one of the simulcast streams through.
-          addRIDExtension(test.pcRemote, extmap_id[1]);
-          selectRecvRID(test.pcRemote, "foo");
-        }
-      ]);
+    test.chain.insertAfter('PC_LOCAL_GET_ANSWER', [
+      function PC_LOCAL_ADD_FRAMEMARKING_TO_ANSWER(test) {
+        test._remote_answer.sdp = sdputils.transferFrameMarkingExtmap(
+          test.originalOffer.sdp, test._remote_answer.sdp);
+        info("Answer with FrameMarking: " + JSON.stringify(test._remote_answer));
+        ok(test._remote_answer.sdp.match(/urn:ietf:params:rtp-hdrext:framemarking/), "Modified answer has RID");
+      }
+    ]);
 
-      test.chain.append([
-        async function PC_REMOTE_WAIT_FOR_FRAMES() {
-          const vremote = test.pcRemote.remoteMediaElements[0];
-          ok(vremote, "Should have remote video element for pcRemote");
-          emitter.start();
-          await helper.checkVideoPlaying(vremote, 10, 10, 16);
-          emitter.stop();
-        },
-        function PC_REMOTE_CHECK_SIZE_1() {
-          const vlocal = test.pcLocal.localMediaElements[0];
-          const vremote = test.pcRemote.remoteMediaElements[0];
-          ok(vlocal, "Should have local video element for pcLocal");
-          ok(vremote, "Should have remote video element for pcRemote");
-          ok(vlocal.videoWidth > 0, "source width is positive");
-          ok(vlocal.videoHeight > 0, "source height is positive");
-          is(vremote.videoWidth, vlocal.videoWidth, "sink is same width as source");
-          is(vremote.videoHeight, vlocal.videoHeight,  "sink is same height as source");
-        },
-        function PC_REMOTE_SET_RTP_SECOND_RID(test) {
-          // Now, cause pcRemote to filter out everything but RID "bar", only
-          // allowing the other simulcast stream through.
-          selectRecvRID(test.pcRemote, "bar");
-        },
-        function PC_REMOTE_WAIT_FOR_SECOND_MEDIA_FLOW(test) {
-          return test.pcRemote.waitForMediaFlow();
-        },
-        async function PC_REMOTE_WAIT_FOR_FRAMES_2() {
-          const vremote = test.pcRemote.remoteMediaElements[0];
-          ok(vremote, "Should have remote video element for pcRemote");
-          emitter.start();
-          await helper.checkVideoPlaying(vremote, 10, 10, 16);
-          emitter.stop();
-        },
-        // For some reason, even though we're getting a 25x25 stream, sometimes
-        // the resolution isn't updated on the video element on the first frame.
-        async function PC_REMOTE_WAIT_FOR_FRAMES_3() {
-          const vremote = test.pcRemote.remoteMediaElements[0];
-          ok(vremote, "Should have remote video element for pcRemote");
-          emitter.start();
-          await helper.checkVideoPlaying(vremote, 10, 10, 16);
-          emitter.stop();
-        },
-        function PC_REMOTE_CHECK_SIZE_2() {
-          const vlocal = test.pcLocal.localMediaElements[0];
-          const vremote = test.pcRemote.remoteMediaElements[0];
-          ok(vlocal, "Should have local video element for pcLocal");
-          ok(vremote, "Should have remote video element for pcRemote");
-          ok(vlocal.videoWidth > 0, "source width is positive");
-          ok(vlocal.videoHeight > 0, "source height is positive");
-          is(vremote.videoWidth, vlocal.videoWidth / 2, "sink is 1/2 width of source");
-          is(vremote.videoHeight, vlocal.videoHeight / 2, "sink is 1/2 height of source");
-        },
-      ]);
+    test.chain.insertAfter('PC_REMOTE_SET_LOCAL_DESCRIPTION',[
+      function PC_REMOTE_VERIFY_FRAMEMARKING(test) {
+        const extmap_id = test.originalOffer.sdp.match(
+            "a=extmap:([0-9+])/sendonly urn:ietf:params:rtp-hdrext:framemarking");
+        ok(extmap_id, "Original offer has extmap id for framemarking: " + extmap_id[1]);
+      }
+    ]);
 
-      return test.run();
-  })
-  .catch(e => ok(false, "unexpected failure: " + e)));
+    test.run();
+  });
 </script>
 </pre>
 </body>
 </html>