hls.js 1.5.17 → 1.5.18

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.
@@ -411,7 +411,7 @@ function enableLogs(debugConfig, id) {
411
411
  // Some browsers don't allow to use bind on console object anyway
412
412
  // fallback to default if needed
413
413
  try {
414
- exportedLogger.log(`Debug logs enabled for "${id}" in hls.js version ${"1.5.17"}`);
414
+ exportedLogger.log(`Debug logs enabled for "${id}" in hls.js version ${"1.5.18"}`);
415
415
  } catch (e) {
416
416
  exportedLogger = fakeLogger;
417
417
  }
@@ -7220,6 +7220,7 @@ class BufferController {
7220
7220
  this.resetBuffer(type);
7221
7221
  });
7222
7222
  this._initSourceBuffer();
7223
+ this.hls.resumeBuffering();
7223
7224
  }
7224
7225
  resetBuffer(type) {
7225
7226
  const sb = this.sourceBuffer[type];
@@ -8857,47 +8858,51 @@ class XhrLoader {
8857
8858
  xhr.onprogress = null;
8858
8859
  const status = xhr.status;
8859
8860
  // http status between 200 to 299 are all successful
8860
- const useResponse = xhr.responseType !== 'text';
8861
- if (status >= 200 && status < 300 && (useResponse && xhr.response || xhr.responseText !== null)) {
8862
- stats.loading.end = Math.max(self.performance.now(), stats.loading.first);
8863
- const data = useResponse ? xhr.response : xhr.responseText;
8864
- const len = xhr.responseType === 'arraybuffer' ? data.byteLength : data.length;
8865
- stats.loaded = stats.total = len;
8866
- stats.bwEstimate = stats.total * 8000 / (stats.loading.end - stats.loading.first);
8867
- if (!this.callbacks) {
8868
- return;
8869
- }
8870
- const onProgress = this.callbacks.onProgress;
8871
- if (onProgress) {
8872
- onProgress(stats, context, data, xhr);
8873
- }
8874
- if (!this.callbacks) {
8861
+ const useResponseText = xhr.responseType === 'text' ? xhr.responseText : null;
8862
+ if (status >= 200 && status < 300) {
8863
+ const data = useResponseText != null ? useResponseText : xhr.response;
8864
+ if (data != null) {
8865
+ stats.loading.end = Math.max(self.performance.now(), stats.loading.first);
8866
+ const len = xhr.responseType === 'arraybuffer' ? data.byteLength : data.length;
8867
+ stats.loaded = stats.total = len;
8868
+ stats.bwEstimate = stats.total * 8000 / (stats.loading.end - stats.loading.first);
8869
+ if (!this.callbacks) {
8870
+ return;
8871
+ }
8872
+ const onProgress = this.callbacks.onProgress;
8873
+ if (onProgress) {
8874
+ onProgress(stats, context, data, xhr);
8875
+ }
8876
+ if (!this.callbacks) {
8877
+ return;
8878
+ }
8879
+ const _response = {
8880
+ url: xhr.responseURL,
8881
+ data: data,
8882
+ code: status
8883
+ };
8884
+ this.callbacks.onSuccess(_response, stats, context, xhr);
8875
8885
  return;
8876
8886
  }
8877
- const response = {
8878
- url: xhr.responseURL,
8879
- data: data,
8880
- code: status
8881
- };
8882
- this.callbacks.onSuccess(response, stats, context, xhr);
8887
+ }
8888
+
8889
+ // Handle bad status or nullish response
8890
+ const retryConfig = config.loadPolicy.errorRetry;
8891
+ const retryCount = stats.retry;
8892
+ // if max nb of retries reached or if http status between 400 and 499 (such error cannot be recovered, retrying is useless), return error
8893
+ const response = {
8894
+ url: context.url,
8895
+ data: undefined,
8896
+ code: status
8897
+ };
8898
+ if (shouldRetry(retryConfig, retryCount, false, response)) {
8899
+ this.retry(retryConfig);
8883
8900
  } else {
8884
- const retryConfig = config.loadPolicy.errorRetry;
8885
- const retryCount = stats.retry;
8886
- // if max nb of retries reached or if http status between 400 and 499 (such error cannot be recovered, retrying is useless), return error
8887
- const response = {
8888
- url: context.url,
8889
- data: undefined,
8890
- code: status
8891
- };
8892
- if (shouldRetry(retryConfig, retryCount, false, response)) {
8893
- this.retry(retryConfig);
8894
- } else {
8895
- logger.error(`${status} while loading ${context.url}`);
8896
- this.callbacks.onError({
8897
- code: status,
8898
- text: xhr.statusText
8899
- }, context, xhr, stats);
8900
- }
8901
+ logger.error(`${status} while loading ${context.url}`);
8902
+ this.callbacks.onError({
8903
+ code: status,
8904
+ text: xhr.statusText
8905
+ }, context, xhr, stats);
8901
8906
  }
8902
8907
  }
8903
8908
  }
@@ -11899,6 +11904,7 @@ class BaseStreamController extends TaskLoop {
11899
11904
  this.startFragRequested = false;
11900
11905
  this.decrypter = void 0;
11901
11906
  this.initPTS = [];
11907
+ this.buffering = true;
11902
11908
  this.onvseeking = null;
11903
11909
  this.onvended = null;
11904
11910
  this.logPrefix = '';
@@ -11938,6 +11944,12 @@ class BaseStreamController extends TaskLoop {
11938
11944
  this.clearNextTick();
11939
11945
  this.state = State.STOPPED;
11940
11946
  }
11947
+ pauseBuffering() {
11948
+ this.buffering = false;
11949
+ }
11950
+ resumeBuffering() {
11951
+ this.buffering = true;
11952
+ }
11941
11953
  _streamEnded(bufferInfo, levelDetails) {
11942
11954
  // If playlist is live, there is another buffered range after the current range, nothing buffered, media is detached,
11943
11955
  // of nothing loading/loaded return false
@@ -16187,19 +16199,23 @@ class MP4Remuxer {
16187
16199
  this.videoTrackConfig = undefined;
16188
16200
  }
16189
16201
  getVideoStartPts(videoSamples) {
16202
+ // Get the minimum PTS value relative to the first sample's PTS, normalized for 33-bit wrapping
16190
16203
  let rolloverDetected = false;
16204
+ const firstPts = videoSamples[0].pts;
16191
16205
  const startPTS = videoSamples.reduce((minPTS, sample) => {
16192
- const delta = sample.pts - minPTS;
16206
+ let pts = sample.pts;
16207
+ let delta = pts - minPTS;
16193
16208
  if (delta < -4294967296) {
16194
16209
  // 2^32, see PTSNormalize for reasoning, but we're hitting a rollover here, and we don't want that to impact the timeOffset calculation
16195
16210
  rolloverDetected = true;
16196
- return normalizePts(minPTS, sample.pts);
16197
- } else if (delta > 0) {
16211
+ pts = normalizePts(pts, firstPts);
16212
+ delta = pts - minPTS;
16213
+ }
16214
+ if (delta > 0) {
16198
16215
  return minPTS;
16199
- } else {
16200
- return sample.pts;
16201
16216
  }
16202
- }, videoSamples[0].pts);
16217
+ return pts;
16218
+ }, firstPts);
16203
16219
  if (rolloverDetected) {
16204
16220
  logger.debug('PTS rollover detected');
16205
16221
  }
@@ -18745,7 +18761,7 @@ class StreamController extends BaseStreamController {
18745
18761
  if (this.altAudio && this.audioOnly) {
18746
18762
  return;
18747
18763
  }
18748
- const level = hls.nextLoadLevel;
18764
+ const level = this.buffering ? hls.nextLoadLevel : hls.loadLevel;
18749
18765
  if (!(levels != null && levels[level])) {
18750
18766
  return;
18751
18767
  }
@@ -18767,6 +18783,9 @@ class StreamController extends BaseStreamController {
18767
18783
  this.state = State.ENDED;
18768
18784
  return;
18769
18785
  }
18786
+ if (!this.buffering) {
18787
+ return;
18788
+ }
18770
18789
 
18771
18790
  // set next load level : this will trigger a playlist load if needed
18772
18791
  if (hls.loadLevel !== level && hls.manualLevel === -1) {
@@ -19729,7 +19748,7 @@ class Hls {
19729
19748
  * Get the video-dev/hls.js package version.
19730
19749
  */
19731
19750
  static get version() {
19732
- return "1.5.17";
19751
+ return "1.5.18";
19733
19752
  }
19734
19753
 
19735
19754
  /**
@@ -20010,9 +20029,13 @@ class Hls {
20010
20029
  startLoad(startPosition = -1) {
20011
20030
  logger.log(`startLoad(${startPosition})`);
20012
20031
  this.started = true;
20013
- this.networkControllers.forEach(controller => {
20014
- controller.startLoad(startPosition);
20015
- });
20032
+ this.resumeBuffering();
20033
+ for (let i = 0; i < this.networkControllers.length; i++) {
20034
+ this.networkControllers[i].startLoad(startPosition);
20035
+ if (!this.started || !this.networkControllers) {
20036
+ break;
20037
+ }
20038
+ }
20016
20039
  }
20017
20040
 
20018
20041
  /**
@@ -20021,32 +20044,35 @@ class Hls {
20021
20044
  stopLoad() {
20022
20045
  logger.log('stopLoad');
20023
20046
  this.started = false;
20024
- this.networkControllers.forEach(controller => {
20025
- controller.stopLoad();
20026
- });
20047
+ for (let i = 0; i < this.networkControllers.length; i++) {
20048
+ this.networkControllers[i].stopLoad();
20049
+ if (this.started || !this.networkControllers) {
20050
+ break;
20051
+ }
20052
+ }
20027
20053
  }
20028
20054
 
20029
20055
  /**
20030
- * Resumes stream controller segment loading if previously started.
20056
+ * Resumes stream controller segment loading after `pauseBuffering` has been called.
20031
20057
  */
20032
20058
  resumeBuffering() {
20033
- if (this.started) {
20034
- this.networkControllers.forEach(controller => {
20035
- if ('fragmentLoader' in controller) {
20036
- controller.startLoad(-1);
20037
- }
20038
- });
20039
- }
20059
+ logger.log(`resume buffering`);
20060
+ this.networkControllers.forEach(controller => {
20061
+ if (controller.resumeBuffering) {
20062
+ controller.resumeBuffering();
20063
+ }
20064
+ });
20040
20065
  }
20041
20066
 
20042
20067
  /**
20043
- * Stops stream controller segment loading without changing 'started' state like stopLoad().
20068
+ * Prevents stream controller from loading new segments until `resumeBuffering` is called.
20044
20069
  * This allows for media buffering to be paused without interupting playlist loading.
20045
20070
  */
20046
20071
  pauseBuffering() {
20072
+ logger.log(`pause buffering`);
20047
20073
  this.networkControllers.forEach(controller => {
20048
- if ('fragmentLoader' in controller) {
20049
- controller.stopLoad();
20074
+ if (controller.pauseBuffering) {
20075
+ controller.pauseBuffering();
20050
20076
  }
20051
20077
  });
20052
20078
  }