summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasource/test/test_Eviction_mp4.html
blob: c702cc3bb262aca3cb933c8067a4f9fe5f2be45b (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
80
81
82
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
  <title>MSE: QuotaExceededError when source buffer is full</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();
// We fill up the source buffer with audio data until the buffer is full.
// We ensure that QuotaExceededError is thrown once the buffer is full.
// We then seek to half the content. By that time, another appendBuffer must succeed
// as the auto-eviction would succeed (removing all data prior currentTime)

// Fill up the SourceBuffer by appending data repeatedly via doAppendDataFunc until
// an exception is thrown.
function fillUpSourceBuffer(sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback) {
  // We are appending data repeatedly in sequence mode, there should be no gaps.
  ok(sourceBuffer.buffered.length <= 1, "there should be no gap in buffered ranges.");
  try {
    doAppendDataFunc();
  } catch(ex) {
    onCaughtExceptionCallback(ex);
    return;
  }
  once(sourceBuffer, 'updateend', () => {
    fillUpSourceBuffer(sourceBuffer, doAppendDataFunc, onCaughtExceptionCallback);
  });
}

runWithMSE(function(ms, el) {
  el.controls = true;
  once(ms, 'sourceopen').then(function() {
    ok(true, "Receive a sourceopen event");
    SpecialPowers.pushPrefEnv({
      "set": [
        ["media.mediasource.eviction_threshold.audio", 524288],
      ]
    }, function() {
      let audiosb = ms.addSourceBuffer("audio/mp4");
      audiosb.mode = "sequence";
      fetchAndLoad(audiosb, 'bipbop/bipbop_audio', ['init'], '.mp4')
      .then(function() {
        fetchWithXHR('bipbop/bipbop_audio1.m4s', function(audioBuffer) {
           fillUpSourceBuffer(audiosb,
             function() { // doAppendDataFunc
               audiosb.appendBuffer(audioBuffer);
             },
             function(ex) { // onCaughtExceptionCallback
               is(ex.name, 'QuotaExceededError', "QuotaExceededError thrown");
               is(audiosb.buffered.end(0), el.duration, "Duration is end of buffered range");
               let seekTime = audiosb.buffered.end(0) / 2;
               el.currentTime = seekTime;
               once(el, 'seeked', () => {
                 is(el.currentTime, seekTime, "correctly seeked to " + seekTime);
                 try {
                   audiosb.appendBuffer(audioBuffer);
                 } catch(ex) {
                   ok(false, "Shouldn't throw another time when data can be evicted");
                   el.mozDumpDebugInfo();
                   SimpleTest.finish();
                   return;
                 }
                 once(audiosb, 'update', () => {
                   ok(true, "appendBuffer succeeded");
                   SimpleTest.finish();
                 });
               });
            });
        });
      });
    });
  });
});

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