hls.js 1.6.0-beta.2.0.canary.10846 → 1.6.0-beta.2.0.canary.10853

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hls.js CHANGED
@@ -1058,7 +1058,7 @@
1058
1058
  // Some browsers don't allow to use bind on console object anyway
1059
1059
  // fallback to default if needed
1060
1060
  try {
1061
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.0-beta.2.0.canary.10846");
1061
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.0-beta.2.0.canary.10853");
1062
1062
  } catch (e) {
1063
1063
  /* log fn threw an exception. All logger methods are no-ops. */
1064
1064
  return createLogger();
@@ -7143,7 +7143,7 @@
7143
7143
  }, {
7144
7144
  key: "expired",
7145
7145
  get: function get() {
7146
- if (this.live && this.age) {
7146
+ if (this.live && this.age && this.misses < 3) {
7147
7147
  var playlistWindowDuration = this.partEnd - this.fragmentStart;
7148
7148
  return this.age > Math.max(playlistWindowDuration, this.totalduration) + this.levelTargetDuration;
7149
7149
  }
@@ -8314,6 +8314,9 @@
8314
8314
  return drift;
8315
8315
  }
8316
8316
  function mergeDetails(oldDetails, newDetails) {
8317
+ if (oldDetails === newDetails) {
8318
+ return;
8319
+ }
8317
8320
  // Track the last initSegment processed. Initialize it to the last one on the timeline.
8318
8321
  var currentInitSegment = null;
8319
8322
  var oldFragments = oldDetails.fragments;
@@ -9689,7 +9692,7 @@
9689
9692
  frag = this.getInitialLiveFragment(levelDetails, fragments);
9690
9693
  var mainStart = this.hls.startPosition;
9691
9694
  var liveSyncPosition = this.hls.liveSyncPosition;
9692
- var startPosition = frag ? (mainStart !== -1 ? mainStart : liveSyncPosition) || frag.start : pos;
9695
+ var startPosition = frag ? (mainStart !== -1 && mainStart >= start ? mainStart : liveSyncPosition) || frag.start : pos;
9693
9696
  this.log("Setting startPosition to " + startPosition + " to match initial live edge. mainStart: " + mainStart + " liveSyncPosition: " + liveSyncPosition + " frag.start: " + ((_frag = frag) == null ? void 0 : _frag.start));
9694
9697
  this.startPosition = this.nextLoadPosition = startPosition;
9695
9698
  }
@@ -15690,7 +15693,7 @@
15690
15693
  var duration = getDuration(data, initData);
15691
15694
  var startDTS = getStartDTS(initData, data);
15692
15695
  var decodeTime = startDTS === null ? timeOffset : startDTS;
15693
- if (isInvalidInitPts(initPTS, decodeTime, timeOffset, duration) || initSegment.timescale !== initPTS.timescale && accurateTimeOffset) {
15696
+ if ((accurateTimeOffset || !initPTS) && (isInvalidInitPts(initPTS, decodeTime, timeOffset, duration) || initSegment.timescale !== initPTS.timescale)) {
15694
15697
  initSegment.initPTS = decodeTime - timeOffset;
15695
15698
  if (initPTS && initPTS.timescale === 1) {
15696
15699
  this.logger.warn("Adjusting initPTS @" + timeOffset + " from " + initPTS.baseTime / initPTS.timescale + " to " + initSegment.initPTS);
@@ -16305,7 +16308,7 @@
16305
16308
  return !remuxResult.audio && !remuxResult.video && !remuxResult.text && !remuxResult.id3 && !remuxResult.initSegment;
16306
16309
  }
16307
16310
 
16308
- var version = "1.6.0-beta.2.0.canary.10846";
16311
+ var version = "1.6.0-beta.2.0.canary.10853";
16309
16312
 
16310
16313
  // ensure the worker ends up in the bundle
16311
16314
  // If the worker should not be included this gets aliased to empty.js
@@ -17074,37 +17077,40 @@
17074
17077
  var cachedTrackLoadedData = this.cachedTrackLoadedData;
17075
17078
  if (cachedTrackLoadedData) {
17076
17079
  this.cachedTrackLoadedData = null;
17077
- this.hls.trigger(Events.AUDIO_TRACK_LOADED, cachedTrackLoadedData);
17080
+ this.onAudioTrackLoaded(Events.AUDIO_TRACK_LOADED, cachedTrackLoadedData);
17078
17081
  }
17079
17082
  };
17080
17083
  _proto.onAudioTrackLoaded = function onAudioTrackLoaded(event, data) {
17081
- var _track$details;
17084
+ var _trackLevel$details;
17082
17085
  var levels = this.levels;
17083
17086
  var newDetails = data.details,
17084
- trackId = data.id;
17087
+ trackId = data.id,
17088
+ groupId = data.groupId,
17089
+ track = data.track;
17090
+ if (!levels) {
17091
+ this.warn("Audio tracks reset while loading track " + trackId + " \"" + track.name + "\" of \"" + groupId + "\"");
17092
+ return;
17093
+ }
17085
17094
  var mainDetails = this.mainDetails;
17086
- if (!mainDetails || mainDetails.expired || newDetails.endCC > mainDetails.endCC) {
17095
+ if (!mainDetails || newDetails.endCC > mainDetails.endCC || mainDetails.expired) {
17087
17096
  this.cachedTrackLoadedData = data;
17088
17097
  if (this.state !== State.STOPPED) {
17089
17098
  this.state = State.WAITING_TRACK;
17090
17099
  }
17091
17100
  return;
17092
17101
  }
17093
- if (!levels) {
17094
- this.warn("Audio tracks were reset while loading level " + trackId);
17095
- return;
17096
- }
17097
- this.log("Audio track " + trackId + " loaded [" + newDetails.startSN + "," + newDetails.endSN + "]" + (newDetails.lastPartSn ? "[part-" + newDetails.lastPartSn + "-" + newDetails.lastPartIndex + "]" : '') + ",duration:" + newDetails.totalduration);
17098
- var track = levels[trackId];
17102
+ this.cachedTrackLoadedData = null;
17103
+ this.log("Audio track " + trackId + " \"" + track.name + "\" of \"" + groupId + "\" loaded [" + newDetails.startSN + "," + newDetails.endSN + "]" + (newDetails.lastPartSn ? "[part-" + newDetails.lastPartSn + "-" + newDetails.lastPartIndex + "]" : '') + ",duration:" + newDetails.totalduration);
17104
+ var trackLevel = levels[trackId];
17099
17105
  var sliding = 0;
17100
- if (newDetails.live || (_track$details = track.details) != null && _track$details.live) {
17106
+ if (newDetails.live || (_trackLevel$details = trackLevel.details) != null && _trackLevel$details.live) {
17101
17107
  this.checkLiveUpdate(newDetails);
17102
17108
  if (newDetails.deltaUpdateFailed) {
17103
17109
  return;
17104
17110
  }
17105
- if (track.details) {
17111
+ if (trackLevel.details) {
17106
17112
  var _this$levelLastLoaded;
17107
- sliding = this.alignPlaylists(newDetails, track.details, (_this$levelLastLoaded = this.levelLastLoaded) == null ? void 0 : _this$levelLastLoaded.details);
17113
+ sliding = this.alignPlaylists(newDetails, trackLevel.details, (_this$levelLastLoaded = this.levelLastLoaded) == null ? void 0 : _this$levelLastLoaded.details);
17108
17114
  }
17109
17115
  if (!newDetails.alignedSliding) {
17110
17116
  // Align audio rendition with the "main" playlist on discontinuity change
@@ -17116,8 +17122,8 @@
17116
17122
  sliding = newDetails.fragmentStart;
17117
17123
  }
17118
17124
  }
17119
- track.details = newDetails;
17120
- this.levelLastLoaded = track;
17125
+ trackLevel.details = newDetails;
17126
+ this.levelLastLoaded = trackLevel;
17121
17127
 
17122
17128
  // compute start position if we are aligned with the main playlist
17123
17129
  if (!this.startFragRequested) {
@@ -17433,10 +17439,10 @@
17433
17439
 
17434
17440
  // we force a frag loading in audio switch as fragment tracker might not have evicted previous frags in case of quick audio switch
17435
17441
  if (this.switchingTrack || fragState === FragmentState.NOT_LOADED || fragState === FragmentState.PARTIAL) {
17436
- var _track$details2;
17442
+ var _track$details;
17437
17443
  if (!isMediaFragment(frag)) {
17438
17444
  this._loadInitSegment(frag, track);
17439
- } else if ((_track$details2 = track.details) != null && _track$details2.live && !this.initPTS[frag.cc]) {
17445
+ } else if ((_track$details = track.details) != null && _track$details.live && !this.initPTS[frag.cc]) {
17440
17446
  this.log("Waiting for video PTS in continuity counter " + frag.cc + " of live stream before loading audio fragment " + frag.sn + " of level " + this.trackId);
17441
17447
  this.state = State.WAITING_INIT_PTS;
17442
17448
  var mainDetails = this.mainDetails;
@@ -17456,9 +17462,14 @@
17456
17462
  var bufferedAttributes = bufferedTrack == null ? void 0 : bufferedTrack.attrs;
17457
17463
  var switchAttributes = switchingTrack.attrs;
17458
17464
  if (media && bufferedAttributes && (bufferedAttributes.CHANNELS !== switchAttributes.CHANNELS || bufferedTrack.name !== switchingTrack.name || bufferedTrack.lang !== switchingTrack.lang)) {
17459
- this.log('Switching audio track : flushing all audio');
17460
- _BaseStreamController.prototype.flushMainBuffer.call(this, 0, Number.POSITIVE_INFINITY, 'audio');
17461
- this.bufferedTrack = null;
17465
+ if (useAlternateAudio(switchingTrack.url, this.hls)) {
17466
+ this.log('Switching audio track : flushing all audio');
17467
+ _BaseStreamController.prototype.flushMainBuffer.call(this, 0, Number.POSITIVE_INFINITY, 'audio');
17468
+ this.bufferedTrack = null;
17469
+ } else {
17470
+ // Main is being buffered. Set bufferedTrack so that it is flushed when switching back to alt-audio
17471
+ this.bufferedTrack = switchingTrack;
17472
+ }
17462
17473
  }
17463
17474
  };
17464
17475
  _proto.completeAudioSwitch = function completeAudioSwitch(switchingTrack) {
@@ -32696,6 +32707,7 @@
32696
32707
  transmuxer.push(payload, initSegmentData, audioCodec, videoCodec, frag, part, details.totalduration, accurateTimeOffset, chunkMeta, initPTS);
32697
32708
  };
32698
32709
  _proto.onAudioTrackSwitching = function onAudioTrackSwitching(event, data) {
32710
+ var _this2 = this;
32699
32711
  var hls = this.hls;
32700
32712
  // if any URL found on new audio track, it is an alternate audio track
32701
32713
  var fromAltAudio = this.altAudio === 2;
@@ -32724,12 +32736,17 @@
32724
32736
  }
32725
32737
  // If switching from alt to main audio, flush all audio and trigger track switched
32726
32738
  if (fromAltAudio) {
32739
+ this.fragmentTracker.removeAllFragments();
32740
+ hls.once(Events.BUFFER_FLUSHED, function () {
32741
+ var _this2$hls;
32742
+ (_this2$hls = _this2.hls) == null ? void 0 : _this2$hls.trigger(Events.AUDIO_TRACK_SWITCHED, data);
32743
+ });
32727
32744
  hls.trigger(Events.BUFFER_FLUSHING, {
32728
32745
  startOffset: 0,
32729
32746
  endOffset: Number.POSITIVE_INFINITY,
32730
32747
  type: null
32731
32748
  });
32732
- this.fragmentTracker.removeAllFragments();
32749
+ return;
32733
32750
  }
32734
32751
  hls.trigger(Events.AUDIO_TRACK_SWITCHED, data);
32735
32752
  } else {
@@ -32954,18 +32971,18 @@
32954
32971
  return audioCodec;
32955
32972
  };
32956
32973
  _proto._loadBitrateTestFrag = function _loadBitrateTestFrag(fragment, level) {
32957
- var _this2 = this;
32974
+ var _this3 = this;
32958
32975
  fragment.bitrateTest = true;
32959
32976
  this._doFragLoad(fragment, level).then(function (data) {
32960
- var hls = _this2.hls;
32977
+ var hls = _this3.hls;
32961
32978
  var frag = data == null ? void 0 : data.frag;
32962
- if (!frag || _this2.fragContextChanged(frag)) {
32979
+ if (!frag || _this3.fragContextChanged(frag)) {
32963
32980
  return;
32964
32981
  }
32965
32982
  level.fragmentError = 0;
32966
- _this2.state = State.IDLE;
32967
- _this2.startFragRequested = false;
32968
- _this2.bitrateTest = false;
32983
+ _this3.state = State.IDLE;
32984
+ _this3.startFragRequested = false;
32985
+ _this3.bitrateTest = false;
32969
32986
  var stats = frag.stats;
32970
32987
  // Bitrate tests fragments are neither parsed nor buffered
32971
32988
  stats.parsing.start = stats.parsing.end = stats.buffering.start = stats.buffering.end = self.performance.now();
@@ -33120,7 +33137,7 @@
33120
33137
  }
33121
33138
  };
33122
33139
  _proto._bufferInitSegment = function _bufferInitSegment(currentLevel, tracks, frag, chunkMeta) {
33123
- var _this3 = this;
33140
+ var _this4 = this;
33124
33141
  if (this.state !== State.PARSING) {
33125
33142
  return;
33126
33143
  }
@@ -33213,7 +33230,7 @@
33213
33230
  var track = tracks[trackName];
33214
33231
  var initSegment = track.initSegment;
33215
33232
  if (initSegment != null && initSegment.byteLength) {
33216
- _this3.hls.trigger(Events.BUFFER_APPENDING, {
33233
+ _this4.hls.trigger(Events.BUFFER_APPENDING, {
33217
33234
  type: trackName,
33218
33235
  data: initSegment,
33219
33236
  frag: frag,