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.
package/dist/hls.light.js CHANGED
@@ -521,7 +521,7 @@
521
521
  // Some browsers don't allow to use bind on console object anyway
522
522
  // fallback to default if needed
523
523
  try {
524
- exportedLogger.log("Debug logs enabled for \"" + id + "\" in hls.js version " + "1.5.17");
524
+ exportedLogger.log("Debug logs enabled for \"" + id + "\" in hls.js version " + "1.5.18");
525
525
  } catch (e) {
526
526
  exportedLogger = fakeLogger;
527
527
  }
@@ -7503,6 +7503,7 @@
7503
7503
  _this2.resetBuffer(type);
7504
7504
  });
7505
7505
  this._initSourceBuffer();
7506
+ this.hls.resumeBuffering();
7506
7507
  };
7507
7508
  _proto.resetBuffer = function resetBuffer(type) {
7508
7509
  var sb = this.sourceBuffer[type];
@@ -9145,47 +9146,51 @@
9145
9146
  xhr.onprogress = null;
9146
9147
  var _status = xhr.status;
9147
9148
  // http status between 200 to 299 are all successful
9148
- var useResponse = xhr.responseType !== 'text';
9149
- if (_status >= 200 && _status < 300 && (useResponse && xhr.response || xhr.responseText !== null)) {
9150
- stats.loading.end = Math.max(self.performance.now(), stats.loading.first);
9151
- var data = useResponse ? xhr.response : xhr.responseText;
9152
- var len = xhr.responseType === 'arraybuffer' ? data.byteLength : data.length;
9153
- stats.loaded = stats.total = len;
9154
- stats.bwEstimate = stats.total * 8000 / (stats.loading.end - stats.loading.first);
9155
- if (!this.callbacks) {
9156
- return;
9157
- }
9158
- var onProgress = this.callbacks.onProgress;
9159
- if (onProgress) {
9160
- onProgress(stats, context, data, xhr);
9161
- }
9162
- if (!this.callbacks) {
9149
+ var useResponseText = xhr.responseType === 'text' ? xhr.responseText : null;
9150
+ if (_status >= 200 && _status < 300) {
9151
+ var data = useResponseText != null ? useResponseText : xhr.response;
9152
+ if (data != null) {
9153
+ stats.loading.end = Math.max(self.performance.now(), stats.loading.first);
9154
+ var len = xhr.responseType === 'arraybuffer' ? data.byteLength : data.length;
9155
+ stats.loaded = stats.total = len;
9156
+ stats.bwEstimate = stats.total * 8000 / (stats.loading.end - stats.loading.first);
9157
+ if (!this.callbacks) {
9158
+ return;
9159
+ }
9160
+ var onProgress = this.callbacks.onProgress;
9161
+ if (onProgress) {
9162
+ onProgress(stats, context, data, xhr);
9163
+ }
9164
+ if (!this.callbacks) {
9165
+ return;
9166
+ }
9167
+ var _response = {
9168
+ url: xhr.responseURL,
9169
+ data: data,
9170
+ code: _status
9171
+ };
9172
+ this.callbacks.onSuccess(_response, stats, context, xhr);
9163
9173
  return;
9164
9174
  }
9165
- var response = {
9166
- url: xhr.responseURL,
9167
- data: data,
9168
- code: _status
9169
- };
9170
- this.callbacks.onSuccess(response, stats, context, xhr);
9175
+ }
9176
+
9177
+ // Handle bad status or nullish response
9178
+ var retryConfig = config.loadPolicy.errorRetry;
9179
+ var retryCount = stats.retry;
9180
+ // if max nb of retries reached or if http status between 400 and 499 (such error cannot be recovered, retrying is useless), return error
9181
+ var response = {
9182
+ url: context.url,
9183
+ data: undefined,
9184
+ code: _status
9185
+ };
9186
+ if (shouldRetry(retryConfig, retryCount, false, response)) {
9187
+ this.retry(retryConfig);
9171
9188
  } else {
9172
- var retryConfig = config.loadPolicy.errorRetry;
9173
- var retryCount = stats.retry;
9174
- // if max nb of retries reached or if http status between 400 and 499 (such error cannot be recovered, retrying is useless), return error
9175
- var _response = {
9176
- url: context.url,
9177
- data: undefined,
9178
- code: _status
9179
- };
9180
- if (shouldRetry(retryConfig, retryCount, false, _response)) {
9181
- this.retry(retryConfig);
9182
- } else {
9183
- logger.error(_status + " while loading " + context.url);
9184
- this.callbacks.onError({
9185
- code: _status,
9186
- text: xhr.statusText
9187
- }, context, xhr, stats);
9188
- }
9189
+ logger.error(_status + " while loading " + context.url);
9190
+ this.callbacks.onError({
9191
+ code: _status,
9192
+ text: xhr.statusText
9193
+ }, context, xhr, stats);
9189
9194
  }
9190
9195
  }
9191
9196
  }
@@ -12238,6 +12243,7 @@
12238
12243
  _this.startFragRequested = false;
12239
12244
  _this.decrypter = void 0;
12240
12245
  _this.initPTS = [];
12246
+ _this.buffering = true;
12241
12247
  _this.onvseeking = null;
12242
12248
  _this.onvended = null;
12243
12249
  _this.logPrefix = '';
@@ -12280,6 +12286,12 @@
12280
12286
  this.clearNextTick();
12281
12287
  this.state = State.STOPPED;
12282
12288
  };
12289
+ _proto.pauseBuffering = function pauseBuffering() {
12290
+ this.buffering = false;
12291
+ };
12292
+ _proto.resumeBuffering = function resumeBuffering() {
12293
+ this.buffering = true;
12294
+ };
12283
12295
  _proto._streamEnded = function _streamEnded(bufferInfo, levelDetails) {
12284
12296
  // If playlist is live, there is another buffered range after the current range, nothing buffered, media is detached,
12285
12297
  // of nothing loading/loaded return false
@@ -16548,19 +16560,23 @@
16548
16560
  this.videoTrackConfig = undefined;
16549
16561
  };
16550
16562
  _proto.getVideoStartPts = function getVideoStartPts(videoSamples) {
16563
+ // Get the minimum PTS value relative to the first sample's PTS, normalized for 33-bit wrapping
16551
16564
  var rolloverDetected = false;
16565
+ var firstPts = videoSamples[0].pts;
16552
16566
  var startPTS = videoSamples.reduce(function (minPTS, sample) {
16553
- var delta = sample.pts - minPTS;
16567
+ var pts = sample.pts;
16568
+ var delta = pts - minPTS;
16554
16569
  if (delta < -4294967296) {
16555
16570
  // 2^32, see PTSNormalize for reasoning, but we're hitting a rollover here, and we don't want that to impact the timeOffset calculation
16556
16571
  rolloverDetected = true;
16557
- return normalizePts(minPTS, sample.pts);
16558
- } else if (delta > 0) {
16572
+ pts = normalizePts(pts, firstPts);
16573
+ delta = pts - minPTS;
16574
+ }
16575
+ if (delta > 0) {
16559
16576
  return minPTS;
16560
- } else {
16561
- return sample.pts;
16562
16577
  }
16563
- }, videoSamples[0].pts);
16578
+ return pts;
16579
+ }, firstPts);
16564
16580
  if (rolloverDetected) {
16565
16581
  logger.debug('PTS rollover detected');
16566
16582
  }
@@ -19241,7 +19257,7 @@
19241
19257
  if (this.altAudio && this.audioOnly) {
19242
19258
  return;
19243
19259
  }
19244
- var level = hls.nextLoadLevel;
19260
+ var level = this.buffering ? hls.nextLoadLevel : hls.loadLevel;
19245
19261
  if (!(levels != null && levels[level])) {
19246
19262
  return;
19247
19263
  }
@@ -19263,6 +19279,9 @@
19263
19279
  this.state = State.ENDED;
19264
19280
  return;
19265
19281
  }
19282
+ if (!this.buffering) {
19283
+ return;
19284
+ }
19266
19285
 
19267
19286
  // set next load level : this will trigger a playlist load if needed
19268
19287
  if (hls.loadLevel !== level && hls.manualLevel === -1) {
@@ -20471,9 +20490,13 @@
20471
20490
  }
20472
20491
  logger.log("startLoad(" + startPosition + ")");
20473
20492
  this.started = true;
20474
- this.networkControllers.forEach(function (controller) {
20475
- controller.startLoad(startPosition);
20476
- });
20493
+ this.resumeBuffering();
20494
+ for (var i = 0; i < this.networkControllers.length; i++) {
20495
+ this.networkControllers[i].startLoad(startPosition);
20496
+ if (!this.started || !this.networkControllers) {
20497
+ break;
20498
+ }
20499
+ }
20477
20500
  }
20478
20501
 
20479
20502
  /**
@@ -20482,32 +20505,35 @@
20482
20505
  _proto.stopLoad = function stopLoad() {
20483
20506
  logger.log('stopLoad');
20484
20507
  this.started = false;
20485
- this.networkControllers.forEach(function (controller) {
20486
- controller.stopLoad();
20487
- });
20508
+ for (var i = 0; i < this.networkControllers.length; i++) {
20509
+ this.networkControllers[i].stopLoad();
20510
+ if (this.started || !this.networkControllers) {
20511
+ break;
20512
+ }
20513
+ }
20488
20514
  }
20489
20515
 
20490
20516
  /**
20491
- * Resumes stream controller segment loading if previously started.
20517
+ * Resumes stream controller segment loading after `pauseBuffering` has been called.
20492
20518
  */;
20493
20519
  _proto.resumeBuffering = function resumeBuffering() {
20494
- if (this.started) {
20495
- this.networkControllers.forEach(function (controller) {
20496
- if ('fragmentLoader' in controller) {
20497
- controller.startLoad(-1);
20498
- }
20499
- });
20500
- }
20520
+ logger.log("resume buffering");
20521
+ this.networkControllers.forEach(function (controller) {
20522
+ if (controller.resumeBuffering) {
20523
+ controller.resumeBuffering();
20524
+ }
20525
+ });
20501
20526
  }
20502
20527
 
20503
20528
  /**
20504
- * Stops stream controller segment loading without changing 'started' state like stopLoad().
20529
+ * Prevents stream controller from loading new segments until `resumeBuffering` is called.
20505
20530
  * This allows for media buffering to be paused without interupting playlist loading.
20506
20531
  */;
20507
20532
  _proto.pauseBuffering = function pauseBuffering() {
20533
+ logger.log("pause buffering");
20508
20534
  this.networkControllers.forEach(function (controller) {
20509
- if ('fragmentLoader' in controller) {
20510
- controller.stopLoad();
20535
+ if (controller.pauseBuffering) {
20536
+ controller.pauseBuffering();
20511
20537
  }
20512
20538
  });
20513
20539
  }
@@ -21064,7 +21090,7 @@
21064
21090
  * Get the video-dev/hls.js package version.
21065
21091
  */
21066
21092
  function get() {
21067
- return "1.5.17";
21093
+ return "1.5.18";
21068
21094
  }
21069
21095
  }, {
21070
21096
  key: "Events",