test_TimestampOffset_mp4.html (3155B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>MSE: basic functionality</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 eps = 0.01; 17 18 await once(ms, "sourceopen"); 19 ok(true, "Receive a sourceopen event"); 20 const audiosb = ms.addSourceBuffer("audio/mp4"); 21 const videosb = ms.addSourceBuffer("video/mp4"); 22 // We divide the video into 3 chunks: 23 // chunk 0: segments 1-4 24 // chunk 1: segments 5-8 25 // chunk 2: segments 9-13 26 // We then fill the timeline so that it seamlessly plays the chunks in order 0, 2, 1. 27 const vchunks = [{start: 0, end: 3.2033}, 28 { start: 3.2033, end: 6.4066}, 29 { start: 6.4066, end: 10.01}]; 30 const firstvoffset = vchunks[2].end - vchunks[2].start; // Duration of chunk 2 31 const secondvoffset = -(vchunks[1].end - vchunks[1].start); // -(Duration of chunk 1) 32 33 await fetchAndLoad(videosb, "bipbop/bipbop_video", ["init"], ".mp4"); 34 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(1, 5), ".m4s"); 35 is(videosb.buffered.length, 1, "No discontinuity"); 36 isfuzzy(videosb.buffered.start(0), vchunks[0].start, eps, "Chunk start"); 37 isfuzzy(videosb.buffered.end(0), vchunks[0].end, eps, "Chunk end"); 38 videosb.timestampOffset = firstvoffset; 39 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(5, 9), ".m4s"); 40 is(videosb.buffered.length, 2, "One discontinuity"); 41 isfuzzy(videosb.buffered.start(0), vchunks[0].start, eps, "First Chunk start"); 42 isfuzzy(videosb.buffered.end(0), vchunks[0].end, eps, "First chunk end"); 43 isfuzzy(videosb.buffered.start(1), vchunks[1].start + firstvoffset, eps, "Second chunk start"); 44 isfuzzy(videosb.buffered.end(1), vchunks[1].end + firstvoffset, eps, "Second chunk end"); 45 videosb.timestampOffset = secondvoffset; 46 await fetchAndLoad(videosb, "bipbop/bipbop_video", range(9, 14), ".m4s"); 47 is(videosb.buffered.length, 1, "No discontinuity (end)"); 48 isfuzzy(videosb.buffered.start(0), vchunks[0].start, eps, "Chunk start"); 49 isfuzzy(videosb.buffered.end(0), vchunks[2].end, eps, "Chunk end"); 50 audiosb.timestampOffset = 3; 51 await fetchAndLoad(audiosb, "bipbop/bipbop_audio", ["init"], ".mp4"); 52 await fetchAndLoad(audiosb, "bipbop/bipbop_audio", range(1, 12), ".m4s"); 53 is(audiosb.buffered.length, 1, "No audio discontinuity"); 54 isfuzzy(audiosb.buffered.start(0), 3, eps, "Audio starts at 3"); 55 56 // Trim the rest of the audio. 57 audiosb.remove(videosb.buffered.end(0), Infinity); 58 videosb.remove(videosb.buffered.end(0), Infinity); 59 if (audiosb.updating) { 60 await once(audiosb, "updateend"); 61 } 62 if (videosb.updating) { 63 await once(videosb, "updateend"); 64 } 65 info("waiting for play to complete"); 66 el.play(); 67 el.currentTime = el.buffered.start(0); 68 ms.endOfStream(); 69 await Promise.all([once(el, "ended"), once(el, "seeked")]); 70 SimpleTest.finish(); 71 }); 72 73 </script> 74 </pre> 75 </body> 76 </html>