Skip to content

Commit

Permalink
fix(hls): Made HLS notify segments after fit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
theodab committed Nov 3, 2021
1 parent b8b72a9 commit 9220c1f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 24 additions & 9 deletions lib/hls/hls_parser.js
Expand Up @@ -534,6 +534,30 @@ shaka.hls.HlsParser = class {
}
}

// Now that the content has been fit, notify segments.
this.segmentsToNotifyByStream_ = [];
const streamsToNotify = [];
for (const variant of variants) {
for (const stream of [variant.video, variant.audio]) {
if (stream) {
streamsToNotify.push(stream);
}
}
}
await Promise.all(streamsToNotify.map(async (stream) => {
await stream.createSegmentIndex();
}));
for (const stream of streamsToNotify) {
this.segmentsToNotifyByStream_.push(stream.segmentIndex.references);
}
this.notifySegments_();

// This asserts that the live edge is being calculated from segment times.
// For VOD and event streams, this check should still pass.
goog.asserts.assert(
!this.presentationTimeline_.usingPresentationStartTime(),
'We should not be using the presentation start time in HLS!');

this.manifest_ = {
presentationTimeline: this.presentationTimeline_,
variants,
Expand Down Expand Up @@ -1618,12 +1642,6 @@ shaka.hls.HlsParser = class {
}

this.notifySegments_();

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

/**
Expand Down Expand Up @@ -2014,9 +2032,6 @@ shaka.hls.HlsParser = class {
}
}

this.segmentsToNotifyByStream_.push(references);
this.notifySegments_();

return references;
}

Expand Down
2 changes: 2 additions & 0 deletions test/hls/hls_parser_unit.js
Expand Up @@ -1309,6 +1309,8 @@ describe('HlsParser', () => {
// stream.
const timeline = actual.presentationTimeline;
expect(timeline.getDuration()).toBe(10);
expect(timeline.getSeekRangeStart()).toBe(0);
expect(timeline.getSeekRangeEnd()).toBe(10);

expect(actual.textStreams.length).toBe(1);
expect(actual.variants.length).toBe(1);
Expand Down

0 comments on commit 9220c1f

Please sign in to comment.