Bug 1230184 - add media.peerconnection.simulcast pref. r=bwc
authorJan-Ivar Bruaroey <jib@mozilla.com>
Thu, 31 Dec 2015 10:32:26 -0600
changeset 278144 9d2a98ad114f849b51723c9f17faf5de5be53e47
parent 278143 6418df768fe4dd193a5c20bc672f45dbc4b91a52
child 278145 e23c280f0d3a31cf8b8cb0e335d1b97f39a96603
push id69689
push userbcampen@mozilla.com
push dateThu, 31 Dec 2015 23:23:36 +0000
treeherdermozilla-inbound@e23c280f0d3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwc
bugs1230184
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1230184 - add media.peerconnection.simulcast pref. r=bwc
dom/media/PeerConnection.js
dom/media/tests/mochitest/test_peerConnection_setParameters.html
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -1034,17 +1034,19 @@ RTCPeerConnection.prototype = {
       this._onReplaceTrackWithTrack = withTrack;
       this._onReplaceTrackSuccess = resolve;
       this._onReplaceTrackFailure = reject;
       this._impl.replaceTrack(sender.track, withTrack);
     });
   },
 
   _setParameters: function(sender, parameters) {
-
+    if (!Services.prefs.getBoolPref("media.peerconnection.simulcast")) {
+      return;
+    }
     // validate parameters input
     var encodings = parameters.encodings || [];
 
     encodings.reduce((uniqueRids, encoding) => {
       if (!encoding.rid && encodings.length > 1) {
         throw new this._win.DOMException("Missing rid", "TypeError");
       }
       if (uniqueRids[encoding.rid]) {
@@ -1053,16 +1055,19 @@ RTCPeerConnection.prototype = {
       uniqueRids[encoding.rid] = true;
       return uniqueRids;
     }, {});
 
     this._impl.setParameters(sender.track, parameters);
   },
 
   _getParameters: function(sender) {
+    if (!Services.prefs.getBoolPref("media.peerconnection.simulcast")) {
+      return;
+    }
     return this._impl.getParameters(sender.track);
   },
 
   close: function() {
     if (this._closed) {
       return;
     }
     this.changeIceConnectionState("closed");
--- a/dom/media/tests/mochitest/test_peerConnection_setParameters.html
+++ b/dom/media/tests/mochitest/test_peerConnection_setParameters.html
@@ -1,83 +1,89 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <script type="application/javascript" src="pc.js"></script>
 </head>
 <body>
 <pre id="test">
 <script type="application/javascript;version=1.8">
-  createHTML({
-    bug: "1230184",
-    title: "Set parameters on sender",
-    visible: true
-  });
-
-  function parameterstest(wrapper) {
-    var pc = wrapper._pc;
-    ok(pc.getSenders().length > 0, "have senders");
-    var sender = pc.getSenders()[0];
+createHTML({
+  bug: "1230184",
+  title: "Set parameters on sender",
+  visible: true
+});
 
-    var testParameters = (params, errorName, errorMsg) => {
-      var compareParameters = (a, b) => {
-        var compareEncoding = (a, b) => {
-          is(a.rid, b.rid || "", "same rid");
-          is(a.maxBitrate, b.maxBitrate, "same maxBitrate");
-        };
-        is(a.encodings.length, (b.encodings || []).length, "same encodings");
-        a.encodings.forEach((en, i) => compareEncoding(en, b.encodings[i]));
+function parameterstest(wrapper) {
+  var pc = wrapper._pc;
+  ok(pc.getSenders().length > 0, "have senders");
+  var sender = pc.getSenders()[0];
+
+  var testParameters = (params, errorName, errorMsg) => {
+    var compareParameters = (a, b) => {
+      var compareEncoding = (a, b) => {
+        is(a.rid, b.rid || "", "same rid");
+        is(a.maxBitrate, b.maxBitrate, "same maxBitrate");
       };
-      try {
-        sender.setParameters(params);
-        compareParameters(sender.getParameters(), params);
-        is(null, errorName || null, "is success expected");
-      } catch (e) {
-        is(e.name, errorName, "correct error name");
-        is(e.message, errorMsg, "correct error message");
-      }
+      is(a.encodings.length, (b.encodings || []).length, "same encodings");
+      a.encodings.forEach((en, i) => compareEncoding(en, b.encodings[i]));
     };
+    try {
+      sender.setParameters(params);
+      compareParameters(sender.getParameters(), params);
+      is(null, errorName || null, "is success expected");
+    } catch (e) {
+      is(e.name, errorName, "correct error name");
+      is(e.message, errorMsg, "correct error message");
+    }
+  };
 
-    testParameters({
-      encodings: [
-        { rid: "foo", maxBitrate: 40000 },
-        { rid: "bar", maxBitrate: 10000 },
-      ]
-    });
-    testParameters({
-      encodings: [
-        { maxBitrate: 10000 },
-      ]
-    });
-    testParameters({
-      encodings: [
-        { maxBitrate: 40000 },
-        { rid: "bar", maxBitrate: 10000 },
-      ]
-    }, "TypeError", "Missing rid");
-    testParameters({
-      encodings: [
-        { rid: "foo", maxBitrate: 40000 },
-        { rid: "bar", maxBitrate: 10000 },
-        { rid: "bar", maxBitrate: 20000 },
-      ]
-    }, "TypeError", "Duplicate rid");
-    testParameters({});
-  }
+  testParameters({
+    encodings: [
+      { rid: "foo", maxBitrate: 40000 },
+      { rid: "bar", maxBitrate: 10000 },
+    ]
+  });
+  testParameters({
+    encodings: [
+      { maxBitrate: 10000 },
+    ]
+  });
+  testParameters({
+    encodings: [
+      { maxBitrate: 40000 },
+      { rid: "bar", maxBitrate: 10000 },
+    ]
+  }, "TypeError", "Missing rid");
+  testParameters({
+    encodings: [
+      { rid: "foo", maxBitrate: 40000 },
+      { rid: "bar", maxBitrate: 10000 },
+      { rid: "bar", maxBitrate: 20000 },
+    ]
+  }, "TypeError", "Duplicate rid");
+  testParameters({});
+}
 
-  runNetworkTest(function () {
+var pushPrefs = (...p) => new Promise(r => SpecialPowers.pushPrefEnv({set: p}, r));
+
+runNetworkTest(() =>
+  pushPrefs(['media.peerconnection.simulcast', true]).then(() => {
+
     test = new PeerConnectionTest();
     test.setMediaConstraints([{video: true}], [{video: true}]);
     test.chain.removeAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW");
 
     // Test sender parameters.
     test.chain.append([
       function PC_LOCAL_SET_PARAMETERS(test) {
         return parameterstest(test.pcLocal);
       }
     ]);
 
-    test.run();
-  });
+    return test.run();
+  })
+  .catch(e => ok(false, "unexpected failure: " + e)));
+
 </script>
 </pre>
 </body>
 </html>