Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HLS): Reset textSequenceModeOffset on discontinuity #6388

Merged
merged 11 commits into from
Apr 4, 2024
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ module.exports = (config) => {
{pattern: 'test/test/assets/hls-raw-ec3/*', included: false},
{pattern: 'test/test/assets/hls-raw-mp3/*', included: false},
{pattern: 'test/test/assets/hls-sample-aes/*', included: false},
{pattern: 'test/test/assets/hls-text-offset/*', included: false},
{pattern: 'test/test/assets/hls-ts-aac/*', included: false},
{pattern: 'test/test/assets/hls-ts-ac3/*', included: false},
{pattern: 'test/test/assets/hls-ts-ec3/*', included: false},
Expand Down
6 changes: 6 additions & 0 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,12 @@ shaka.media.MediaSourceEngine = class {
return;
}

// Reset the promise in case the timestamp offset changed during
// a period/discontinuity transition.
if (contentType == ContentType.VIDEO) {
this.textSequenceModeOffset_ = new shaka.util.PublicPromise();
}

// Queue an abort() to help MSE splice together overlapping segments.
// We set appendWindowEnd when we change periods in DASH content, and the
// period transition may result in overlap.
Expand Down
26 changes: 26 additions & 0 deletions test/hls/hls_parser_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,30 @@ describe('HlsParser', () => {

await player.unload();
});

it('supports text discontinuity', async () => {
if (!shaka.util.Platform.supportsSequenceMode()) {
pending('Sequence mode is not supported by the platform.');
}

player.configure('manifest.hls.ignoreManifestProgramDateTime', true);
player.setTextTrackVisibility(true);

await player.load('/base/test/test/assets/hls-text-offset/index.m3u8');
await video.play();

// Wait for last cue
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 7, 30);

const cues = video.textTracks[0].cues;
expect(cues.length).toBe(3);
expect(cues[0].startTime).toBeCloseTo(0, 0);
expect(cues[0].endTime).toBeCloseTo(2, 0);
expect(cues[1].startTime).toBeCloseTo(2, 0);
expect(cues[1].endTime).toBeCloseTo(4, 0);
expect(cues[2].startTime).toBeCloseTo(6, 0);
expect(cues[2].endTime).toBeCloseTo(8, 0);

await player.unload();
});
});
8 changes: 8 additions & 0 deletions test/test/assets/hls-text-offset/index.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-INDEPENDENT-SEGMENTS

#EXT-X-STREAM-INF:BANDWIDTH=728000,AVERAGE-BANDWIDTH=728000,RESOLUTION=640x360,CODECS="avc1.4d001e,mp4a.40.2",SUBTITLES="subs"
playlist-video.m3u8

#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",LANGUAGE="en-US",NAME="caption_webvtt_en_webvtt",AUTOSELECT=YES,DEFAULT=YES,FORCED=NO,URI="playlist-vtt.m3u8"
22 changes: 22 additions & 0 deletions test/test/assets/hls-text-offset/playlist-video.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:07.364Z
#EXTINF:2.000000
video-069.ts
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:09.364Z
#EXTINF:2.000000
video-070.ts
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:11.364Z
#EXTINF:1.583000
video-071.ts
#EXT-X-DISCONTINUITY
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:27.573Z
#EXTINF:0.917000
video-072.ts
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:28.490Z
#EXTINF:2.000000
video-073.ts
#EXT-X-ENDLIST
22 changes: 22 additions & 0 deletions test/test/assets/hls-text-offset/playlist-vtt.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:07.364Z
#EXTINF:2.000000
vtt-069.vtt
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:09.364Z
#EXTINF:2.000000
vtt-070.vtt
#EXT-X-DISCONTINUITY
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:27.573Z
#EXTINF:0.917000
vtt-071.vtt
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:28.490Z
#EXTINF:2.000000
vtt-072.vtt
#EXT-X-PROGRAM-DATE-TIME:2024-03-05T23:17:30.490Z
#EXTINF:2.000000
vtt-073.vtt
#EXT-X-ENDLIST
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/test/assets/hls-text-offset/video-069.ts
Binary file not shown.
Binary file added test/test/assets/hls-text-offset/video-070.ts
Binary file not shown.
Binary file added test/test/assets/hls-text-offset/video-071.ts
Binary file not shown.
Binary file added test/test/assets/hls-text-offset/video-072.ts
Binary file not shown.
Binary file added test/test/assets/hls-text-offset/video-073.ts
Binary file not shown.
5 changes: 5 additions & 0 deletions test/test/assets/hls-text-offset/vtt-069.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
WEBVTT
X-TIMESTAMP-MAP=LOCAL:01:00:00.000,MPEGTS:324000000

02:20.000 --> 02:22.000
You're a jerk Tom!
5 changes: 5 additions & 0 deletions test/test/assets/hls-text-offset/vtt-070.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
WEBVTT
X-TIMESTAMP-MAP=LOCAL:01:00:00.000,MPEGTS:324000000

02:22.000 --> 02:24.000
You're jealous of my robot hand!
2 changes: 2 additions & 0 deletions test/test/assets/hls-text-offset/vtt-071.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WEBVTT
X-TIMESTAMP-MAP=LOCAL:01:00:00.000,MPEGTS:324000000
2 changes: 2 additions & 0 deletions test/test/assets/hls-text-offset/vtt-072.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WEBVTT
X-TIMESTAMP-MAP=LOCAL:01:00:00.000,MPEGTS:324000000
5 changes: 5 additions & 0 deletions test/test/assets/hls-text-offset/vtt-073.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
WEBVTT
X-TIMESTAMP-MAP=LOCAL:01:00:00.000,MPEGTS:324000000

00:03.500 --> 00:05.500
cues after discontinuity