diff --git a/AUTHORS b/AUTHORS index 39cf13edea..9aa71c3872 100644 --- a/AUTHORS +++ b/AUTHORS @@ -32,6 +32,7 @@ Cristian Atehortua Damien Deis Dany L'Hébreux Dave Nicholas +David Pfister Davide Zordan Dl Dador Edgeware AB <*@edgeware.tv> diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 76351d75e1..c78e5553c6 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -48,6 +48,7 @@ Cristian Atehortua Damien Deis Dany L'Hébreux Dave Nicholas +David Pfister Davide Zordan Dl Dador Donato Borrello diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index deb05c0f07..e8ffc1289a 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -1844,6 +1844,48 @@ shaka.media.MediaSourceEngine = class { null); } + /** + * Returns the source buffer parameters + * @param {shaka.util.ManifestParserUtils.ContentType} contentType + * @return {?shaka.media.MediaSourceEngine.SourceBufferParams} + * @private + */ + getSourceBufferParams_(contentType) { + if (!this.sourceBuffers_[contentType]) { + return null; + } + return { + timestampOffset: this.sourceBuffers_[contentType].timestampOffset, + appendWindowStart: this.sourceBuffers_[contentType].appendWindowStart, + appendWindowEnd: this.sourceBuffers_[contentType].appendWindowEnd, + }; + } + + /** + * Restore source buffer parameters + * @param {shaka.util.ManifestParserUtils.ContentType} contentType + * @param {?shaka.media.MediaSourceEngine.SourceBufferParams} params + * @private + */ + restoreSourceBufferParams_(contentType, params) { + if (!params) { + return; + } + + if (!this.sourceBuffers_[contentType]) { + shaka.log.warning('Attempted to restore a non-existent source buffer'); + return; + } + + this.sourceBuffers_[contentType].timestampOffset = + params.timestampOffset; + // `end` needs to be set before `start` + this.sourceBuffers_[contentType].appendWindowEnd = + params.appendWindowEnd; + this.sourceBuffers_[contentType].appendWindowStart = + params.appendWindowStart; + } + /** * Resets the MediaSource and re-adds source buffers due to codec mismatch * @@ -1904,7 +1946,6 @@ shaka.media.MediaSourceEngine = class { } await Promise.all(cleanup); this.transmuxers_ = {}; - this.sourceBuffers_ = {}; const previousDuration = this.mediaSource_.duration; this.mediaSourceOpen_ = new shaka.util.PublicPromise(); @@ -1935,6 +1976,7 @@ shaka.media.MediaSourceEngine = class { onSourceBufferAdded); for (const contentType of streamsByType.keys()) { + const previousParams = this.getSourceBufferParams_(contentType); const stream = streamsByType.get(contentType); // eslint-disable-next-line no-await-in-loop await this.initSourceBuffer_(contentType, stream, stream.codecs); @@ -1944,6 +1986,8 @@ shaka.media.MediaSourceEngine = class { } else { this.queues_[contentType] = []; } + + this.restoreSourceBufferParams_(contentType, previousParams); } // Fake a seek to catchup the playhead. @@ -2231,3 +2275,12 @@ shaka.media.MediaSourceEngine.SourceBufferMode_ = { * Callback to use when metadata arrives. */ shaka.media.MediaSourceEngine.PlayerInterface; + +/** + * @typedef {{ + * timestampOffset: number, + * appendWindowStart: number, + * appendWindowEnd: number + * }} + */ +shaka.media.MediaSourceEngine.SourceBufferParams;