test_InputBufferIsCleared.html (2222B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>MSE: input buffer is cleared as expected (bug 1697476)</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 // Test bug 1697476 is fixed. We do this by appending a number of segments with 16 // trailing `skip` boxes. If the bug is fixed, then the data from these appends 17 // will eventually be cleared from memory. If not fixed, we leak that memory. 18 runWithMSE(async (ms, v) => { 19 await once(ms, "sourceopen"); 20 const sb = ms.addSourceBuffer("video/mp4"); 21 await fetchAndLoad(sb, "bipbop/bipbop_video", ["init"], ".mp4"); 22 // Load ~1mb of media. 23 await fetchAndLoad(sb, "bipbop/bipbop_trailing_skip_box_video", ["1"], ".m4s"); 24 // Load ~1mb more media several more times. 25 const numberOfAppends = 5; 26 for (let i = 1; i < numberOfAppends; ++i) { 27 sb.timestampOffset = v.buffered.end(0); 28 await fetchAndLoad(sb, "bipbop/bipbop_trailing_skip_box_video", ["1"], ".m4s"); 29 } 30 31 // Grab a memory report. We'll use this to make sure we're not accumulating 32 // too much data in our buffers. 33 const mgr = SpecialPowers.Cc["@mozilla.org/memory-reporter-manager;1"] 34 .getService(SpecialPowers.Ci.nsIMemoryReporterManager); 35 36 let amount = 0; 37 const handleReport = (aProcess, aPath, aKind, aUnits, aAmount) => { 38 if (aPath == "explicit/media/resources") { 39 amount += aAmount; 40 } 41 }; 42 43 await new Promise(r => mgr.getReports(handleReport, null, r, null, /* anonymized = */ false)); 44 ok(true, "Yay didn't crash!"); 45 ok(amount !== undefined, "Got media resources amount"); 46 const sgementSize = 1023860; 47 // Set the limit to be equal to the total data we appended. If we're not 48 // clearing buffers, we'll have all the data from the appends + some other 49 // data, so will fail. 50 const limit = sgementSize * numberOfAppends - 1; 51 ok(amount < limit, `Should have less than ${limit} bytes of media usage. Got ${amount} bytes.`); 52 SimpleTest.finish(); 53 }); 54 55 </script> 56 </pre> 57 </body> 58 </html>