From 8f6b55a1cd8a3e47d043e840676af2bd6ae6253a Mon Sep 17 00:00:00 2001 From: Theodore Abshire Date: Sun, 11 Sep 2022 15:35:02 -0700 Subject: [PATCH] feat(HLS): Lazy-load HLS media playlists 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. Closes #1936 --- lib/hls/hls_parser.js | 781 ++++++++++++++++++----------- lib/media/presentation_timeline.js | 14 + lib/player.js | 63 ++- test/hls/hls_live_unit.js | 106 +++- test/hls/hls_parser_unit.js | 68 ++- 5 files changed, 699 insertions(+), 333 deletions(-) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 26801b272b1..ce5442a52ff 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -71,6 +71,22 @@ 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. + * @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 "