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): Fix single-variant HLS streams #4573

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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