Bug 1120030 - Test for timestampOffset. r=jya
authorBobby Holley <bobbyholley@gmail.com>
Fri, 06 Feb 2015 11:00:07 -0800
changeset 241868 7b0674e3a899966d7b1a98caf1dbda17f7624c51
parent 241867 9a9b1ee1a69e2e181bcae69fa475ae08aa34afaa
child 241869 eec32dc1a5394a2f3e07e1f66ea7480b9098be90
push id625
push userdburns@mozilla.com
push dateTue, 10 Feb 2015 14:14:40 +0000
reviewersjya
bugs1120030
milestone38.0a1
Bug 1120030 - Test for timestampOffset. r=jya
dom/media/mediasource/test/mochitest.ini
dom/media/mediasource/test/test_TimestampOffset_mp4.html
--- a/dom/media/mediasource/test/mochitest.ini
+++ b/dom/media/mediasource/test/mochitest.ini
@@ -34,10 +34,12 @@ skip-if = (toolkit == 'android' || build
 [test_SeekableAfterEndOfStreamSplit.html]
 [test_SeekableBeforeEndOfStream.html]
 [test_SeekableBeforeEndOfStreamSplit.html]
 [test_SeekTwice_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (os != "win" && os != "mac")) # Only supported on osx and vista+
 [test_SetModeThrows.html]
 [test_SplitAppendDelay.html]
 [test_SplitAppend.html]
+[test_TimestampOffset_mp4.html]
+skip-if = ((os == "win" && os_version == "5.1") || (os != "win" && os != "mac")) # Only supported on osx and vista+
 [test_WaitingOnMissingData.html]
  skip-if = android_version == '10' # bug 1115148 - frequent failures on Android 2.3
new file mode 100644
--- /dev/null
+++ b/dom/media/mediasource/test/test_TimestampOffset_mp4.html
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>MSE: basic functionality</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="mediasource.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+function range(start, end) {
+  var rv = [];
+  for (var i = start; i < end; ++i) {
+    rv.push(i);
+  }
+  return rv;
+}
+
+var eps = 0.01;
+runWithMSE(function(ms, el) {
+
+  once(ms, 'sourceopen').then(function() {
+    ok(true, "Receive a sourceopen event");
+    var audiosb = ms.addSourceBuffer("audio/mp4");
+    var videosb = ms.addSourceBuffer("video/mp4");
+    // We divide the video into 3 chunks:
+    // chunk 0: segments 1-4
+    // chunk 1: segments 5-8
+    // chunk 2: segments 9-13
+    // We then fill the timeline so that it seamlessly plays the chunks in order 0, 2, 1.
+    var vchunks = [ {start: 0, end: 3.2033}, { start: 3.2033, end: 6.4066}, { start: 6.4066, end: 10.01} ];
+    var firstvoffset = vchunks[2].end - vchunks[2].start; // Duration of chunk 2
+    var secondvoffset = -(vchunks[1].end - vchunks[1].start); // -(Duration of chunk 1)
+
+    fetchAndLoad(videosb, 'bipbop/bipbop_video', ['init'], '.mp4')
+    .then(fetchAndLoad.bind(null, videosb, 'bipbop/bipbop_video', range(1, 5), '.m4s'))
+    .then(function() {
+      is(videosb.buffered.length, 1, "No discontinuity");
+      isfuzzy(videosb.buffered.start(0), vchunks[0].start, eps, "Chunk start");
+      isfuzzy(videosb.buffered.end(0), vchunks[0].end, eps, "Chunk end");
+      videosb.timestampOffset = firstvoffset;
+      return fetchAndLoad(videosb, 'bipbop/bipbop_video', range(5, 9), '.m4s');
+    })
+    .then(function(data) {
+      is(videosb.buffered.length, 2, "One discontinuity");
+      isfuzzy(videosb.buffered.start(0), vchunks[0].start, eps, "First Chunk start");
+      isfuzzy(videosb.buffered.end(0), vchunks[0].end, eps, "First chunk end");
+      isfuzzy(videosb.buffered.start(1),  vchunks[1].start + firstvoffset, eps, "Second chunk start");
+      isfuzzy(videosb.buffered.end(1), vchunks[1].end + firstvoffset, eps, "Second chunk end");
+      videosb.timestampOffset = secondvoffset;
+      return fetchAndLoad(videosb, 'bipbop/bipbop_video', range(9, 14), '.m4s');
+    })
+    .then(function() {
+      is(videosb.buffered.length, 1, "No discontinuity (end)");
+      isfuzzy(videosb.buffered.start(0), vchunks[0].start, eps, "Chunk start");
+      isfuzzy(videosb.buffered.end(0), vchunks[2].end, eps, "Chunk end");
+      audiosb.timestampOffset = 3;
+    }).then(fetchAndLoad.bind(null, audiosb, 'bipbop/bipbop_audio', ['init'], '.mp4'))
+    .then(fetchAndLoad.bind(null, audiosb, 'bipbop/bipbop_audio', range(1, 12), '.m4s'))
+    .then(function() {
+      is(audiosb.buffered.length, 1, "No audio discontinuity");
+      isfuzzy(audiosb.buffered.start(0), 3, eps, "Audio starts at 3");
+
+      // Trim the rest of the audio.
+      ms.duration = videosb.buffered.end(0);
+      return Promise.all([audiosb.updating ? once(audiosb, 'updateend') : Promise.resolve(),
+                          videosb.updating ? once(videosb, 'updateend') : Promise.resolve()]);
+    }).then(function() {
+      ms.endOfStream();
+      once(el, 'ended').then(SimpleTest.finish.bind(SimpleTest));
+      el.play();
+    });
+  });
+});
+
+</script>
+</pre>
+</body>
+</html>