Skip to content

Commit 9220c1f

Browse files
committed
fix(hls): Made HLS notify segments after fit
Previously, the HLS parser would notify the presentation timeline of the segments in the manifest before fitting the segments. The HLS parser will also sometimes remove segments from the end of a VOD asset if they do not fit within the playlist duration. This could sometimes cause the presentation timeline and MediaSource to have different opinions on how long the VOD asset was, which could lead to the seek bar looking like the presentation stopped before the end. Closes shaka-project#3733 Change-Id: I67fdc28a3f6eee158c9906359491fe6bb418e730
1 parent b8b72a9 commit 9220c1f

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

lib/hls/hls_parser.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,30 @@ shaka.hls.HlsParser = class {
534534
}
535535
}
536536

537+
// Now that the content has been fit, notify segments.
538+
this.segmentsToNotifyByStream_ = [];
539+
const streamsToNotify = [];
540+
for (const variant of variants) {
541+
for (const stream of [variant.video, variant.audio]) {
542+
if (stream) {
543+
streamsToNotify.push(stream);
544+
}
545+
}
546+
}
547+
await Promise.all(streamsToNotify.map(async (stream) => {
548+
await stream.createSegmentIndex();
549+
}));
550+
for (const stream of streamsToNotify) {
551+
this.segmentsToNotifyByStream_.push(stream.segmentIndex.references);
552+
}
553+
this.notifySegments_();
554+
555+
// This asserts that the live edge is being calculated from segment times.
556+
// For VOD and event streams, this check should still pass.
557+
goog.asserts.assert(
558+
!this.presentationTimeline_.usingPresentationStartTime(),
559+
'We should not be using the presentation start time in HLS!');
560+
537561
this.manifest_ = {
538562
presentationTimeline: this.presentationTimeline_,
539563
variants,
@@ -1618,12 +1642,6 @@ shaka.hls.HlsParser = class {
16181642
}
16191643

16201644
this.notifySegments_();
1621-
1622-
// This asserts that the live edge is being calculated from segment times.
1623-
// For VOD and event streams, this check should still pass.
1624-
goog.asserts.assert(
1625-
!this.presentationTimeline_.usingPresentationStartTime(),
1626-
'We should not be using the presentation start time in HLS!');
16271645
}
16281646

16291647
/**
@@ -2014,9 +2032,6 @@ shaka.hls.HlsParser = class {
20142032
}
20152033
}
20162034

2017-
this.segmentsToNotifyByStream_.push(references);
2018-
this.notifySegments_();
2019-
20202035
return references;
20212036
}
20222037

test/hls/hls_parser_unit.js

+2
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,8 @@ describe('HlsParser', () => {
13091309
// stream.
13101310
const timeline = actual.presentationTimeline;
13111311
expect(timeline.getDuration()).toBe(10);
1312+
expect(timeline.getSeekRangeStart()).toBe(0);
1313+
expect(timeline.getSeekRangeEnd()).toBe(10);
13121314

13131315
expect(actual.textStreams.length).toBe(1);
13141316
expect(actual.variants.length).toBe(1);

0 commit comments

Comments
 (0)