test_NoVideoLoopBackData.html (3490B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>MSE: loop-back data not available yet (shorter video)</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 <script class="testbody" type="text/javascript"> 11 12 /** 13 * This test is used to check whether a looping video can loop back successfully 14 * when it has a shorter video track than its audio track. When reaching EOS for 15 * the shorter track, there is no loop-back data at the start position (they are 16 * not appended yet) Even that, we should still be able to loop back but the 17 * looping would become non-seamless in this situation. 18 */ 19 SimpleTest.waitForExplicitFinish(); 20 21 runWithMSE(async (ms, el) => { 22 await once(ms, "sourceopen"); 23 ok(true, "Receive a sourceopen event"); 24 const videosb = ms.addSourceBuffer("video/mp4"); 25 const audiosb = ms.addSourceBuffer("audio/mp4"); 26 27 // Here we create a way shorter video than audio because audio decoding is 28 // very fast. If two track only have small diffence in length, audio track 29 // would still reach to the end first. But in this test, we want to test 30 // reaching video EOS first. 31 info(`create different length source buffers`); 32 await fetchAndLoad(audiosb, "bipbop/bipbop_audio", ["init"], ".mp4"); 33 await fetchAndLoad(audiosb, "bipbop/bipbop_audio", range(5, 8), ".m4s"); 34 videosb.appendWindowEnd = audiosb.buffered.end(0) - 2.5; 35 await fetchAndLoad(videosb, "bipbop/bipbop_video", ["init"], ".mp4"); 36 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(5, 8), ".m4s"); 37 ms.endOfStream(); 38 await Promise.all([once(el, "durationchange"), once(ms, "sourceended")]); 39 info(`audio=[${audiosb.buffered.start(0)}-${audiosb.buffered.end(0)}], video=[${videosb.buffered.start(0)}-${videosb.buffered.end(0)}]`); 40 ok(true, `endOfStream completed, buffer=[${el.buffered.start(0)}, ${el.buffered.end(0)}]`); 41 ok(audiosb.buffered.end(0) > videosb.buffered.end(0), `audio should be longer than video`); 42 43 info(`seek to the position where buffered data exists`); 44 el.loop = true; 45 el.controls = true; 46 el.currentTime = el.buffered.start(0); 47 await el.play(); 48 49 info(`video should trigger seeking when reaching to the end`); 50 let seekingCount = 0, seekedCount = 0; 51 el.addEventListener("seeking", () => { 52 is(++seekingCount, 1, "should only receive seeking once!"); 53 }); 54 el.addEventListener("seeked", () => { 55 is(++seekedCount, 1, "should only receive seeked once!"); 56 }); 57 await once(el, "seeking"); 58 59 info(`trim old data before append new data`); 60 let p = Promise.all([once(videosb, "updateend"), once(audiosb, "updateend")]); 61 videosb.remove(videosb.buffered.start(0), videosb.buffered.end(0)); 62 audiosb.remove(audiosb.buffered.start(0), audiosb.buffered.end(0)); 63 await p; 64 65 info(`append new data`); 66 const seekedPromise = once(el, "seeked"); 67 p = Promise.all([once(videosb, "updateend"), once(audiosb, "updateend")]); 68 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 2), ".m4s"); 69 await fetchAndLoad(audiosb, "bipbop/bipbop_audio", range(1, 2), ".m4s"); 70 await p; 71 info(`audio=[${audiosb.buffered.start(0)}-${audiosb.buffered.end(0)}], video=[${videosb.buffered.start(0)}-${videosb.buffered.end(0)}]`); 72 73 info(`now we should be able to finish seeking to the start position`); 74 await seekedPromise; 75 76 SimpleTest.finish(SimpleTest); 77 }); 78 79 </script> 80 </body> 81 </html>