From b2f279db1b111e3c8a02706551f466468621cd97 Mon Sep 17 00:00:00 2001 From: theodab Date: Sat, 8 Oct 2022 17:00:11 -0700 Subject: [PATCH] feat(HLS): Lazy-load HLS media playlists (#4511) This changes the HLS parser so that the media playlists are only downloaded when the createSegmentIndex function for the associated stream is called. Because there is some important information about HLS streams that is stored inside the media playlist, this also changes the player to call createSegmentIndex on the initial variant earlier in the load process, to make sure that information is available in time. As of this change, we will now require HLS streams to be aligned (see #4308) for livestreams. VOD content can still be unaligned. Closes #1936 --- lib/hls/hls_parser.js | 818 ++++++++++++++++++----------- lib/media/presentation_timeline.js | 37 +- lib/player.js | 48 +- test/hls/hls_live_unit.js | 106 +++- test/hls/hls_parser_unit.js | 138 ++++- 5 files changed, 793 insertions(+), 354 deletions(-) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 26801b272b..95227eb47d 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -71,6 +71,24 @@ shaka.hls.HlsParser = class { */ this.groupIdToStreamInfosMap_ = new Map(); + /** + * For media playlist lazy-loading to work in livestreams, we have to assume + * that each stream of a type (video, audio, etc) has the same mappings of + * sequence number to start time. + * This map stores those relationships. + * Only used during livestreams; we do not assume that VOD content is + * aligned in that way. + * @private {!Map.>} + */ + this.mediaSequenceToStartTimeByType_ = new Map(); + + // Set initial maps. + const ContentType = shaka.util.ManifestParserUtils.ContentType; + this.mediaSequenceToStartTimeByType_.set(ContentType.VIDEO, new Map()); + this.mediaSequenceToStartTimeByType_.set(ContentType.AUDIO, new Map()); + this.mediaSequenceToStartTimeByType_.set(ContentType.TEXT, new Map()); + this.mediaSequenceToStartTimeByType_.set(ContentType.IMAGE, new Map()); + /** * The values are strings of the form "