test_Threshold_mp4.html (2827B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>MSE: data gap detection</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script type="text/javascript" src="mediasource.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 </head> 9 <body> 10 <pre id="test"> 11 <script class="testbody" type="text/javascript"> 12 13 SimpleTest.waitForExplicitFinish(); 14 15 runWithMSE(async (ms, el) => { 16 const threshold = 0.5; // gap threshold in seconds. 17 const fuzz = 0.000001; // fuzz when comparing double. 18 19 await once(ms, "sourceopen"); 20 ok(true, "Receive a sourceopen event"); 21 const videosb = ms.addSourceBuffer("video/mp4"); 22 const vchunks = [{start: 0, end: 3.203333}, { start: 3.203333, end: 6.406666}]; 23 24 await fetchAndLoad(videosb, "bipbop/bipbop_video", ["init"], ".mp4"); 25 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 5), ".m4s"); 26 // We will insert a gap of threshold 27 videosb.timestampOffset = threshold; 28 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(5, 9), ".m4s"); 29 // HTMLMediaElement fires 'waiting' if somebody invokes |play()| before the MDSM 30 // has notified it of available data. Make sure that we get 'playing' before 31 // we starting waiting for 'waiting'. 32 info("Invoking play()"); 33 let p = once(el, "playing"); 34 el.play(); 35 await p; 36 await once(el, "waiting"); 37 // We're waiting for data after the start of the last frame. 38 // 0.033333 is the duration of the last frame. 39 ok((el.currentTime >= vchunks[1].end - 0.033333 + threshold - fuzz && 40 el.currentTime <= vchunks[1].end + threshold + fuzz), 41 `skipped the gap properly: ${el.currentTime} ${vchunks[1].end + threshold}`); 42 is(el.buffered.length, 2, "buffered range has right length"); 43 // Now we test that seeking will succeed despite the gap. 44 el.currentTime = el.buffered.end(0) + (threshold / 2); 45 await once(el, "seeked"); 46 // Now we test that we don't pass the gap. 47 // Clean up our sourcebuffer by removing all data. 48 videosb.timestampOffset = 0; 49 videosb.remove(0, Infinity); 50 el.currentTime = 0; 51 el.pause(); 52 await once(videosb, "updateend"); 53 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 5), ".m4s"); 54 // We will insert a gap of threshold + 1ms 55 videosb.timestampOffset = threshold + 1 / 1000; 56 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(5, 9), ".m4s"); 57 info("Invoking play()"); 58 p = once(el, "playing"); 59 el.play(); 60 await p; 61 await once(el, "waiting"); 62 // We're waiting for data after the start of the last frame. 63 // 0.033333 is the duration of the last frame. 64 ok((el.currentTime >= vchunks[0].end - 0.033333 - fuzz && 65 el.currentTime <= vchunks[0].end + fuzz), 66 `stopped at the gap properly: ${el.currentTime} ${vchunks[0].end}`); 67 SimpleTest.finish(); 68 }); 69 70 </script> 71 </pre> 72 </body> 73 </html>