From 6ecf859cc6536a8ac2cabd20504b4b4943ac7d80 Mon Sep 17 00:00:00 2001 From: Chuck Wilson Date: Fri, 26 Apr 2019 17:33:19 -0400 Subject: [PATCH] fix(source-updater): run callbacks after setting timestampOffset (#480) --- src/source-updater.js | 1 + test/source-updater.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/source-updater.js b/src/source-updater.js index 18819561e..8ff80d699 100644 --- a/src/source-updater.js +++ b/src/source-updater.js @@ -177,6 +177,7 @@ export default class SourceUpdater { if (typeof offset !== 'undefined') { this.queueCallback_(() => { this.sourceBuffer_.timestampOffset = offset; + this.runCallback_(); }); this.timestampOffset_ = offset; } diff --git a/test/source-updater.test.js b/test/source-updater.test.js index b80b06069..21a62b944 100644 --- a/test/source-updater.test.js +++ b/test/source-updater.test.js @@ -131,6 +131,24 @@ QUnit.test('runs the next callback after updateend fires', function(assert) { 'appended the bytes'); }); +QUnit.test('runs the next callback after calling timestampOffset', function(assert) { + let updater = new SourceUpdater(this.mediaSource, 'video/mp2t'); + let sourceBuffer; + + updater.timestampOffset(10); + updater.appendBuffer({ + bytes: new Uint8Array([0, 1, 2]) + }, () => {}); + + this.mediaSource.trigger('sourceopen'); + sourceBuffer = this.mediaSource.sourceBuffers[0]; + + assert.equal(sourceBuffer.timestampOffset, 10, 'offset correctly set'); + assert.equal(sourceBuffer.updates_.length, 1, 'updated once'); + assert.deepEqual(sourceBuffer.updates_[0].append, new Uint8Array([0, 1, 2]), + 'appended the bytes'); +}); + QUnit.test('runs only one callback at a time', function(assert) { let updater = new SourceUpdater(this.mediaSource, 'video/mp2t'); let sourceBuffer;