hls.js 1.5.12-0.canary.10397 → 1.5.12-0.canary.10399

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.mjs CHANGED
@@ -420,7 +420,7 @@ function enableLogs(debugConfig, context, id) {
420
420
  // Some browsers don't allow to use bind on console object anyway
421
421
  // fallback to default if needed
422
422
  try {
423
- newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.5.12-0.canary.10397"}`);
423
+ newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.5.12-0.canary.10399"}`);
424
424
  } catch (e) {
425
425
  /* log fn threw an exception. All logger methods are no-ops. */
426
426
  return createLogger();
@@ -5116,6 +5116,7 @@ class LatencyController {
5116
5116
  this.currentTime = 0;
5117
5117
  this.stallCount = 0;
5118
5118
  this._latency = null;
5119
+ this._targetLatencyUpdated = false;
5119
5120
  this.onTimeupdate = () => {
5120
5121
  const {
5121
5122
  media,
@@ -5193,12 +5194,17 @@ class LatencyController {
5193
5194
  } = this.config;
5194
5195
  const userConfig = this.hls.userConfig;
5195
5196
  let targetLatency = lowLatencyMode ? partHoldBack || holdBack : holdBack;
5196
- if (userConfig.liveSyncDuration || userConfig.liveSyncDurationCount || targetLatency === 0) {
5197
+ if (this._targetLatencyUpdated || userConfig.liveSyncDuration || userConfig.liveSyncDurationCount || targetLatency === 0) {
5197
5198
  targetLatency = liveSyncDuration !== undefined ? liveSyncDuration : liveSyncDurationCount * targetduration;
5198
5199
  }
5199
5200
  const maxLiveSyncOnStallIncrease = targetduration;
5200
5201
  return targetLatency + Math.min(this.stallCount * this.config.liveSyncOnStallIncrease, maxLiveSyncOnStallIncrease);
5201
5202
  }
5203
+ set targetLatency(latency) {
5204
+ this.stallCount = 0;
5205
+ this.config.liveSyncDuration = latency;
5206
+ this._targetLatencyUpdated = true;
5207
+ }
5202
5208
  get liveSyncPosition() {
5203
5209
  const liveEdge = this.estimateLiveEdge();
5204
5210
  const targetLatency = this.targetLatency;
@@ -9909,7 +9915,7 @@ class BaseStreamController extends TaskLoop {
9909
9915
  // If backtracking, always remove from the tracker without reducing max buffer length
9910
9916
  const backtrackFragment = this.backtrackFragment;
9911
9917
  const backtracked = backtrackFragment ? frag.sn - backtrackFragment.sn : 0;
9912
- if (backtracked === 1 || this.reduceMaxBufferLength(minForwardBufferLength)) {
9918
+ if (backtracked === 1 || this.reduceMaxBufferLength(minForwardBufferLength, frag.duration)) {
9913
9919
  fragmentTracker.removeFragment(frag);
9914
9920
  }
9915
9921
  } else if (((_this$mediaBuffer = this.mediaBuffer) == null ? void 0 : _this$mediaBuffer.buffered.length) === 0) {
@@ -10410,10 +10416,10 @@ class BaseStreamController extends TaskLoop {
10410
10416
  }
10411
10417
  return Math.min(maxBufLen, config.maxMaxBufferLength);
10412
10418
  }
10413
- reduceMaxBufferLength(threshold) {
10419
+ reduceMaxBufferLength(threshold, fragDuration) {
10414
10420
  const config = this.config;
10415
- const minLength = threshold || config.maxBufferLength;
10416
- const reducedLength = config.maxMaxBufferLength / 2;
10421
+ const minLength = Math.max(Math.min(threshold, config.maxBufferLength), fragDuration);
10422
+ const reducedLength = Math.max(threshold - fragDuration * 3, config.maxMaxBufferLength / 2);
10417
10423
  if (reducedLength >= minLength) {
10418
10424
  // reduce max buffer length as it might be too high. we do this to avoid loop flushing ...
10419
10425
  config.maxMaxBufferLength = reducedLength;
@@ -10803,13 +10809,14 @@ class BaseStreamController extends TaskLoop {
10803
10809
  reduceLengthAndFlushBuffer(data) {
10804
10810
  // if in appending state
10805
10811
  if (this.state === State.PARSING || this.state === State.PARSED) {
10812
+ const frag = data.frag;
10806
10813
  const playlistType = data.parent;
10807
10814
  const bufferedInfo = this.getFwdBufferInfo(this.mediaBuffer, playlistType);
10808
10815
  // 0.5 : tolerance needed as some browsers stalls playback before reaching buffered end
10809
10816
  // reduce max buf len if current position is buffered
10810
10817
  const buffered = bufferedInfo && bufferedInfo.len > 0.5;
10811
10818
  if (buffered) {
10812
- this.reduceMaxBufferLength(bufferedInfo.len);
10819
+ this.reduceMaxBufferLength(bufferedInfo.len, (frag == null ? void 0 : frag.duration) || 10);
10813
10820
  }
10814
10821
  const flushBuffer = !buffered;
10815
10822
  if (flushBuffer) {
@@ -10818,9 +10825,9 @@ class BaseStreamController extends TaskLoop {
10818
10825
  // in that case flush the whole audio buffer to recover
10819
10826
  this.warn(`Buffer full error while media.currentTime is not buffered, flush ${playlistType} buffer`);
10820
10827
  }
10821
- if (data.frag) {
10822
- this.fragmentTracker.removeFragment(data.frag);
10823
- this.nextLoadPosition = data.frag.start;
10828
+ if (frag) {
10829
+ this.fragmentTracker.removeFragment(frag);
10830
+ this.nextLoadPosition = frag.start;
10824
10831
  }
10825
10832
  this.resetLoadingState();
10826
10833
  return flushBuffer;
@@ -29273,7 +29280,7 @@ class Hls {
29273
29280
  * Get the video-dev/hls.js package version.
29274
29281
  */
29275
29282
  static get version() {
29276
- return "1.5.12-0.canary.10397";
29283
+ return "1.5.12-0.canary.10399";
29277
29284
  }
29278
29285
 
29279
29286
  /**
@@ -30068,6 +30075,9 @@ class Hls {
30068
30075
  get targetLatency() {
30069
30076
  return this.latencyController.targetLatency;
30070
30077
  }
30078
+ set targetLatency(latency) {
30079
+ this.latencyController.targetLatency = latency;
30080
+ }
30071
30081
 
30072
30082
  /**
30073
30083
  * the rate at which the edge of the current live playlist is advancing or 1 if there is none