Bug 1059265 - Reduce number of concurrent playback and active cubeb streams to avoid hitting bug 847903. r=kinetik, a=lmandel
authorJW Wang <jwwang@mozilla.com>
Tue, 16 Sep 2014 19:35:00 +1200
changeset 225007 dd0958929b1716e3519977b496a9ee2978a410d7
parent 225006 4ae055d7bc847dd8554b43aa678e3d77a3f3be8c
child 225008 fa6dc8cffc42096f171f03eaa2214df7fcddfb99
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik, lmandel
bugs1059265, 847903
milestone34.0a2
Bug 1059265 - Reduce number of concurrent playback and active cubeb streams to avoid hitting bug 847903. r=kinetik, a=lmandel
content/media/test/reactivate_helper.html
content/media/test/test_reactivate.html
--- a/content/media/test/reactivate_helper.html
+++ b/content/media/test/reactivate_helper.html
@@ -1,38 +1,54 @@
 <!DOCTYPE HTML>
 <html>
 <body>
 <script>
 var loadsWaiting = 0;
 var elements = [];
 
-function loadedData(event) {
-  parent.ok(elements.indexOf(event.target) == -1, "Element already loaded: " + event.target.currentSrc);
-
-  elements.push(event.target);
-
+function checkAllLoaded() {
   --loadsWaiting;
-  parent.ok(true, "Loaded " + event.target.currentSrc);
   if (loadsWaiting == 0) {
     parent.loadedAll(elements);
   }
 }
 
+function loadedData(event) {
+  var e = event.target;
+  parent.ok(elements.indexOf(e) == -1, "Element already loaded: " + e._name);
+  parent.info("Loaded " + e._name);
+  elements.push(e);
+  // Reset "onerror" handler to avoid triggering another error in removeNodeAndSource().
+  e.onerror = null;
+  checkAllLoaded();
+
+}
+
+function error(event) {
+  var e = event.target;
+  parent.info("Error " + e._name);
+  // Don't wait for the element encounting errors.
+  checkAllLoaded();
+}
+
 for (var i = 0; i < parent.gSmallTests.length; ++i) {
   var test = parent.gSmallTests[i];
   var elemType = /^audio/.test(test.type) ? "audio" : "video";
   // Associate these elements with the subframe's document
   var e = document.createElement(elemType);
-  e.preload = "auto";
+  e.preload = "metadata";
   if (e.canPlayType(test.type)) {
     e.src = test.name;
-    e.addEventListener("loadeddata", loadedData, false);
+    e._name = test.name;
+    e.onloadeddata = loadedData;
+    e.onerror = error;
     e.load();
     ++loadsWaiting;
+    parent.info("Loading " + e._name);
   }
 }
 
 if (loadsWaiting == 0) {
   parent.todo(false, "Can't play anything");
 } else {
   parent.SimpleTest.waitForExplicitFinish();
 }
--- a/content/media/test/test_reactivate.html
+++ b/content/media/test/test_reactivate.html
@@ -8,49 +8,44 @@
 </head>
 <body>
 
 <iframe id="frame" src="reactivate_helper.html"></iframe>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
-var testsWaiting;
 var elements;
 
-function didPlay(event) {
-  ok(true, "Element ended: " + event.target.currentSrc);
-
-  removeNodeAndSource(event.target);
-
-  --testsWaiting;
-  if (testsWaiting == 0) {
+function playElement(e) {
+  // All elements played out, finish the test case.
+  if (!e) {
     SimpleTest.finish();
-  }
-}
-
-function reviveElements() {
-  // reactivate the elements by moving them to our document
-  for (var i = 0; i < elements.length; ++i) {
-    document.body.appendChild(elements[i]);
-    elements[i].addEventListener("ended", didPlay, false);
+    return;
   }
 
-  testsWaiting = elements.length;
+  e.play();
+  info("Element play: " + e._name);
+  var reviveElement = function() {
+    document.body.appendChild(e);
+    e.onended = function() {
+      info("Element ended: " + e._name);
+      removeNodeAndSource(e);
+      // Play next element.
+      playElement(elements.pop());
+    }
+  }
+  setTimeout(reviveElement, 2000);
 }
 
 function loadedAll(elementList) {
   elements = elementList;
 
   // Blow away the subframe
   document.body.removeChild(document.getElementById("frame"));
 
-  // Start the elements playing.
-  for (var i = 0; i < elements.length; ++i) {
-    elements[i].play();
-  }
-
-  setTimeout(reviveElements, 2000);
+  // Play elements one by one to avoid hitting bug 847903 on MacOSX.
+  playElement(elements.pop());
 }
 </script>
 </pre>
 </body>
 </html>