| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>media-source-real-timestampoffset</title> |
| <script src="mp4-generator.js"></script> |
| <script src="../video-test.js"></script> |
| <script> |
| // Tests that timestampOffset correctly shifts buffered ranges. |
| // This is critical because IPC between WebContent and GPU processes |
| // could introduce rounding errors in timestamp calculations. |
| |
| 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 }] |
| }); |
| sourceBuffer.appendBuffer(initData); |
| await waitFor(sourceBuffer, 'updateend'); |
| |
| // Set timestampOffset to 10 seconds before appending |
| run('sourceBuffer.timestampOffset = 10'); |
| |
| // Append 6 samples at DTS 0-5 — with offset, they should land at 10-15 |
| 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: true }, |
| { duration: 1000, compositionTimeOffset: 0, isSync: false }, |
| { duration: 1000, compositionTimeOffset: 0, isSync: false }, |
| ]}] |
| }); |
| sourceBuffer.appendBuffer(media); |
| await waitFor(sourceBuffer, 'updateend'); |
| |
| // Buffered should be [10, 16) due to timestampOffset |
| testExpected('sourceBuffer.buffered.length', 1); |
| testExpected('sourceBuffer.buffered.start(0)', 10); |
| testExpected('sourceBuffer.buffered.end(0)', 16); |
| } |
| |
| window.addEventListener('load', event => { |
| runTest().then(endTest).catch(failTest); |
| }); |
| </script> |
| </head> |
| <body> |
| <video></video> |
| </body> |
| </html> |