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.light.js CHANGED
@@ -1025,7 +1025,7 @@
1025
1025
  // Some browsers don't allow to use bind on console object anyway
1026
1026
  // fallback to default if needed
1027
1027
  try {
1028
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.0-beta.1.0.canary.10714");
1028
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.6.0-beta.1.0.canary.10717");
1029
1029
  } catch (e) {
1030
1030
  /* log fn threw an exception. All logger methods are no-ops. */
1031
1031
  return createLogger();
@@ -1769,6 +1769,7 @@
1769
1769
  quickly enough to prevent underbuffering
1770
1770
  */
1771
1771
  _this._abandonRulesCheck = function () {
1772
+ var _this$hls$latestLevel;
1772
1773
  var _this2 = _this,
1773
1774
  frag = _this2.fragCurrent,
1774
1775
  part = _this2.partCurrent,
@@ -1820,12 +1821,15 @@
1820
1821
  }
1821
1822
  var loadRate = loadedFirstByte ? stats.loaded * 1000 / timeStreaming : 0;
1822
1823
  // fragLoadDelay is an estimate of the time (in seconds) it will take to buffer the remainder of the fragment
1823
- var fragLoadedDelay = loadRate ? (expectedLen - stats.loaded) / loadRate : expectedLen * 8 / bwEstimate + ttfbEstimate / 1000;
1824
+ var ttfbSeconds = ttfbEstimate / 1000;
1825
+ var fragLoadedDelay = loadRate ? (expectedLen - stats.loaded) / loadRate : expectedLen * 8 / bwEstimate + ttfbSeconds;
1824
1826
  // Only downswitch if the time to finish loading the current fragment is greater than the amount of buffer left
1825
1827
  if (fragLoadedDelay <= bufferStarvationDelay) {
1826
1828
  return;
1827
1829
  }
1828
1830
  var bwe = loadRate ? loadRate * 8 : bwEstimate;
1831
+ var live = ((_this$hls$latestLevel = _this.hls.latestLevelDetails) == null ? void 0 : _this$hls$latestLevel.live) === true;
1832
+ var abrBandWidthUpFactor = _this.hls.config.abrBandWidthUpFactor;
1829
1833
  var fragLevelNextLoadedDelay = Number.POSITIVE_INFINITY;
1830
1834
  var nextLoadLevel;
1831
1835
  // Iterate through lower level and try to find the largest one that avoids rebuffering
@@ -1833,8 +1837,9 @@
1833
1837
  // compute time to load next fragment at lower level
1834
1838
  // 8 = bits per byte (bps/Bps)
1835
1839
  var levelNextBitrate = levels[nextLoadLevel].maxBitrate;
1836
- fragLevelNextLoadedDelay = _this.getTimeToLoadFrag(ttfbEstimate / 1000, bwe, duration * levelNextBitrate, !levels[nextLoadLevel].details);
1837
- if (fragLevelNextLoadedDelay < bufferStarvationDelay) {
1840
+ var requiresLevelLoad = !levels[nextLoadLevel].details || live;
1841
+ fragLevelNextLoadedDelay = _this.getTimeToLoadFrag(ttfbSeconds, bwe, duration * levelNextBitrate, requiresLevelLoad);
1842
+ if (fragLevelNextLoadedDelay < Math.min(bufferStarvationDelay, duration + ttfbSeconds)) {
1838
1843
  break;
1839
1844
  }
1840
1845
  }
@@ -1848,7 +1853,6 @@
1848
1853
  if (fragLevelNextLoadedDelay > duration * 10) {
1849
1854
  return;
1850
1855
  }
1851
- hls.nextLoadLevel = hls.nextAutoLevel = nextLoadLevel;
1852
1856
  if (loadedFirstByte) {
1853
1857
  // If there has been loading progress, sample bandwidth using loading time offset by minimum TTFB time
1854
1858
  _this.bwEstimator.sample(timeLoading - Math.min(ttfbEstimate, ttfb), stats.loaded);
@@ -1857,11 +1861,34 @@
1857
1861
  _this.bwEstimator.sampleTTFB(timeLoading);
1858
1862
  }
1859
1863
  var nextLoadLevelBitrate = levels[nextLoadLevel].maxBitrate;
1860
- if (_this.getBwEstimate() * _this.hls.config.abrBandWidthUpFactor > nextLoadLevelBitrate) {
1864
+ if (_this.getBwEstimate() * abrBandWidthUpFactor > nextLoadLevelBitrate) {
1861
1865
  _this.resetEstimator(nextLoadLevelBitrate);
1862
1866
  }
1867
+ var bestSwitchLevel = _this.findBestLevel(nextLoadLevelBitrate, minAutoLevel, nextLoadLevel, 0, bufferStarvationDelay, 1, 1);
1868
+ if (bestSwitchLevel > -1) {
1869
+ nextLoadLevel = bestSwitchLevel;
1870
+ }
1871
+ _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");
1872
+ hls.nextLoadLevel = hls.nextAutoLevel = nextLoadLevel;
1863
1873
  _this.clearTimer();
1864
- _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");
1874
+ _this.timer = self.setInterval(function () {
1875
+ // Are nextLoadLevel details available or is stream-controller still in "WAITING_LEVEL" state?
1876
+ _this.clearTimer();
1877
+ if (_this.fragCurrent === frag && _this.hls.loadLevel === nextLoadLevel && nextLoadLevel > 0) {
1878
+ var _bufferStarvationDelay = _this.getStarvationDelay();
1879
+ _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");
1880
+ frag.abortRequests();
1881
+ _this.fragCurrent = _this.partCurrent = null;
1882
+ if (nextLoadLevel > minAutoLevel) {
1883
+ var lowestSwitchLevel = _this.findBestLevel(_this.hls.levels[minAutoLevel].bitrate, minAutoLevel, nextLoadLevel, 0, _bufferStarvationDelay, 1, 1);
1884
+ if (lowestSwitchLevel === -1) {
1885
+ lowestSwitchLevel = minAutoLevel;
1886
+ }
1887
+ _this.hls.nextLoadLevel = _this.hls.nextAutoLevel = lowestSwitchLevel;
1888
+ _this.resetEstimator(_this.hls.levels[lowestSwitchLevel].bitrate);
1889
+ }
1890
+ }
1891
+ }, fragLevelNextLoadedDelay * 1000);
1865
1892
  hls.trigger(Events.FRAG_LOAD_EMERGENCY_ABORTED, {
1866
1893
  frag: frag,
1867
1894
  part: part,
@@ -2160,7 +2187,7 @@
2160
2187
  return this.bwEstimator.canEstimate() ? this.bwEstimator.getEstimate() : this.hls.config.abrEwmaDefaultEstimate;
2161
2188
  };
2162
2189
  _proto.findBestLevel = function findBestLevel(currentBw, minAutoLevel, maxAutoLevel, bufferStarvationDelay, maxStarvationDelay, bwFactor, bwUpFactor) {
2163
- var _level$details,
2190
+ var _this$hls$latestLevel2,
2164
2191
  _this3 = this;
2165
2192
  var maxFetchDuration = bufferStarvationDelay + maxStarvationDelay;
2166
2193
  var lastLoadedFragLevel = this.lastLoadedFragLevel;
@@ -2176,7 +2203,7 @@
2176
2203
  return 0;
2177
2204
  }
2178
2205
  var level = levels[selectionBaseLevel];
2179
- var live = !!(level != null && (_level$details = level.details) != null && _level$details.live);
2206
+ var live = !!((_this$hls$latestLevel2 = this.hls.latestLevelDetails) != null && _this$hls$latestLevel2.live);
2180
2207
  var firstSelection = loadLevel === -1 || lastLoadedFragLevel === -1;
2181
2208
  var currentCodecSet;
2182
2209
  var currentVideoRange = 'SDR';
@@ -16692,7 +16719,10 @@
16692
16719
  return;
16693
16720
  }
16694
16721
  if (data.context.type === PlaylistContextType.LEVEL && data.context.level === this.level) {
16695
- this.checkRetry(data);
16722
+ var retry = this.checkRetry(data);
16723
+ if (!retry) {
16724
+ this.requestScheduled = -1;
16725
+ }
16696
16726
  }
16697
16727
  }
16698
16728
 
@@ -16867,8 +16897,10 @@
16867
16897
  var pathwayId = level.attrs['PATHWAY-ID'];
16868
16898
  this.currentLevelIndex = newLevel;
16869
16899
  this.currentLevel = level;
16870
- if (lastLevelIndex === newLevel && level.details && lastLevel && lastPathwayId === pathwayId) {
16871
- return;
16900
+ if (lastLevelIndex === newLevel && lastLevel && lastPathwayId === pathwayId) {
16901
+ if (level.details || this.requestScheduled !== -1) {
16902
+ return;
16903
+ }
16872
16904
  }
16873
16905
  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 : ''));
16874
16906
  var levelSwitchingData = {
@@ -19522,7 +19554,7 @@
19522
19554
  return !remuxResult.audio && !remuxResult.video && !remuxResult.text && !remuxResult.id3 && !remuxResult.initSegment;
19523
19555
  }
19524
19556
 
19525
- var version = "1.6.0-beta.1.0.canary.10714";
19557
+ var version = "1.6.0-beta.1.0.canary.10717";
19526
19558
 
19527
19559
  // ensure the worker ends up in the bundle
19528
19560
  // If the worker should not be included this gets aliased to empty.js