hls.js 1.6.0-beta.1.0.canary.10714 → 1.6.0-beta.1.0.canary.10717

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
@@ -1054,7 +1054,7 @@
1054
1054
  // Some browsers don't allow to use bind on console object anyway
1055
1055
  // fallback to default if needed
1056
1056
  try {
1057
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.0-beta.1.0.canary.10714");
1057
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.0-beta.1.0.canary.10717");
1058
1058
  } catch (e) {
1059
1059
  /* log fn threw an exception. All logger methods are no-ops. */
1060
1060
  return createLogger();
@@ -2067,6 +2067,7 @@
2067
2067
  quickly enough to prevent underbuffering
2068
2068
  */
2069
2069
  _this._abandonRulesCheck = function () {
2070
+ var _this$hls$latestLevel;
2070
2071
  var _this2 = _this,
2071
2072
  frag = _this2.fragCurrent,
2072
2073
  part = _this2.partCurrent,
@@ -2118,12 +2119,15 @@
2118
2119
  }
2119
2120
  var loadRate = loadedFirstByte ? stats.loaded * 1000 / timeStreaming : 0;
2120
2121
  // fragLoadDelay is an estimate of the time (in seconds) it will take to buffer the remainder of the fragment
2121
- var fragLoadedDelay = loadRate ? (expectedLen - stats.loaded) / loadRate : expectedLen * 8 / bwEstimate + ttfbEstimate / 1000;
2122
+ var ttfbSeconds = ttfbEstimate / 1000;
2123
+ var fragLoadedDelay = loadRate ? (expectedLen - stats.loaded) / loadRate : expectedLen * 8 / bwEstimate + ttfbSeconds;
2122
2124
  // Only downswitch if the time to finish loading the current fragment is greater than the amount of buffer left
2123
2125
  if (fragLoadedDelay <= bufferStarvationDelay) {
2124
2126
  return;
2125
2127
  }
2126
2128
  var bwe = loadRate ? loadRate * 8 : bwEstimate;
2129
+ var live = ((_this$hls$latestLevel = _this.hls.latestLevelDetails) == null ? void 0 : _this$hls$latestLevel.live) === true;
2130
+ var abrBandWidthUpFactor = _this.hls.config.abrBandWidthUpFactor;
2127
2131
  var fragLevelNextLoadedDelay = Number.POSITIVE_INFINITY;
2128
2132
  var nextLoadLevel;
2129
2133
  // Iterate through lower level and try to find the largest one that avoids rebuffering
@@ -2131,8 +2135,9 @@
2131
2135
  // compute time to load next fragment at lower level
2132
2136
  // 8 = bits per byte (bps/Bps)
2133
2137
  var levelNextBitrate = levels[nextLoadLevel].maxBitrate;
2134
- fragLevelNextLoadedDelay = _this.getTimeToLoadFrag(ttfbEstimate / 1000, bwe, duration * levelNextBitrate, !levels[nextLoadLevel].details);
2135
- if (fragLevelNextLoadedDelay < bufferStarvationDelay) {
2138
+ var requiresLevelLoad = !levels[nextLoadLevel].details || live;
2139
+ fragLevelNextLoadedDelay = _this.getTimeToLoadFrag(ttfbSeconds, bwe, duration * levelNextBitrate, requiresLevelLoad);
2140
+ if (fragLevelNextLoadedDelay < Math.min(bufferStarvationDelay, duration + ttfbSeconds)) {
2136
2141
  break;
2137
2142
  }
2138
2143
  }
@@ -2146,7 +2151,6 @@
2146
2151
  if (fragLevelNextLoadedDelay > duration * 10) {
2147
2152
  return;
2148
2153
  }
2149
- hls.nextLoadLevel = hls.nextAutoLevel = nextLoadLevel;
2150
2154
  if (loadedFirstByte) {
2151
2155
  // If there has been loading progress, sample bandwidth using loading time offset by minimum TTFB time
2152
2156
  _this.bwEstimator.sample(timeLoading - Math.min(ttfbEstimate, ttfb), stats.loaded);
@@ -2155,11 +2159,34 @@
2155
2159
  _this.bwEstimator.sampleTTFB(timeLoading);
2156
2160
  }
2157
2161
  var nextLoadLevelBitrate = levels[nextLoadLevel].maxBitrate;
2158
- if (_this.getBwEstimate() * _this.hls.config.abrBandWidthUpFactor > nextLoadLevelBitrate) {
2162
+ if (_this.getBwEstimate() * abrBandWidthUpFactor > nextLoadLevelBitrate) {
2159
2163
  _this.resetEstimator(nextLoadLevelBitrate);
2160
2164
  }
2165
+ var bestSwitchLevel = _this.findBestLevel(nextLoadLevelBitrate, minAutoLevel, nextLoadLevel, 0, bufferStarvationDelay, 1, 1);
2166
+ if (bestSwitchLevel > -1) {
2167
+ nextLoadLevel = bestSwitchLevel;
2168
+ }
2169
+ _this.warn("Fragment " + frag.sn + (part ? ' part ' + part.index : '') + " of level " + frag.level + " is loading too slowly;\n Fragment duration: " + frag.duration.toFixed(3) + "\n Time to underbuffer: " + bufferStarvationDelay.toFixed(3) + " s\n Estimated load time for current fragment: " + fragLoadedDelay.toFixed(3) + " s\n Estimated load time for down switch fragment: " + fragLevelNextLoadedDelay.toFixed(3) + " s\n TTFB estimate: " + (ttfb | 0) + " ms\n Current BW estimate: " + (isFiniteNumber(bwEstimate) ? bwEstimate | 0 : 'Unknown') + " bps\n New BW estimate: " + (_this.getBwEstimate() | 0) + " bps\n Switching to level " + nextLoadLevel + " @ " + (nextLoadLevelBitrate | 0) + " bps");
2170
+ hls.nextLoadLevel = hls.nextAutoLevel = nextLoadLevel;
2161
2171
  _this.clearTimer();
2162
- _this.warn("Fragment " + frag.sn + (part ? ' part ' + part.index : '') + " of level " + frag.level + " is loading too slowly;\n Time to underbuffer: " + bufferStarvationDelay.toFixed(3) + " s\n Estimated load time for current fragment: " + fragLoadedDelay.toFixed(3) + " s\n Estimated load time for down switch fragment: " + fragLevelNextLoadedDelay.toFixed(3) + " s\n TTFB estimate: " + (ttfb | 0) + " ms\n Current BW estimate: " + (isFiniteNumber(bwEstimate) ? bwEstimate | 0 : 'Unknown') + " bps\n New BW estimate: " + (_this.getBwEstimate() | 0) + " bps\n Switching to level " + nextLoadLevel + " @ " + (nextLoadLevelBitrate | 0) + " bps");
2172
+ _this.timer = self.setInterval(function () {
2173
+ // Are nextLoadLevel details available or is stream-controller still in "WAITING_LEVEL" state?
2174
+ _this.clearTimer();
2175
+ if (_this.fragCurrent === frag && _this.hls.loadLevel === nextLoadLevel && nextLoadLevel > 0) {
2176
+ var _bufferStarvationDelay = _this.getStarvationDelay();
2177
+ _this.warn("Aborting inflight request " + (nextLoadLevel > 0 ? 'and switching down' : '') + "\n Fragment duration: " + frag.duration.toFixed(3) + " s\n Time to underbuffer: " + _bufferStarvationDelay.toFixed(3) + " s");
2178
+ frag.abortRequests();
2179
+ _this.fragCurrent = _this.partCurrent = null;
2180
+ if (nextLoadLevel > minAutoLevel) {
2181
+ var lowestSwitchLevel = _this.findBestLevel(_this.hls.levels[minAutoLevel].bitrate, minAutoLevel, nextLoadLevel, 0, _bufferStarvationDelay, 1, 1);
2182
+ if (lowestSwitchLevel === -1) {
2183
+ lowestSwitchLevel = minAutoLevel;
2184
+ }
2185
+ _this.hls.nextLoadLevel = _this.hls.nextAutoLevel = lowestSwitchLevel;
2186
+ _this.resetEstimator(_this.hls.levels[lowestSwitchLevel].bitrate);
2187
+ }
2188
+ }
2189
+ }, fragLevelNextLoadedDelay * 1000);
2163
2190
  hls.trigger(Events.FRAG_LOAD_EMERGENCY_ABORTED, {
2164
2191
  frag: frag,
2165
2192
  part: part,
@@ -2458,7 +2485,7 @@
2458
2485
  return this.bwEstimator.canEstimate() ? this.bwEstimator.getEstimate() : this.hls.config.abrEwmaDefaultEstimate;
2459
2486
  };
2460
2487
  _proto.findBestLevel = function findBestLevel(currentBw, minAutoLevel, maxAutoLevel, bufferStarvationDelay, maxStarvationDelay, bwFactor, bwUpFactor) {
2461
- var _level$details,
2488
+ var _this$hls$latestLevel2,
2462
2489
  _this3 = this;
2463
2490
  var maxFetchDuration = bufferStarvationDelay + maxStarvationDelay;
2464
2491
  var lastLoadedFragLevel = this.lastLoadedFragLevel;
@@ -2474,7 +2501,7 @@
2474
2501
  return 0;
2475
2502
  }
2476
2503
  var level = levels[selectionBaseLevel];
2477
- var live = !!(level != null && (_level$details = level.details) != null && _level$details.live);
2504
+ var live = !!((_this$hls$latestLevel2 = this.hls.latestLevelDetails) != null && _this$hls$latestLevel2.live);
2478
2505
  var firstSelection = loadLevel === -1 || lastLoadedFragLevel === -1;
2479
2506
  var currentCodecSet;
2480
2507
  var currentVideoRange = 'SDR';
@@ -16059,7 +16086,7 @@
16059
16086
  return !remuxResult.audio && !remuxResult.video && !remuxResult.text && !remuxResult.id3 && !remuxResult.initSegment;
16060
16087
  }
16061
16088
 
16062
- var version = "1.6.0-beta.1.0.canary.10714";
16089
+ var version = "1.6.0-beta.1.0.canary.10717";
16063
16090
 
16064
16091
  // ensure the worker ends up in the bundle
16065
16092
  // If the worker should not be included this gets aliased to empty.js
@@ -31012,7 +31039,10 @@
31012
31039
  return;
31013
31040
  }
31014
31041
  if (data.context.type === PlaylistContextType.LEVEL && data.context.level === this.level) {
31015
- this.checkRetry(data);
31042
+ var retry = this.checkRetry(data);
31043
+ if (!retry) {
31044
+ this.requestScheduled = -1;
31045
+ }
31016
31046
  }
31017
31047
  }
31018
31048
 
@@ -31187,8 +31217,10 @@
31187
31217
  var pathwayId = level.attrs['PATHWAY-ID'];
31188
31218
  this.currentLevelIndex = newLevel;
31189
31219
  this.currentLevel = level;
31190
- if (lastLevelIndex === newLevel && level.details && lastLevel && lastPathwayId === pathwayId) {
31191
- return;
31220
+ if (lastLevelIndex === newLevel && lastLevel && lastPathwayId === pathwayId) {
31221
+ if (level.details || this.requestScheduled !== -1) {
31222
+ return;
31223
+ }
31192
31224
  }
31193
31225
  this.log("Switching to level " + newLevel + " (" + (level.height ? level.height + 'p ' : '') + (level.videoRange ? level.videoRange + ' ' : '') + (level.codecSet ? level.codecSet + ' ' : '') + "@" + level.bitrate + ")" + (pathwayId ? ' with Pathway ' + pathwayId : '') + " from level " + lastLevelIndex + (lastPathwayId ? ' with Pathway ' + lastPathwayId : ''));
31194
31226
  var levelSwitchingData = {