hls.js 1.5.2-0.canary.9965 → 1.5.2-0.canary.9969

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.9965"}`);
434
+ newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.5.2-0.canary.9969"}`);
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
  }
@@ -18739,7 +18755,8 @@ class StreamController extends BaseStreamController {
18739
18755
  }
18740
18756
  // set new level to playlist loader : this will trigger start level load
18741
18757
  // 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;
18758
+ hls.nextLoadLevel = startLevel;
18759
+ this.level = hls.loadLevel;
18743
18760
  this.loadedmetadata = false;
18744
18761
  }
18745
18762
  // if startPosition undefined but lastCurrentTime set, set startPosition to last currentTime
@@ -19792,7 +19809,7 @@ class Hls {
19792
19809
  * Get the video-dev/hls.js package version.
19793
19810
  */
19794
19811
  static get version() {
19795
- return "1.5.2-0.canary.9965";
19812
+ return "1.5.2-0.canary.9969";
19796
19813
  }
19797
19814
 
19798
19815
  /**