Skip to content

Commit

Permalink
fix(hls): Fix single-variant HLS streams
Browse files Browse the repository at this point in the history
The changes to implement lazy-loading broke the previous functionality
to load media playlists directly, as they are not lazy loaded.
This fixes that case, so that lazy-loaded media playlists will correctly
set their duration and presentation type.

Issue shaka-project#1936
Issue shaka-project#3536
  • Loading branch information
theodab committed Oct 12, 2022
1 parent 757b34e commit c6cee8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 21 additions & 6 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,19 @@ shaka.hls.HlsParser = class {
/* presentationStartTime= */ null, /* delay= */ 0);
this.presentationTimeline_.setStatic(true);

// Single-variant streams aren't lazy-loaded, so for them we already have
// enough info here to determine the presentation type and duration.
if (playlist.type == shaka.hls.PlaylistType.MEDIA) {
if (this.isLive_()) {
this.changePresentationTimelineToLive_();
const delay = this.updatePlaylistDelay_;
this.updatePlaylistTimer_.tickAfter(/* seconds= */ delay);
}
const streamInfos = Array.from(this.uriToStreamInfosMap_.values());
this.finalizeStreams_(streamInfos);
this.determineDuration_();
}

this.manifest_ = {
presentationTimeline: this.presentationTimeline_,
variants,
Expand Down Expand Up @@ -1604,11 +1617,6 @@ shaka.hls.HlsParser = class {
stream.roles = realStream.roles;
stream.mimeType = realStream.mimeType;

// MediaSource expects no codec strings combined with raw formats.
if (shaka.media.MediaSourceEngine.RAW_FORMATS.includes(stream.mimeType)) {
stream.codecs = '';
}

// Add finishing touches to the stream that can only be done once we have
// more full context on the media as a whole.
if (this.hasEnoughInfoToFinalizeStreams_()) {
Expand Down Expand Up @@ -1692,6 +1700,13 @@ shaka.hls.HlsParser = class {
streamInfo.stream.segmentIndex.fit(/* periodStart= */ 0, minDuration);
}
}
// MediaSource expects no codec strings combined with raw formats.
for (const streamInfo of streamInfos) {
const stream = streamInfo.stream;
if (shaka.media.MediaSourceEngine.RAW_FORMATS.includes(stream.mimeType)) {
stream.codecs = '';
}
}
this.notifySegmentsForStreams_(streamInfos.map((s) => s.stream));
if (this.config_.hls.ignoreManifestProgramDateTime) {
this.syncStreamsWithSequenceNumber_(streamInfos);
Expand Down Expand Up @@ -1872,7 +1887,7 @@ shaka.hls.HlsParser = class {

return {
stream,
type: '', // Not set here
type,
verbatimMediaPlaylistUri,
absoluteMediaPlaylistUri,
maxTimestamp: lastEndTime,
Expand Down
4 changes: 3 additions & 1 deletion test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3841,7 +3841,9 @@ describe('HlsParser', () => {
});
});

await testHlsParser(media, '', manifest);
const actualManifest = await testHlsParser(media, '', manifest);

expect(actualManifest.presentationTimeline.getDuration()).toBe(5);
});

it('honors hls.mediaPlaylistFullMimeType', async () => {
Expand Down

0 comments on commit c6cee8a

Please sign in to comment.