hls.js 1.5.2-0.canary.9966 → 1.5.2-0.canary.9970

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
@@ -556,7 +556,7 @@
556
556
  // Some browsers don't allow to use bind on console object anyway
557
557
  // fallback to default if needed
558
558
  try {
559
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.2-0.canary.9966");
559
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.2-0.canary.9970");
560
560
  } catch (e) {
561
561
  /* log fn threw an exception. All logger methods are no-ops. */
562
562
  return createLogger();
@@ -1799,6 +1799,12 @@
1799
1799
  var val = readSint32(buffer, offset);
1800
1800
  return val < 0 ? 4294967296 + val : val;
1801
1801
  }
1802
+ function readUint64(buffer, offset) {
1803
+ var result = readUint32(buffer, offset);
1804
+ result *= Math.pow(2, 32);
1805
+ result += readUint32(buffer, offset + 4);
1806
+ return result;
1807
+ }
1802
1808
  function readSint32(buffer, offset) {
1803
1809
  return buffer[offset] << 24 | buffer[offset + 1] << 16 | buffer[offset + 2] << 8 | buffer[offset + 3];
1804
1810
  }
@@ -1861,15 +1867,14 @@
1861
1867
  var index = 8;
1862
1868
  var timescale = readUint32(sidx, index);
1863
1869
  index += 4;
1864
-
1865
- // TODO: parse earliestPresentationTime and firstOffset
1866
- // usually zero in our case
1867
1870
  var earliestPresentationTime = 0;
1868
1871
  var firstOffset = 0;
1869
1872
  if (version === 0) {
1870
- index += 8;
1873
+ earliestPresentationTime = readUint32(sidx, index += 4);
1874
+ firstOffset = readUint32(sidx, index += 4);
1871
1875
  } else {
1872
- index += 16;
1876
+ earliestPresentationTime = readUint64(sidx, index += 8);
1877
+ firstOffset = readUint64(sidx, index += 8);
1873
1878
  }
1874
1879
 
1875
1880
  // skip reserved
@@ -2319,17 +2324,24 @@
2319
2324
  }
2320
2325
  if (videoDuration === 0 && audioDuration === 0) {
2321
2326
  // If duration samples are not available in the traf use sidx subsegment_duration
2327
+ var sidxMinStart = Infinity;
2328
+ var sidxMaxEnd = 0;
2322
2329
  var sidxDuration = 0;
2323
2330
  var sidxs = findBox(data, ['sidx']);
2324
2331
  for (var _i2 = 0; _i2 < sidxs.length; _i2++) {
2325
2332
  var sidx = parseSegmentIndex(sidxs[_i2]);
2326
2333
  if (sidx != null && sidx.references) {
2327
- sidxDuration += sidx.references.reduce(function (dur, ref) {
2334
+ sidxMinStart = Math.min(sidxMinStart, sidx.earliestPresentationTime / sidx.timescale);
2335
+ var subSegmentDuration = sidx.references.reduce(function (dur, ref) {
2328
2336
  return dur + ref.info.duration || 0;
2329
2337
  }, 0);
2338
+ sidxMaxEnd = Math.max(sidxMaxEnd, subSegmentDuration + sidx.earliestPresentationTime / sidx.timescale);
2339
+ sidxDuration = sidxMaxEnd - sidxMinStart;
2330
2340
  }
2331
2341
  }
2332
- return sidxDuration;
2342
+ if (sidxDuration && isFiniteNumber(sidxDuration)) {
2343
+ return sidxDuration;
2344
+ }
2333
2345
  }
2334
2346
  if (videoDuration) {
2335
2347
  return videoDuration;
@@ -7797,8 +7809,11 @@
7797
7809
  return nextABRAutoLevel;
7798
7810
  },
7799
7811
  set: function set(nextLevel) {
7800
- var value = Math.max(this.hls.minAutoLevel, nextLevel);
7801
- if (this._nextAutoLevel != value) {
7812
+ var _this$hls3 = this.hls,
7813
+ maxAutoLevel = _this$hls3.maxAutoLevel,
7814
+ minAutoLevel = _this$hls3.minAutoLevel;
7815
+ var value = Math.min(Math.max(nextLevel, minAutoLevel), maxAutoLevel);
7816
+ if (this._nextAutoLevel !== value) {
7802
7817
  this.nextAutoLevelKey = '';
7803
7818
  this._nextAutoLevel = value;
7804
7819
  }
@@ -9532,6 +9547,7 @@
9532
9547
  _this.startFragRequested = false;
9533
9548
  _this.decrypter = void 0;
9534
9549
  _this.initPTS = [];
9550
+ _this.buffering = true;
9535
9551
  _this.onMediaSeeking = function () {
9536
9552
  var _assertThisInitialize = _assertThisInitialized(_this),
9537
9553
  config = _assertThisInitialize.config,
@@ -9635,6 +9651,12 @@
9635
9651
  this.clearNextTick();
9636
9652
  this.state = State.STOPPED;
9637
9653
  };
9654
+ _proto.pauseBuffering = function pauseBuffering() {
9655
+ this.buffering = false;
9656
+ };
9657
+ _proto.resumeBuffering = function resumeBuffering() {
9658
+ this.buffering = true;
9659
+ };
9638
9660
  _proto._streamEnded = function _streamEnded(bufferInfo, levelDetails) {
9639
9661
  // If playlist is live, there is another buffered range after the current range, nothing buffered, media is detached,
9640
9662
  // of nothing loading/loaded return false
@@ -16490,12 +16512,13 @@
16490
16512
  trackId = this.trackId;
16491
16513
  var config = hls.config;
16492
16514
 
16493
- // 1. if video not attached AND
16515
+ // 1. if buffering is suspended
16516
+ // 2. if video not attached AND
16494
16517
  // start fragment already requested OR start frag prefetch not enabled
16495
- // 2. if tracks or track not loaded and selected
16518
+ // 3. if tracks or track not loaded and selected
16496
16519
  // then exit loop
16497
16520
  // => if media not attached but start frag prefetch is enabled and start frag not requested yet, we will not exit loop
16498
- if (!media && (this.startFragRequested || !config.startFragPrefetch) || !(levels != null && levels[trackId])) {
16521
+ if (!this.buffering || !media && (this.startFragRequested || !config.startFragPrefetch) || !(levels != null && levels[trackId])) {
16499
16522
  return;
16500
16523
  }
16501
16524
  var levelInfo = levels[trackId];
@@ -16681,7 +16704,7 @@
16681
16704
 
16682
16705
  // compute start position if we are aligned with the main playlist
16683
16706
  if (!this.startFragRequested && (this.mainDetails || !newDetails.live)) {
16684
- this.setStartPosition(track.details, sliding);
16707
+ this.setStartPosition(this.mainDetails || newDetails, sliding);
16685
16708
  }
16686
16709
  // only switch back to IDLE state if we were waiting for track to start downloading a new fragment
16687
16710
  if (this.state === State.WAITING_TRACK && !this.waitForCdnTuneIn(newDetails)) {
@@ -17578,7 +17601,7 @@
17578
17601
  track.details = newDetails;
17579
17602
  this.levelLastLoaded = track;
17580
17603
  if (!this.startFragRequested && (this.mainDetails || !newDetails.live)) {
17581
- this.setStartPosition(track.details, sliding);
17604
+ this.setStartPosition(this.mainDetails || newDetails, sliding);
17582
17605
  }
17583
17606
 
17584
17607
  // trigger handler right now
@@ -18521,6 +18544,7 @@
18521
18544
  _this2.resetBuffer(type);
18522
18545
  });
18523
18546
  this._initSourceBuffer();
18547
+ this.hls.resumeBuffering();
18524
18548
  };
18525
18549
  _proto.resetBuffer = function resetBuffer(type) {
18526
18550
  var sb = this.sourceBuffer[type];
@@ -27393,7 +27417,8 @@
27393
27417
  }
27394
27418
  // set new level to playlist loader : this will trigger start level load
27395
27419
  // hls.nextLoadLevel remains until it is set to a new value or until a new frag is successfully loaded
27396
- this.level = hls.nextLoadLevel = startLevel;
27420
+ hls.nextLoadLevel = startLevel;
27421
+ this.level = hls.loadLevel;
27397
27422
  this.loadedmetadata = false;
27398
27423
  }
27399
27424
  // if startPosition undefined but lastCurrentTime set, set startPosition to last currentTime
@@ -27478,7 +27503,7 @@
27478
27503
  if (this.altAudio && this.audioOnly) {
27479
27504
  return;
27480
27505
  }
27481
- if (!(levels != null && levels[level])) {
27506
+ if (!this.buffering || !(levels != null && levels[level])) {
27482
27507
  return;
27483
27508
  }
27484
27509
  var levelInfo = levels[level];
@@ -28456,7 +28481,6 @@
28456
28481
  this.logger = void 0;
28457
28482
  this.coreComponents = void 0;
28458
28483
  this.networkControllers = void 0;
28459
- this.started = false;
28460
28484
  this._emitter = new EventEmitter();
28461
28485
  this._autoLevelCapping = -1;
28462
28486
  this._maxHdcpLevel = null;
@@ -28687,7 +28711,6 @@
28687
28711
  startPosition = -1;
28688
28712
  }
28689
28713
  this.logger.log("startLoad(" + startPosition + ")");
28690
- this.started = true;
28691
28714
  this.networkControllers.forEach(function (controller) {
28692
28715
  controller.startLoad(startPosition);
28693
28716
  });
@@ -28698,33 +28721,30 @@
28698
28721
  */;
28699
28722
  _proto.stopLoad = function stopLoad() {
28700
28723
  this.logger.log('stopLoad');
28701
- this.started = false;
28702
28724
  this.networkControllers.forEach(function (controller) {
28703
28725
  controller.stopLoad();
28704
28726
  });
28705
28727
  }
28706
28728
 
28707
28729
  /**
28708
- * Resumes stream controller segment loading if previously started.
28730
+ * Resumes stream controller segment loading after `pauseBuffering` has been called.
28709
28731
  */;
28710
28732
  _proto.resumeBuffering = function resumeBuffering() {
28711
- if (this.started) {
28712
- this.networkControllers.forEach(function (controller) {
28713
- if ('fragmentLoader' in controller) {
28714
- controller.startLoad(-1);
28715
- }
28716
- });
28717
- }
28733
+ this.networkControllers.forEach(function (controller) {
28734
+ if (controller.resumeBuffering) {
28735
+ controller.resumeBuffering();
28736
+ }
28737
+ });
28718
28738
  }
28719
28739
 
28720
28740
  /**
28721
- * Stops stream controller segment loading without changing 'started' state like stopLoad().
28741
+ * Prevents stream controller from loading new segments until `resumeBuffering` is called.
28722
28742
  * This allows for media buffering to be paused without interupting playlist loading.
28723
28743
  */;
28724
28744
  _proto.pauseBuffering = function pauseBuffering() {
28725
28745
  this.networkControllers.forEach(function (controller) {
28726
- if ('fragmentLoader' in controller) {
28727
- controller.stopLoad();
28746
+ if (controller.pauseBuffering) {
28747
+ controller.pauseBuffering();
28728
28748
  }
28729
28749
  });
28730
28750
  }
@@ -29281,7 +29301,7 @@
29281
29301
  * Get the video-dev/hls.js package version.
29282
29302
  */
29283
29303
  function get() {
29284
- return "1.5.2-0.canary.9966";
29304
+ return "1.5.2-0.canary.9970";
29285
29305
  }
29286
29306
  }, {
29287
29307
  key: "Events",
package/dist/hls.js.d.ts CHANGED
@@ -246,6 +246,7 @@ export declare class BaseStreamController extends TaskLoop implements NetworkCom
246
246
  protected startFragRequested: boolean;
247
247
  protected decrypter: Decrypter;
248
248
  protected initPTS: RationalTimestamp[];
249
+ protected buffering: boolean;
249
250
  constructor(hls: Hls, fragmentTracker: FragmentTracker, keyLoader: KeyLoader, logPrefix: string, playlistType: PlaylistLevelType);
250
251
  protected registerListeners(): void;
251
252
  protected unregisterListeners(): void;
@@ -253,6 +254,8 @@ export declare class BaseStreamController extends TaskLoop implements NetworkCom
253
254
  protected onTickEnd(): void;
254
255
  startLoad(startPosition: number): void;
255
256
  stopLoad(): void;
257
+ pauseBuffering(): void;
258
+ resumeBuffering(): void;
256
259
  protected _streamEnded(bufferInfo: BufferInfo, levelDetails: LevelDetails): boolean;
257
260
  protected getLevelDetails(): LevelDetails | undefined;
258
261
  protected onMediaAttached(event: Events.MEDIA_ATTACHED, data: MediaAttachedData): void;
@@ -1318,7 +1321,6 @@ declare class Hls implements HlsEventEmitter {
1318
1321
  readonly logger: ILogger;
1319
1322
  private coreComponents;
1320
1323
  private networkControllers;
1321
- private started;
1322
1324
  private _emitter;
1323
1325
  private _autoLevelCapping;
1324
1326
  private _maxHdcpLevel;
@@ -1405,11 +1407,11 @@ declare class Hls implements HlsEventEmitter {
1405
1407
  */
1406
1408
  stopLoad(): void;
1407
1409
  /**
1408
- * Resumes stream controller segment loading if previously started.
1410
+ * Resumes stream controller segment loading after `pauseBuffering` has been called.
1409
1411
  */
1410
1412
  resumeBuffering(): void;
1411
1413
  /**
1412
- * Stops stream controller segment loading without changing 'started' state like stopLoad().
1414
+ * Prevents stream controller from loading new segments until `resumeBuffering` is called.
1413
1415
  * This allows for media buffering to be paused without interupting playlist loading.
1414
1416
  */
1415
1417
  pauseBuffering(): void;
@@ -2411,6 +2413,8 @@ export declare type MP4RemuxerConfig = {
2411
2413
  export declare interface NetworkComponentAPI extends ComponentAPI {
2412
2414
  startLoad(startPosition: number): void;
2413
2415
  stopLoad(): void;
2416
+ pauseBuffering?(): void;
2417
+ resumeBuffering?(): void;
2414
2418
  }
2415
2419
 
2416
2420
  export declare const enum NetworkErrorAction {