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.
@@ -431,7 +431,7 @@ function enableLogs(debugConfig, context, id) {
431
431
  // Some browsers don't allow to use bind on console object anyway
432
432
  // fallback to default if needed
433
433
  try {
434
- newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.5.2-0.canary.9966"}`);
434
+ newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.5.2-0.canary.9970"}`);
435
435
  } catch (e) {
436
436
  /* log fn threw an exception. All logger methods are no-ops. */
437
437
  return createLogger();
@@ -1433,6 +1433,12 @@ function readUint32(buffer, offset) {
1433
1433
  const val = readSint32(buffer, offset);
1434
1434
  return val < 0 ? 4294967296 + val : val;
1435
1435
  }
1436
+ function readUint64(buffer, offset) {
1437
+ let result = readUint32(buffer, offset);
1438
+ result *= Math.pow(2, 32);
1439
+ result += readUint32(buffer, offset + 4);
1440
+ return result;
1441
+ }
1436
1442
  function readSint32(buffer, offset) {
1437
1443
  return buffer[offset] << 24 | buffer[offset + 1] << 16 | buffer[offset + 2] << 8 | buffer[offset + 3];
1438
1444
  }
@@ -1495,15 +1501,14 @@ function parseSegmentIndex(sidx) {
1495
1501
  let index = 8;
1496
1502
  const timescale = readUint32(sidx, index);
1497
1503
  index += 4;
1498
-
1499
- // TODO: parse earliestPresentationTime and firstOffset
1500
- // usually zero in our case
1501
- const earliestPresentationTime = 0;
1502
- const firstOffset = 0;
1504
+ let earliestPresentationTime = 0;
1505
+ let firstOffset = 0;
1503
1506
  if (version === 0) {
1504
- index += 8;
1507
+ earliestPresentationTime = readUint32(sidx, index += 4);
1508
+ firstOffset = readUint32(sidx, index += 4);
1505
1509
  } else {
1506
- index += 16;
1510
+ earliestPresentationTime = readUint64(sidx, index += 8);
1511
+ firstOffset = readUint64(sidx, index += 8);
1507
1512
  }
1508
1513
 
1509
1514
  // skip reserved
@@ -1951,15 +1956,22 @@ function getDuration(data, initData) {
1951
1956
  }
1952
1957
  if (videoDuration === 0 && audioDuration === 0) {
1953
1958
  // If duration samples are not available in the traf use sidx subsegment_duration
1959
+ let sidxMinStart = Infinity;
1960
+ let sidxMaxEnd = 0;
1954
1961
  let sidxDuration = 0;
1955
1962
  const sidxs = findBox(data, ['sidx']);
1956
1963
  for (let i = 0; i < sidxs.length; i++) {
1957
1964
  const sidx = parseSegmentIndex(sidxs[i]);
1958
1965
  if (sidx != null && sidx.references) {
1959
- sidxDuration += sidx.references.reduce((dur, ref) => dur + ref.info.duration || 0, 0);
1966
+ sidxMinStart = Math.min(sidxMinStart, sidx.earliestPresentationTime / sidx.timescale);
1967
+ const subSegmentDuration = sidx.references.reduce((dur, ref) => dur + ref.info.duration || 0, 0);
1968
+ sidxMaxEnd = Math.max(sidxMaxEnd, subSegmentDuration + sidx.earliestPresentationTime / sidx.timescale);
1969
+ sidxDuration = sidxMaxEnd - sidxMinStart;
1960
1970
  }
1961
1971
  }
1962
- return sidxDuration;
1972
+ if (sidxDuration && isFiniteNumber(sidxDuration)) {
1973
+ return sidxDuration;
1974
+ }
1963
1975
  }
1964
1976
  if (videoDuration) {
1965
1977
  return videoDuration;
@@ -6748,8 +6760,12 @@ class AbrController extends Logger {
6748
6760
  return -1;
6749
6761
  }
6750
6762
  set nextAutoLevel(nextLevel) {
6751
- const value = Math.max(this.hls.minAutoLevel, nextLevel);
6752
- if (this._nextAutoLevel != value) {
6763
+ const {
6764
+ maxAutoLevel,
6765
+ minAutoLevel
6766
+ } = this.hls;
6767
+ const value = Math.min(Math.max(nextLevel, minAutoLevel), maxAutoLevel);
6768
+ if (this._nextAutoLevel !== value) {
6753
6769
  this.nextAutoLevelKey = '';
6754
6770
  this._nextAutoLevel = value;
6755
6771
  }
@@ -7229,6 +7245,7 @@ class BufferController extends Logger {
7229
7245
  this.resetBuffer(type);
7230
7246
  });
7231
7247
  this._initSourceBuffer();
7248
+ this.hls.resumeBuffering();
7232
7249
  }
7233
7250
  resetBuffer(type) {
7234
7251
  const sb = this.sourceBuffer[type];
@@ -11937,6 +11954,7 @@ class BaseStreamController extends TaskLoop {
11937
11954
  this.startFragRequested = false;
11938
11955
  this.decrypter = void 0;
11939
11956
  this.initPTS = [];
11957
+ this.buffering = true;
11940
11958
  this.onMediaSeeking = () => {
11941
11959
  const {
11942
11960
  config,
@@ -12042,6 +12060,12 @@ class BaseStreamController extends TaskLoop {
12042
12060
  this.clearNextTick();
12043
12061
  this.state = State.STOPPED;
12044
12062
  }
12063
+ pauseBuffering() {
12064
+ this.buffering = false;
12065
+ }
12066
+ resumeBuffering() {
12067
+ this.buffering = true;
12068
+ }
12045
12069
  _streamEnded(bufferInfo, levelDetails) {
12046
12070
  // If playlist is live, there is another buffered range after the current range, nothing buffered, media is detached,
12047
12071
  // of nothing loading/loaded return false
@@ -18739,7 +18763,8 @@ class StreamController extends BaseStreamController {
18739
18763
  }
18740
18764
  // set new level to playlist loader : this will trigger start level load
18741
18765
  // hls.nextLoadLevel remains until it is set to a new value or until a new frag is successfully loaded
18742
- this.level = hls.nextLoadLevel = startLevel;
18766
+ hls.nextLoadLevel = startLevel;
18767
+ this.level = hls.loadLevel;
18743
18768
  this.loadedmetadata = false;
18744
18769
  }
18745
18770
  // if startPosition undefined but lastCurrentTime set, set startPosition to last currentTime
@@ -18832,7 +18857,7 @@ class StreamController extends BaseStreamController {
18832
18857
  if (this.altAudio && this.audioOnly) {
18833
18858
  return;
18834
18859
  }
18835
- if (!(levels != null && levels[level])) {
18860
+ if (!this.buffering || !(levels != null && levels[level])) {
18836
18861
  return;
18837
18862
  }
18838
18863
  const levelInfo = levels[level];
@@ -19792,7 +19817,7 @@ class Hls {
19792
19817
  * Get the video-dev/hls.js package version.
19793
19818
  */
19794
19819
  static get version() {
19795
- return "1.5.2-0.canary.9966";
19820
+ return "1.5.2-0.canary.9970";
19796
19821
  }
19797
19822
 
19798
19823
  /**
@@ -19861,7 +19886,6 @@ class Hls {
19861
19886
  this.logger = void 0;
19862
19887
  this.coreComponents = void 0;
19863
19888
  this.networkControllers = void 0;
19864
- this.started = false;
19865
19889
  this._emitter = new EventEmitter();
19866
19890
  this._autoLevelCapping = -1;
19867
19891
  this._maxHdcpLevel = null;
@@ -20076,7 +20100,6 @@ class Hls {
20076
20100
  */
20077
20101
  startLoad(startPosition = -1) {
20078
20102
  this.logger.log(`startLoad(${startPosition})`);
20079
- this.started = true;
20080
20103
  this.networkControllers.forEach(controller => {
20081
20104
  controller.startLoad(startPosition);
20082
20105
  });
@@ -20087,33 +20110,30 @@ class Hls {
20087
20110
  */
20088
20111
  stopLoad() {
20089
20112
  this.logger.log('stopLoad');
20090
- this.started = false;
20091
20113
  this.networkControllers.forEach(controller => {
20092
20114
  controller.stopLoad();
20093
20115
  });
20094
20116
  }
20095
20117
 
20096
20118
  /**
20097
- * Resumes stream controller segment loading if previously started.
20119
+ * Resumes stream controller segment loading after `pauseBuffering` has been called.
20098
20120
  */
20099
20121
  resumeBuffering() {
20100
- if (this.started) {
20101
- this.networkControllers.forEach(controller => {
20102
- if ('fragmentLoader' in controller) {
20103
- controller.startLoad(-1);
20104
- }
20105
- });
20106
- }
20122
+ this.networkControllers.forEach(controller => {
20123
+ if (controller.resumeBuffering) {
20124
+ controller.resumeBuffering();
20125
+ }
20126
+ });
20107
20127
  }
20108
20128
 
20109
20129
  /**
20110
- * Stops stream controller segment loading without changing 'started' state like stopLoad().
20130
+ * Prevents stream controller from loading new segments until `resumeBuffering` is called.
20111
20131
  * This allows for media buffering to be paused without interupting playlist loading.
20112
20132
  */
20113
20133
  pauseBuffering() {
20114
20134
  this.networkControllers.forEach(controller => {
20115
- if ('fragmentLoader' in controller) {
20116
- controller.stopLoad();
20135
+ if (controller.pauseBuffering) {
20136
+ controller.pauseBuffering();
20117
20137
  }
20118
20138
  });
20119
20139
  }