summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasource/test/test_Seamless_looping_shorter_audio_than_video_MSE.html
blob: b0bf7b410552e4beda7bb3a0cb5182ff5e425e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE HTML>
<html>
<head>
  <title>MSE: A way shorter audio track for seamless looping</title>
  <script 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>
<script class="testbody" type="text/javascript">

/**
 * This test is used to ensure the media can loop at least twice when its audio
 * is significantly shorter than its video. We use the different strategy to
 * fill the silence between tracks for the first looping and the other loopings
 * happening afterward. The purpose of test is to test the latter one, which
 * should create a series small chunks of audio data to fill out the gap,
 * instead of one big audio data which might not be processed by AudioSink due
 * to its large size.
 */
SimpleTest.waitForExplicitFinish();

runWithMSE(async (ms, el) => {
  await once(ms, "sourceopen");
  ok(true, "Receive a sourceopen event");
  const videosb = ms.addSourceBuffer("video/mp4");
  const audiosb = ms.addSourceBuffer("audio/mp4");

  // Here we create a way shorter audio than video.
  info(`create different length source buffers`);
  await fetchAndLoad(videosb, "bipbop/bipbop_video", ["init"], ".mp4");
  await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 3), ".m4s");
  audiosb.appendWindowEnd = videosb.buffered.end(0) - 1;
  await fetchAndLoad(audiosb, "bipbop/bipbop_audio", ["init"], ".mp4");
  await fetchAndLoad(audiosb, "bipbop/bipbop_audio", range(1, 3), ".m4s");
  ms.endOfStream();
  await Promise.all([once(el, "durationchange"), once(ms, "sourceended")]);
  info(`audio=[${audiosb.buffered.start(0)}-${audiosb.buffered.end(0)}], video=[${videosb.buffered.start(0)}-${videosb.buffered.end(0)}]`);
  ok(true, `endOfStream completed, buffer=[${el.buffered.start(0)}, ${el.buffered.end(0)}]`);
  ok(videosb.buffered.end(0) > audiosb.buffered.end(0), `video should be longer than audio`);

  info(`start playing`);
  el.loop = true;
  el.controls = true;
  await el.play();

  let seekCounter = 0;
  el.addEventListener("seeked", _ => {
    ok(true, `seeked ${++seekCounter} times`);
    if (seekCounter == 2) {
      ok(true, "seeked at least two time!");
      SimpleTest.finish(SimpleTest);
    }
  });
});

</script>
</body>
</html>