blob: f26cf30824ab5ee89c7f778b4a0aad7a0d839626 [file] [edit]
<!DOCTYPE html>
<html>
<head>
<title>media-source-real-reinitialize</title>
<script src="mp4-generator.js"></script>
<script src="../video-test.js"></script>
<script>
// Tests that appending a second initialization segment with matching tracks
// succeeds and doesn't disrupt existing buffered data.
// MSE spec section 3.3.2 "Initialization Segment Received" — when a second
// init segment arrives, track count and types must match the first.
// Weakly tested — minimal real-parser coverage.
var source;
var sourceBuffer;
async function runTest() {
findMediaElement();
source = new MediaSource();
video.src = URL.createObjectURL(source);
await waitFor(source, 'sourceopen');
sourceBuffer = source.addSourceBuffer(MP4.VIDEO_TYPE);
var initData = MP4.initSegment({
timescale: 1000,
tracks: [{ id: 1, type: 'video', timescale: 1000 }]
});
// First init
sourceBuffer.appendBuffer(initData);
await waitFor(sourceBuffer, 'updateend');
testExpected('sourceBuffer.videoTracks.length', 1);
// Append media
var media = MP4.mediaSegment({
sequenceNumber: 1,
tracks: [{ id: 1, type: 'video', baseDecodeTime: 0, samples: [
{ duration: 1000, compositionTimeOffset: 0, isSync: true },
{ duration: 1000, compositionTimeOffset: 0, isSync: false },
{ duration: 1000, compositionTimeOffset: 0, isSync: false },
{ duration: 1000, compositionTimeOffset: 0, isSync: false },
]}]
});
sourceBuffer.appendBuffer(media);
await waitFor(sourceBuffer, 'updateend');
testExpected('sourceBuffer.buffered.length', 1);
testExpectedEqualWithTolerance('sourceBuffer.buffered.end(0)', 4, 0.01);
// Second init — same tracks, should succeed without disrupting buffered data
sourceBuffer.appendBuffer(initData);
await waitFor(sourceBuffer, 'updateend');
testExpected('source.readyState', 'open');
testExpected('sourceBuffer.videoTracks.length', 1);
testExpected('sourceBuffer.buffered.length', 1);
testExpectedEqualWithTolerance('sourceBuffer.buffered.end(0)', 4, 0.01);
// Append more media after re-init — should extend the buffer
var media2 = MP4.mediaSegment({
sequenceNumber: 2,
tracks: [{ id: 1, type: 'video', baseDecodeTime: 4000, samples: [
{ duration: 1000, compositionTimeOffset: 0, isSync: true },
{ duration: 1000, compositionTimeOffset: 0, isSync: false },
]}]
});
sourceBuffer.appendBuffer(media2);
await waitFor(sourceBuffer, 'updateend');
testExpected('source.readyState', 'open');
testExpected('sourceBuffer.buffered.length', 1);
testExpectedEqualWithTolerance('sourceBuffer.buffered.end(0)', 6, 0.01);
}
window.addEventListener('load', event => {
runTest().then(endTest).catch(failTest);
});
</script>
</head>
<body>
<video></video>
</body>
</html>