Bug 1362165: P6. Only use sourcebuffer again once previous operation completed. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 03 May 2017 11:50:33 +0200
changeset 409398 55f7558b7c52281d3d8fc5e1cea26963b0cb2585
parent 409397 bb63055aef6c9842e8fa7370071eb22c9d2ecbc3
child 409399 846a4761d0cde831bffe4301827fd566e9bf5caf
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1362165
milestone55.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 1362165: P6. Only use sourcebuffer again once previous operation completed. r=gerald It was incorrect to assume that once "loadeddata" event fired the sourcebuffer would be usable again. Only the "updateend" event guarantees such condition. MozReview-Commit-ID: HcyaLWjjBlp
dom/media/mediasource/test/test_TruncatedDuration.html
dom/media/mediasource/test/test_TruncatedDuration_mp4.html
--- a/dom/media/mediasource/test/test_TruncatedDuration.html
+++ b/dom/media/mediasource/test/test_TruncatedDuration.html
@@ -45,34 +45,30 @@ function do_seeked(e) {
     // test playback position was updated (bug 1130839).
     is(v.currentTime, v.duration, "current time was updated");
     is(v._sb.buffered.length, 1, "One buffered range");
     // Truncated mediasource duration will cause the video element to seek.
     v.addEventListener("seeking", do_seeking);
   });
 }
 
-function do_loaded(e) {
-  var v = e.target;
-  v.removeEventListener("loadeddata", do_loaded);
-  v.currentTime = v.duration / 2;
-  is(v.currentTime, v.duration / 2, "current time was updated");
-  ok(v.seeking, "seeking is true");
-  v.addEventListener("seeked", do_seeked);
-}
-
 runWithMSE(function (ms, v) {
   ms.addEventListener("sourceopen", function () {
     var sb = ms.addSourceBuffer("video/webm");
     v._sb = sb;
     v._ms = ms;
 
     fetchWithXHR("seek.webm", function (arrayBuffer) {
       sb.appendBuffer(new Uint8Array(arrayBuffer));
-      v.addEventListener("loadeddata", do_loaded);
+      once(sb, "updateend", function() {
+        v.currentTime = v.duration / 2;
+        is(v.currentTime, v.duration / 2, "current time was updated");
+        ok(v.seeking, "seeking is true");
+        v.addEventListener("seeked", do_seeked);
+      });
     });
   });
 });
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/mediasource/test/test_TruncatedDuration_mp4.html
+++ b/dom/media/mediasource/test/test_TruncatedDuration_mp4.html
@@ -44,40 +44,36 @@ function do_seeked(e) {
     // test playback position was updated (bug 1130839).
     is(v.currentTime, v.duration, "current time was updated");
     is(v._sb.buffered.length, 1, "One buffered range");
     // Truncated mediasource duration will cause the video element to seek.
     v.addEventListener("seeking", do_seeking);
   });
 }
 
-function do_loaded(e) {
-  var v = e.target;
-  v.removeEventListener("loadeddata", do_loaded);
-  // mp4 metadata states 10s when we only have 1.6s worth of video.
-  v._sb.remove(v._sb.buffered.end(0), Infinity);
-  once(v._sb, "updateend", function() {
-    v._ms.duration = v._sb.buffered.end(0);
-    is(v.duration, v._ms.duration, "current time updated with mediasource duration");
-    v.currentTime = v.duration / 2;
-    is(v.currentTime, v.duration / 2, "current time was updated");
-    ok(v.seeking, "seeking is true");
-    v.addEventListener("seeked", do_seeked);
-  });
-}
-
 runWithMSE(function (ms, v) {
   ms.addEventListener("sourceopen", function () {
     var sb = ms.addSourceBuffer("video/mp4");
     v._sb = sb;
     v._ms = ms;
 
     fetchWithXHR("bipbop/bipbop2s.mp4", function (arrayBuffer) {
       sb.appendBuffer(new Uint8Array(arrayBuffer));
-      v.addEventListener("loadeddata", do_loaded);
+      once(sb, "updateend", function() {
+        // mp4 metadata states 10s when we only have 1.6s worth of video.
+        sb.remove(sb.buffered.end(0), Infinity);
+        once(sb, "updateend", function() {
+          ms.duration = sb.buffered.end(0);
+          is(v.duration, ms.duration, "current time updated with mediasource duration");
+          v.currentTime = v.duration / 2;
+          is(v.currentTime, v.duration / 2, "current time was updated");
+          ok(v.seeking, "seeking is true");
+          v.addEventListener("seeked", do_seeked);
+        });
+      });
     });
   });
 });
 
 </script>
 </pre>
 </body>
 </html>