From fb226692eff74d3bddf76c5a371c6592cf1700f1 Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Thu, 16 Mar 2023 02:00:48 -0400 Subject: [PATCH] fix(HLS): don't do sequence mode workaround unless there's a text stream (#5079) The VTT cue timing fix in https://github.com/shaka-project/shaka-player/pull/4217 seems to have caused a regression for videos without VTT streams, where the first segment would sometimes not play smoothly. It also appears to fix the gap jumping seen in the "Art of Motion (HLS, TS)" demo. This was partially fixed for fMP4 in https://github.com/shaka-project/shaka-player/pull/4553 but didn't fix the issue for MPEG-2 TS. Fixes https://github.com/shaka-project/shaka-player/issues/4975. --- lib/media/media_source_engine.js | 7 +++++++ test/media/media_source_engine_unit.js | 1 + 2 files changed, 8 insertions(+) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 7a2acdc0e2..e98287254e 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -408,6 +408,13 @@ shaka.media.MediaSourceEngine = class { 'expected \'open\''); } + if (sequenceMode && !streamsByType.has(ContentType.TEXT)) { + // There's no text stream, 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)); diff --git a/test/media/media_source_engine_unit.js b/test/media/media_source_engine_unit.js index 4806977212..b3b9b62ed9 100644 --- a/test/media/media_source_engine_unit.js +++ b/test/media/media_source_engine_unit.js @@ -639,6 +639,7 @@ describe('MediaSourceEngine', () => { }; const initObject = new Map(); initObject.set(ContentType.VIDEO, fakeVideoStream); + initObject.set(ContentType.TEXT, fakeTextStream); await mediaSourceEngine.init(initObject, /* sequenceMode= */ true);