Bug 972826 - Reset 'src' to force releasing h264 decoder so that the cloned <video> can play gizmo.mp4. r=cajbir, a=test-only
authorJW Wang <jwwang@mozilla.com>
Thu, 17 Jul 2014 20:28:00 +0200 (2014-07-17)
changeset 203165 8f5f26e50c72eb17f4463db6a1439a2f40a30995
parent 203150 1e48c30502fdb9434b808bd536df829ec21928a6
child 203166 d76eb20e74b4e29b46b07792257e48bebf4bf528
push id14
push userryanvm@gmail.com
push dateWed, 23 Jul 2014 01:33:46 +0000 (2014-07-23)
treeherdermozilla-b2g32_v2_0@57c44a3f83f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir, test-only
bugs972826
milestone32.0
Bug 972826 - Reset 'src' to force releasing h264 decoder so that the cloned <video> can play gizmo.mp4. r=cajbir, a=test-only
content/media/test/test_load_same_resource.html
--- a/content/media/test/test_load_same_resource.html
+++ b/content/media/test/test_load_same_resource.html
@@ -18,32 +18,43 @@ function cloneLoaded(event) {
   var e = event.target;
 
   if (e._expectedDuration) {
     ok(Math.abs(e.duration - e._expectedDuration) < 0.1,
        "Clone " + e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration);
   }
 
   e.removeEventListener("loadeddata", cloneLoaded, false);
-
+  removeNodeAndSource(e);
   manager.finished(e.token);
 }
 
 function tryClone(event) {
   var e = event.target;
   var clone = e.cloneNode(false);
   clone.token = e.token;
 
   if (e._expectedDuration) {
     ok(Math.abs(e.duration - e._expectedDuration) < 0.1,
        e.currentSrc + " duration: " + e.duration + " expected: " + e._expectedDuration);
     clone._expectedDuration = e._expectedDuration;
   }
 
   clone.addEventListener("loadeddata", cloneLoaded, false);
+  clone.onloadstart = function(evt) {
+    info("cloned " + evt.target.token + " start loading.");
+    evt.target.onloadstart = null;
+    // Since there is only one H264 decoder instance, we have to delete the
+    // decoder of the original element for the cloned element to load. However,
+    // we can't delete the decoder too early otherwise cloning decoder will
+    // fail to kick in. We wait for 'loadstart' event of the cloned element to
+    // know when the decoder is already cloned and we can delete the decoder of
+    // the original element.
+    removeNodeAndSource(e);
+  }
 
   e.removeEventListener("loadeddata", tryClone, false);
 }
 
 // This test checks that loading the same URI twice in different elements at the same time
 // uses the same resource without doing another network fetch. One of the gCloneTests
 // uses dynamic_resource.sjs to return one resource on the first fetch and a different resource
 // on the second fetch. These resources have different lengths, so if the cloned element