|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <title>media-source-samples-out-of-order-erase-last-previous-frames</title> |
| 5 | + <script src="mock-media-source.js"></script> |
| 6 | + <script src="../video-test.js"></script> |
| 7 | + <script> |
| 8 | + var source; |
| 9 | + var sourceBuffer; |
| 10 | + var initSegment; |
| 11 | + var mediaSegment; |
| 12 | + |
| 13 | + if (window.internals) |
| 14 | + internals.initializeMockMediaSource(); |
| 15 | + |
| 16 | + window.addEventListener('load', async event => { |
| 17 | + findMediaElement(); |
| 18 | + |
| 19 | + source = new MediaSource(); |
| 20 | + run('video.src = URL.createObjectURL(source)'); |
| 21 | + await waitFor(source, 'sourceopen'); |
| 22 | + |
| 23 | + run('sourceBuffer = source.addSourceBuffer("video/mock; codecs=mock")'); |
| 24 | + |
| 25 | + // Test 1. |
| 26 | + |
| 27 | + consoleWrite("Test 1: First segment has normal, monotonically increasing samples with decode timestamp equal "); |
| 28 | + consoleWrite("to presentation timestamp."); |
| 29 | + |
| 30 | + mediaSegment = concatenateSamples([ |
| 31 | + makeAInit(4, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 32 | + // Syntax: makeASample(presentationTime, decodeTime, duration, timeScale, trackID, flags, generation) |
| 33 | + makeASample( 0, 0, 10, 10, 0, SAMPLE_FLAG.SYNC, 0), |
| 34 | + makeASample(10, 10, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 35 | + makeASample(20, 20, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 36 | + makeASample(30, 30, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 37 | + ]); |
| 38 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 39 | + await waitFor(sourceBuffer, 'updateend'); |
| 40 | + |
| 41 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 42 | + testExpected("bufferedSamples.length", 4); |
| 43 | + bufferedSamples.forEach(consoleWrite); |
| 44 | + |
| 45 | + consoleWrite("Test 1: Second, segment with overlap in decoding order but no overlap in presentation order shouldn't "); |
| 46 | + consoleWrite("cause any deletion if decoding order is corrected to avoid conflicts."); |
| 47 | + |
| 48 | + mediaSegment = concatenateSamples([ |
| 49 | + makeAInit(1, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 50 | + makeASample(40, 9, 50, 10, 0, SAMPLE_FLAG.SYNC, 1), |
| 51 | + ]); |
| 52 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 53 | + await waitFor(sourceBuffer, 'updateend'); |
| 54 | + |
| 55 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 56 | + testExpected("bufferedSamples.length", 5); |
| 57 | + bufferedSamples.forEach(consoleWrite); |
| 58 | + |
| 59 | + run('sourceBuffer.remove(0, Infinity)'); |
| 60 | + await waitFor(sourceBuffer, 'updateend'); |
| 61 | + |
| 62 | + // Test 2. |
| 63 | + |
| 64 | + consoleWrite("Test 2: First segment has normal, monotonically increasing samples with decode timestamp equal "); |
| 65 | + consoleWrite("to presentation timestamp, and a last sync sample."); |
| 66 | + |
| 67 | + mediaSegment = concatenateSamples([ |
| 68 | + makeAInit(4, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 69 | + makeASample( 0, 0, 10, 10, 0, SAMPLE_FLAG.SYNC, 0), |
| 70 | + makeASample( 10, 10, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 71 | + makeASample( 20, 20, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 72 | + makeASample( 30, 30, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 73 | + makeASample(100, 100, 10, 10, 0, SAMPLE_FLAG.SYNC, 0) |
| 74 | + ]); |
| 75 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 76 | + await waitFor(sourceBuffer, 'updateend'); |
| 77 | + |
| 78 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 79 | + testExpected("bufferedSamples.length", 5); |
| 80 | + bufferedSamples.forEach(consoleWrite); |
| 81 | + |
| 82 | + consoleWrite("Test 2: Second, segment with overlap in decoding order but no overlap in presentation order shouldn't "); |
| 83 | + consoleWrite("cause any deletion if decoding order is corrected to avoid conflicts."); |
| 84 | + |
| 85 | + mediaSegment = concatenateSamples([ |
| 86 | + makeAInit(1, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 87 | + makeASample(40, 9, 50, 10, 0, SAMPLE_FLAG.SYNC, 1), |
| 88 | + ]); |
| 89 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 90 | + await waitFor(sourceBuffer, 'updateend'); |
| 91 | + |
| 92 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 93 | + testExpected("bufferedSamples.length", 6); |
| 94 | + bufferedSamples.forEach(consoleWrite); |
| 95 | + |
| 96 | + run('sourceBuffer.remove(0, Infinity)'); |
| 97 | + await waitFor(sourceBuffer, 'updateend'); |
| 98 | + |
| 99 | + // Test 3. |
| 100 | + |
| 101 | + consoleWrite("Test 3: First segment has normal, monotonically increasing samples with decode timestamp equal "); |
| 102 | + consoleWrite("to presentation timestamp."); |
| 103 | + |
| 104 | + mediaSegment = concatenateSamples([ |
| 105 | + makeAInit(4, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 106 | + makeASample( 0, 0, 10, 10, 0, SAMPLE_FLAG.SYNC, 0), |
| 107 | + makeASample(10, 10, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 108 | + makeASample(20, 20, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 109 | + makeASample(30, 30, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 110 | + ]); |
| 111 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 112 | + await waitFor(sourceBuffer, 'updateend'); |
| 113 | + |
| 114 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 115 | + testExpected("bufferedSamples.length", 4); |
| 116 | + bufferedSamples.forEach(consoleWrite); |
| 117 | + |
| 118 | + consoleWrite("Test 3: Segment with overlap in decoding order but no overlap in presentation order shouldn't "); |
| 119 | + consoleWrite("cause any deletion if decoding order is corrected to avoid conflicts. This correction can't extend "); |
| 120 | + consoleWrite("beyond the duration of the sample, to avoid conflicts with the hypothetical decode timestamp of a "); |
| 121 | + consoleWrite("sample appended in the future (DTS 39/10), so some samples will be deleted to prevent that. "); |
| 122 | + consoleWrite("Same duration samples."); |
| 123 | + |
| 124 | + mediaSegment = concatenateSamples([ |
| 125 | + makeAInit(1, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 126 | + makeASample(40, 29, 10, 10, 0, SAMPLE_FLAG.SYNC, 1), |
| 127 | + ]); |
| 128 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 129 | + await waitFor(sourceBuffer, 'updateend'); |
| 130 | + |
| 131 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 132 | + testExpected("bufferedSamples.length", 5); |
| 133 | + bufferedSamples.forEach(consoleWrite); |
| 134 | + |
| 135 | + run('sourceBuffer.remove(0, Infinity)'); |
| 136 | + await waitFor(sourceBuffer, 'updateend'); |
| 137 | + |
| 138 | + // Test 4. |
| 139 | + |
| 140 | + consoleWrite("Test 4: First segment has normal, monotonically increasing samples with decode timestamp equal "); |
| 141 | + consoleWrite("to presentation timestamp, and a last sync sample."); |
| 142 | + |
| 143 | + mediaSegment = concatenateSamples([ |
| 144 | + makeAInit(4, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 145 | + makeASample( 0, 0, 10, 10, 0, SAMPLE_FLAG.SYNC, 0), |
| 146 | + makeASample( 10, 10, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 147 | + makeASample( 20, 20, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 148 | + makeASample( 30, 30, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 149 | + makeASample(100, 100, 10, 10, 0, SAMPLE_FLAG.SYNC, 0) |
| 150 | + ]); |
| 151 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 152 | + await waitFor(sourceBuffer, 'updateend'); |
| 153 | + |
| 154 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 155 | + testExpected("bufferedSamples.length", 5); |
| 156 | + bufferedSamples.forEach(consoleWrite); |
| 157 | + |
| 158 | + consoleWrite("Test 4: Second, segment with overlap in decoding order but no overlap in presentation order shouldn't "); |
| 159 | + consoleWrite("cause any deletion if decoding order is corrected to avoid conflicts. This correction can't extend "); |
| 160 | + consoleWrite("beyond the duration of the sample, to avoid conflicts with the hypothetical decode timestamp of a "); |
| 161 | + consoleWrite("sample appended in the future (DTS 39/10), so some samples will be deleted to prevent that. "); |
| 162 | + consoleWrite("Same duration samples."); |
| 163 | + |
| 164 | + mediaSegment = concatenateSamples([ |
| 165 | + makeAInit(1, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 166 | + makeASample(40, 29, 10, 10, 0, SAMPLE_FLAG.SYNC, 1), |
| 167 | + ]); |
| 168 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 169 | + await waitFor(sourceBuffer, 'updateend'); |
| 170 | + |
| 171 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 172 | + testExpected("bufferedSamples.length", 6); |
| 173 | + bufferedSamples.forEach(consoleWrite); |
| 174 | + |
| 175 | + run('sourceBuffer.remove(0, Infinity)'); |
| 176 | + await waitFor(sourceBuffer, 'updateend'); |
| 177 | + |
| 178 | + // Test 5. |
| 179 | + |
| 180 | + consoleWrite("Test 5: First segment has normal, monotonically increasing samples with decode timestamp equal "); |
| 181 | + consoleWrite("to presentation timestamp, and a last sync sample."); |
| 182 | + |
| 183 | + mediaSegment = concatenateSamples([ |
| 184 | + makeAInit(4, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 185 | + makeASample( 0, 0, 10, 10, 0, SAMPLE_FLAG.SYNC, 0), |
| 186 | + makeASample( 10, 10, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 187 | + makeASample( 20, 20, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 188 | + makeASample( 30, 30, 10, 10, 0, SAMPLE_FLAG.NONE, 0), |
| 189 | + makeASample(100, 100, 10, 10, 0, SAMPLE_FLAG.SYNC, 0) |
| 190 | + ]); |
| 191 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 192 | + await waitFor(sourceBuffer, 'updateend'); |
| 193 | + |
| 194 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 195 | + testExpected("bufferedSamples.length", 5); |
| 196 | + bufferedSamples.forEach(consoleWrite); |
| 197 | + |
| 198 | + consoleWrite("Test 5: Second, segment with overlap in decoding order but no overlap in presentation order shouldn't "); |
| 199 | + consoleWrite("cause any deletion if decoding order is corrected to avoid conflicts. This correction can't extend "); |
| 200 | + consoleWrite("beyond the duration of the sample, to avoid conflicts with the hypothetical decode timestamp of a "); |
| 201 | + consoleWrite("sample appended in the future (DTS 29/10). This isn't met, so the whole correction algorithm bails out. "); |
| 202 | + consoleWrite("and all the conflicting samples are deleted (old behaviour). Same duration samples."); |
| 203 | + |
| 204 | + mediaSegment = concatenateSamples([ |
| 205 | + makeAInit(1, [makeATrack(0, 'mock', TRACK_KIND.VIDEO)]), |
| 206 | + makeASample(40, 19, 10, 10, 0, SAMPLE_FLAG.SYNC, 1), |
| 207 | + ]); |
| 208 | + run('sourceBuffer.appendBuffer(mediaSegment)'); |
| 209 | + await waitFor(sourceBuffer, 'updateend'); |
| 210 | + |
| 211 | + bufferedSamples = await internals.bufferedSamplesForTrackId(sourceBuffer, 0); |
| 212 | + testExpected("bufferedSamples.length", 4); |
| 213 | + bufferedSamples.forEach(consoleWrite); |
| 214 | + |
| 215 | + run('sourceBuffer.remove(0, Infinity)'); |
| 216 | + await waitFor(sourceBuffer, 'updateend'); |
| 217 | + |
| 218 | + endTest(); |
| 219 | + }); |
| 220 | + </script> |
| 221 | +</head> |
| 222 | +<body> |
| 223 | + <video></video> |
| 224 | +</body> |
| 225 | +</html> |
0 commit comments