summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasource/test/test_NoAudioLoopBackData_Muted.html
blob: 14cdf34bc6192590ba5acaf9b3fc4bc2a0d6e27c (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE HTML>
<html>
<head>
  <title>MSE: loop-back data not available yet (shorter MUTED audio)</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 check whether a looping video can loop back successfully
 * when it has a shorter MUTED audio track than its video track. When reaching
 * EOS for the shorter track, there is no loop-back data at the start position
 * (they are not appended yet) Even that, we should still be able to loop back
 * but the looping would become non-seamless in this situation.
 */
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 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(5, 8), ".m4s");
  audiosb.appendWindowEnd = videosb.buffered.end(0) - 0.2;
  await fetchAndLoad(audiosb, "bipbop/bipbop_audio", ["init"], ".mp4");
  await fetchAndLoad(audiosb, "bipbop/bipbop_audio", range(5, 8), ".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(`seek to the position where buffered data exists`);
  el.muted = true;
  el.loop = true;
  el.controls = true;
  el.currentTime = el.buffered.start(0);
  await el.play();

  info(`video should trigger seeking when reaching to the end`);
  let seekingCount = 0, seekedCount = 0;
  el.addEventListener("seeking", () => {
    is(++seekingCount, 1, "should only receive seeking once!");
  });
  el.addEventListener("seeked", () => {
    is(++seekedCount, 1, "should only receive seeked once!");
  });
  await once(el, "seeking");

  info(`trim old data before append new data`);
  let p = Promise.all([once(videosb, "updateend"), once(audiosb, "updateend")]);
  videosb.remove(videosb.buffered.start(0), videosb.buffered.end(0));
  audiosb.remove(audiosb.buffered.start(0), audiosb.buffered.end(0));
  await p;

  info(`append new data`);
  const seekedPromise = once(el, "seeked");
  p = Promise.all([once(videosb, "updateend"), once(audiosb, "updateend")]);
  await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 2), ".m4s");
  await fetchAndLoad(audiosb, "bipbop/bipbop_audio", range(1, 2), ".m4s");
  await p;
  info(`audio=[${audiosb.buffered.start(0)}-${audiosb.buffered.end(0)}], video=[${videosb.buffered.start(0)}-${videosb.buffered.end(0)}]`);

  info(`now we should be able to finish seeking to the start position`);
  await seekedPromise;

  SimpleTest.finish(SimpleTest);
});

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