| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>mock-media-source</title> |
| <script src="mock-media-source.js"></script> |
| <script src="../video-test.js"></script> |
| <script> |
| var source; |
| var sourceBuffer; |
| var initSegment; |
| |
| if (window.internals) |
| internals.initializeMockMediaSource(); |
| |
| function runTest() { |
| findMediaElement(); |
| |
| source = new MediaSource(); |
| waitForEventOn(source, 'sourceopen', sourceOpen); |
| run('video.src = URL.createObjectURL(source)'); |
| } |
| |
| function sourceOpen() { |
| run('sourceBuffer = source.addSourceBuffer("video/mock; codecs=mock")'); |
| waitForEventOn(sourceBuffer, 'updateend', loadSamples, false, true); |
| initSegment = makeAInit(8, [makeATrack(1, 'mock', TRACK_KIND.VIDEO)]); |
| run('sourceBuffer.appendBuffer(initSegment)'); |
| } |
| |
| function loadSamples() { |
| const maximumGap = Math.floor(2002 / 24000 * 1000) / 1000; |
| |
| samples = concatenateSamples([ |
| makeASample( 0, 0, 1000 * (1 - maximumGap), 1000, 1, SAMPLE_FLAG.SYNC), |
| makeASample(1000, 1000, 1000 * (1 - maximumGap / 2), 1000, 1, SAMPLE_FLAG.NONE), |
| makeASample(2000, 2000, 1000 * (1 - maximumGap / 3), 1000, 1, SAMPLE_FLAG.NONE), |
| makeASample(3000, 3000, 1000, 1000, 1, SAMPLE_FLAG.NONE), |
| makeASample(4000, 4000, 1000 * (1 - maximumGap), 1000, 1, SAMPLE_FLAG.SYNC), |
| makeASample(5000, 5000, 1000 * (1 - maximumGap / 10), 1000, 1, SAMPLE_FLAG.NONE), |
| makeASample(6000, 6000, 1000 * (0.99), 1000, 1, SAMPLE_FLAG.NONE), |
| makeASample(7000, 7000, 1000, 1000, 1, SAMPLE_FLAG.NONE), |
| ]); |
| |
| waitForEventOn(sourceBuffer, 'updateend', checkBuffered, false, true); |
| run('sourceBuffer.appendBuffer(samples)'); |
| } |
| |
| function checkBuffered() { |
| testExpected('sourceBuffer.buffered.length', 1); |
| testExpected('sourceBuffer.buffered.start(0)', 0); |
| testExpected('sourceBuffer.buffered.end(0)', 8); |
| |
| run('video.play()'); |
| waitForEvent('ended', ended); |
| } |
| |
| function ended() { |
| testExpected('video.currentTime', 8); |
| endTest(); |
| } |
| |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <div>This tests the SourceBuffer.buffered() API. This test will add 8 samples with a small gap (0.01s .. 0.083s) between each sample. The SourceBuffer should coalesce such small gaps to make a single contiguous range. The video element should also play continuously from the beginning to the end.</div> |
| <video></video> |
| </body> |
| </html> |