Skip to content

Commit

Permalink
fix(HLS): Don't do sequence mode workaround unless there's a text stream
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jun 15, 2023
1 parent 07ca8f5 commit 30d59cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ shaka.media.MediaSourceEngine = class {
/** @private {boolean} */
this.ignoreManifestTimestampsInSegmentsMode_ = false;

/** @private {boolean} */
this.hasTextStreams_ = true;

/** @private {!shaka.util.PublicPromise.<number>} */
this.textSequenceModeOffset_ = new shaka.util.PublicPromise();
}
Expand Down Expand Up @@ -369,18 +372,22 @@ shaka.media.MediaSourceEngine = class {
* segment durations being out of sync with segment durations. In other
* words, assume that there are no gaps in the segments when appending
* to the SourceBuffer, even if the manifest and segment times disagree.
* @param {string=} hasTextStreams
* Indicates if the manifest has text streams.
*
* @return {!Promise}
*/
async init(streamsByType, sequenceMode=false,
manifestType=shaka.media.ManifestParser.UNKNOWN,
ignoreManifestTimestampsInSegmentsMode=false) {
ignoreManifestTimestampsInSegmentsMode=false,
hasTextStreams=true) {
await this.mediaSourceOpen_;

this.sequenceMode_ = sequenceMode;
this.manifestType_ = manifestType;
this.ignoreManifestTimestampsInSegmentsMode_ =
ignoreManifestTimestampsInSegmentsMode;
this.hasTextStreams_ = hasTextStreams;

for (const contentType of streamsByType.keys()) {
const stream = streamsByType.get(contentType);
Expand Down Expand Up @@ -447,6 +454,13 @@ shaka.media.MediaSourceEngine = class {
'expected \'open\'');
}

if (this.sequenceMode_ && !this.hasTextStreams_) {
// There's no text streams, so we can set sequence mode early instead
// of setting it after the first segment is appended in appendBuffer_.
sourceBuffer.mode =
shaka.media.MediaSourceEngine.SourceBufferMode_.SEQUENCE;
}

this.eventManager_.listen(
sourceBuffer, 'error',
() => this.onError_(contentType));
Expand Down
1 change: 1 addition & 0 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ shaka.media.StreamingEngine = class {
this.manifest_.sequenceMode,
this.manifest_.type,
this.manifest_.ignoreManifestTimestampsInSegmentsMode,
this.manifest_.textStreams.length > 0
);
this.destroyer_.ensureNotDestroyed();

Expand Down

0 comments on commit 30d59cf

Please sign in to comment.