hls.js 1.5.12-0.canary.10351 → 1.5.12-0.canary.10353

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
@@ -493,7 +493,7 @@
493
493
  // Some browsers don't allow to use bind on console object anyway
494
494
  // fallback to default if needed
495
495
  try {
496
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.12-0.canary.10351");
496
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.12-0.canary.10353");
497
497
  } catch (e) {
498
498
  /* log fn threw an exception. All logger methods are no-ops. */
499
499
  return createLogger();
@@ -6581,12 +6581,9 @@
6581
6581
  }
6582
6582
  if (videoPreference) {
6583
6583
  allowedVideoRanges = videoPreference.allowedVideoRanges || VideoRangeValues.slice(0);
6584
- preferHDR = videoPreference.preferHDR !== undefined ? videoPreference.preferHDR : isHdrSupported();
6585
- if (preferHDR) {
6586
- allowedVideoRanges = allowedVideoRanges.filter(function (range) {
6587
- return range !== 'SDR';
6588
- });
6589
- } else {
6584
+ var allowAutoPreferHDR = allowedVideoRanges.join('') !== 'SDR' && !videoPreference.videoCodec;
6585
+ preferHDR = videoPreference.preferHDR !== undefined ? videoPreference.preferHDR : allowAutoPreferHDR && isHdrSupported();
6586
+ if (!preferHDR) {
6590
6587
  allowedVideoRanges = ['SDR'];
6591
6588
  }
6592
6589
  }
@@ -6600,13 +6597,15 @@
6600
6597
  var codecSets = Object.keys(codecTiers);
6601
6598
  var channelsPreference = audioPreference == null ? void 0 : audioPreference.channels;
6602
6599
  var audioCodecPreference = audioPreference == null ? void 0 : audioPreference.audioCodec;
6600
+ var videoCodecPreference = videoPreference == null ? void 0 : videoPreference.videoCodec;
6603
6601
  var preferStereo = channelsPreference && parseInt(channelsPreference) === 2;
6604
6602
  // Use first level set to determine stereo, and minimum resolution and framerate
6605
- var hasStereo = true;
6603
+ var hasStereo = false;
6606
6604
  var hasCurrentVideoRange = false;
6607
6605
  var minHeight = Infinity;
6608
6606
  var minFramerate = Infinity;
6609
6607
  var minBitrate = Infinity;
6608
+ var minIndex = Infinity;
6610
6609
  var selectedScore = 0;
6611
6610
  var videoRanges = [];
6612
6611
  var _getVideoSelectionOpt = getVideoSelectionOptions(currentVideoRange, videoPreference),
@@ -6614,7 +6613,7 @@
6614
6613
  allowedVideoRanges = _getVideoSelectionOpt.allowedVideoRanges;
6615
6614
  var _loop = function _loop() {
6616
6615
  var tier = codecTiers[codecSets[i]];
6617
- hasStereo = tier.channels[2] > 0;
6616
+ hasStereo || (hasStereo = tier.channels[2] > 0);
6618
6617
  minHeight = Math.min(minHeight, tier.minHeight);
6619
6618
  minFramerate = Math.min(minFramerate, tier.minFramerate);
6620
6619
  minBitrate = Math.min(minBitrate, tier.minBitrate);
@@ -6623,7 +6622,6 @@
6623
6622
  });
6624
6623
  if (matchingVideoRanges.length > 0) {
6625
6624
  hasCurrentVideoRange = true;
6626
- videoRanges = matchingVideoRanges;
6627
6625
  }
6628
6626
  };
6629
6627
  for (var i = codecSets.length; i--;) {
@@ -6638,7 +6636,6 @@
6638
6636
  // If there are no variants with matching preference, set currentVideoRange to undefined
6639
6637
  if (!hasCurrentVideoRange) {
6640
6638
  currentVideoRange = undefined;
6641
- videoRanges = [];
6642
6639
  }
6643
6640
  var codecSet = codecSets.reduce(function (selected, candidate) {
6644
6641
  // Remove candiates which do not meet bitrate, default audio, stereo or channels preference, 1080p or lower, 30fps or lower, or SDR/HDR selection if present
@@ -6646,6 +6643,9 @@
6646
6643
  if (candidate === selected) {
6647
6644
  return selected;
6648
6645
  }
6646
+ videoRanges = hasCurrentVideoRange ? allowedVideoRanges.filter(function (range) {
6647
+ return candidateTier.videoRanges[range] > 0;
6648
+ }) : [];
6649
6649
  if (candidateTier.minBitrate > currentBw) {
6650
6650
  logStartCodecCandidateIgnored(candidate, "min bitrate of " + candidateTier.minBitrate + " > current estimate of " + currentBw);
6651
6651
  return selected;
@@ -6681,6 +6681,10 @@
6681
6681
  logStartCodecCandidateIgnored(candidate, "no variants with VIDEO-RANGE of " + JSON.stringify(videoRanges) + " found");
6682
6682
  return selected;
6683
6683
  }
6684
+ if (videoCodecPreference && candidate.indexOf(videoCodecPreference.substring(0, 4)) % 5 !== 0) {
6685
+ logStartCodecCandidateIgnored(candidate, "video codec preference \"" + videoCodecPreference + "\" not found");
6686
+ return selected;
6687
+ }
6684
6688
  if (candidateTier.maxScore < selectedScore) {
6685
6689
  logStartCodecCandidateIgnored(candidate, "max score of " + candidateTier.maxScore + " < selected max of " + selectedScore);
6686
6690
  return selected;
@@ -6689,6 +6693,7 @@
6689
6693
  if (selected && (codecsSetSelectionPreferenceValue(candidate) >= codecsSetSelectionPreferenceValue(selected) || candidateTier.fragmentError > codecTiers[selected].fragmentError)) {
6690
6694
  return selected;
6691
6695
  }
6696
+ minIndex = candidateTier.minIndex;
6692
6697
  selectedScore = candidateTier.maxScore;
6693
6698
  return candidate;
6694
6699
  }, undefined);
@@ -6697,7 +6702,8 @@
6697
6702
  videoRanges: videoRanges,
6698
6703
  preferHDR: preferHDR,
6699
6704
  minFramerate: minFramerate,
6700
- minBitrate: minBitrate
6705
+ minBitrate: minBitrate,
6706
+ minIndex: minIndex
6701
6707
  };
6702
6708
  }
6703
6709
  function logStartCodecCandidateIgnored(codeSet, reason) {
@@ -6735,7 +6741,7 @@
6735
6741
  });
6736
6742
  }
6737
6743
  function getCodecTiers(levels, audioTracksByGroup, minAutoLevel, maxAutoLevel) {
6738
- return levels.slice(minAutoLevel, maxAutoLevel + 1).reduce(function (tiers, level) {
6744
+ return levels.slice(minAutoLevel, maxAutoLevel + 1).reduce(function (tiers, level, index) {
6739
6745
  if (!level.codecSet) {
6740
6746
  return tiers;
6741
6747
  }
@@ -6746,6 +6752,7 @@
6746
6752
  minBitrate: Infinity,
6747
6753
  minHeight: Infinity,
6748
6754
  minFramerate: Infinity,
6755
+ minIndex: index,
6749
6756
  maxScore: 0,
6750
6757
  videoRanges: {
6751
6758
  SDR: 0
@@ -6761,6 +6768,7 @@
6761
6768
  var lesserWidthOrHeight = Math.min(level.height, level.width);
6762
6769
  tier.minHeight = Math.min(tier.minHeight, lesserWidthOrHeight);
6763
6770
  tier.minFramerate = Math.min(tier.minFramerate, level.frameRate);
6771
+ tier.minIndex = Math.min(tier.minIndex, index);
6764
6772
  tier.maxScore = Math.max(tier.maxScore, level.score);
6765
6773
  tier.fragmentError += level.fragmentError;
6766
6774
  tier.videoRanges[level.videoRange] = (tier.videoRanges[level.videoRange] || 0) + 1;
@@ -7205,6 +7213,7 @@
7205
7213
  var audioPreference = config.audioPreference,
7206
7214
  videoPreference = config.videoPreference;
7207
7215
  var audioTracksByGroup = this.audioTracksByGroup || (this.audioTracksByGroup = getAudioTracksByGroup(allAudioTracks));
7216
+ var minStartIndex = -1;
7208
7217
  if (firstSelection) {
7209
7218
  if (this.firstSelection !== -1) {
7210
7219
  return this.firstSelection;
@@ -7215,7 +7224,9 @@
7215
7224
  videoRanges = startTier.videoRanges,
7216
7225
  minFramerate = startTier.minFramerate,
7217
7226
  minBitrate = startTier.minBitrate,
7227
+ minIndex = startTier.minIndex,
7218
7228
  preferHDR = startTier.preferHDR;
7229
+ minStartIndex = minIndex;
7219
7230
  currentCodecSet = codecSet;
7220
7231
  currentVideoRange = preferHDR ? videoRanges[videoRanges.length - 1] : videoRanges[0];
7221
7232
  currentFrameRate = minFramerate;
@@ -7239,8 +7250,10 @@
7239
7250
  // skip candidates which change codec-family or video-range,
7240
7251
  // and which decrease or increase frame-rate for up and down-switch respectfully
7241
7252
  if (currentCodecSet && levelInfo.codecSet !== currentCodecSet || currentVideoRange && levelInfo.videoRange !== currentVideoRange || upSwitch && currentFrameRate > levelInfo.frameRate || !upSwitch && currentFrameRate > 0 && currentFrameRate < levelInfo.frameRate || levelInfo.supportedResult && !((_levelInfo$supportedR = levelInfo.supportedResult.decodingInfoResults) != null && _levelInfo$supportedR[0].smooth)) {
7242
- levelsSkipped.push(i);
7243
- return 0; // continue
7253
+ if (firstSelection && i !== minStartIndex) {
7254
+ levelsSkipped.push(i);
7255
+ return 0; // continue
7256
+ }
7244
7257
  }
7245
7258
  var levelDetails = levelInfo.details;
7246
7259
  var avgDuration = (partCurrent ? levelDetails == null ? void 0 : levelDetails.partTarget : levelDetails == null ? void 0 : levelDetails.averagetargetduration) || currentFragDuration;
@@ -7275,7 +7288,7 @@
7275
7288
  if (levelsSkipped.length) {
7276
7289
  _this3.trace("Skipped level(s) " + levelsSkipped.join(',') + " of " + maxAutoLevel + " max with CODECS and VIDEO-RANGE:\"" + levels[levelsSkipped[0]].codecs + "\" " + levels[levelsSkipped[0]].videoRange + "; not compatible with \"" + level.codecs + "\" " + currentVideoRange);
7277
7290
  }
7278
- _this3.info("switch candidate:" + selectionBaseLevel + "->" + i + " adjustedbw(" + Math.round(adjustedbw) + ")-bitrate=" + Math.round(adjustedbw - bitrate) + " ttfb:" + ttfbEstimateSec.toFixed(1) + " avgDuration:" + avgDuration.toFixed(1) + " maxFetchDuration:" + maxFetchDuration.toFixed(1) + " fetchDuration:" + fetchDuration.toFixed(1) + " firstSelection:" + firstSelection + " codecSet:" + currentCodecSet + " videoRange:" + currentVideoRange + " hls.loadLevel:" + loadLevel);
7291
+ _this3.info("switch candidate:" + selectionBaseLevel + "->" + i + " adjustedbw(" + Math.round(adjustedbw) + ")-bitrate=" + Math.round(adjustedbw - bitrate) + " ttfb:" + ttfbEstimateSec.toFixed(1) + " avgDuration:" + avgDuration.toFixed(1) + " maxFetchDuration:" + maxFetchDuration.toFixed(1) + " fetchDuration:" + fetchDuration.toFixed(1) + " firstSelection:" + firstSelection + " codecSet:" + level.codecSet + " videoRange:" + level.videoRange + " hls.loadLevel:" + loadLevel);
7279
7292
  }
7280
7293
  if (firstSelection) {
7281
7294
  _this3.firstSelection = i;
@@ -14971,6 +14984,20 @@
14971
14984
  length: 0
14972
14985
  };
14973
14986
  };
14987
+ _proto.getLastNalUnit = function getLastNalUnit(samples) {
14988
+ var _VideoSample;
14989
+ var VideoSample = this.VideoSample;
14990
+ var lastUnit;
14991
+ // try to fallback to previous sample if current one is empty
14992
+ if (!VideoSample || VideoSample.units.length === 0) {
14993
+ VideoSample = samples[samples.length - 1];
14994
+ }
14995
+ if ((_VideoSample = VideoSample) != null && _VideoSample.units) {
14996
+ var units = VideoSample.units;
14997
+ lastUnit = units[units.length - 1];
14998
+ }
14999
+ return lastUnit;
15000
+ };
14974
15001
  _proto.pushAccessUnit = function pushAccessUnit(VideoSample, videoTrack) {
14975
15002
  if (VideoSample.units.length && VideoSample.frame) {
14976
15003
  // if sample does not have PTS/DTS, patch with last sample PTS/DTS
@@ -14993,7 +15020,7 @@
14993
15020
  logger.log(VideoSample.pts + '/' + VideoSample.dts + ':' + VideoSample.debug);
14994
15021
  }
14995
15022
  };
14996
- _proto.parseNALu = function parseNALu(track, array, last) {
15023
+ _proto.parseNALu = function parseNALu(track, array, endOfSegment) {
14997
15024
  var len = array.byteLength;
14998
15025
  var state = track.naluState || 0;
14999
15026
  var lastState = state;
@@ -15035,10 +15062,6 @@
15035
15062
  data: array.subarray(lastUnitStart, overflow),
15036
15063
  type: lastUnitType
15037
15064
  };
15038
- if (track.lastNalu) {
15039
- units.push(track.lastNalu);
15040
- track.lastNalu = null;
15041
- }
15042
15065
  // logger.log('pushing NALU, type/size:' + unit.type + '/' + unit.data.byteLength);
15043
15066
  units.push(unit);
15044
15067
  } else {
@@ -15046,7 +15069,7 @@
15046
15069
  // first check if start code delimiter is overlapping between 2 PES packets,
15047
15070
  // ie it started in last packet (lastState not zero)
15048
15071
  // and ended at the beginning of this PES packet (i <= 4 - lastState)
15049
- var lastUnit = track.lastNalu;
15072
+ var lastUnit = this.getLastNalUnit(track.samples);
15050
15073
  if (lastUnit) {
15051
15074
  if (lastState && i <= 4 - lastState) {
15052
15075
  // start delimiter overlapping between PES packets
@@ -15063,8 +15086,6 @@
15063
15086
  // logger.log('first NALU found with overflow:' + overflow);
15064
15087
  lastUnit.data = appendUint8Array(lastUnit.data, array.subarray(0, overflow));
15065
15088
  lastUnit.state = 0;
15066
- units.push(lastUnit);
15067
- track.lastNalu = null;
15068
15089
  }
15069
15090
  }
15070
15091
  }
@@ -15089,21 +15110,15 @@
15089
15110
  type: lastUnitType,
15090
15111
  state: state
15091
15112
  };
15092
- if (!last) {
15093
- track.lastNalu = _unit;
15094
- // logger.log('store NALu to push it on next PES');
15095
- } else {
15096
- units.push(_unit);
15097
- // logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state);
15098
- }
15099
- } else if (units.length === 0) {
15100
- // no NALu found
15113
+ units.push(_unit);
15114
+ // logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state);
15115
+ }
15116
+ // no NALu found
15117
+ if (units.length === 0) {
15101
15118
  // append pes.data to previous NAL unit
15102
- var _lastUnit = track.lastNalu;
15119
+ var _lastUnit = this.getLastNalUnit(track.samples);
15103
15120
  if (_lastUnit) {
15104
15121
  _lastUnit.data = appendUint8Array(_lastUnit.data, array);
15105
- units.push(_lastUnit);
15106
- track.lastNalu = null;
15107
15122
  }
15108
15123
  }
15109
15124
  track.naluState = state;
@@ -15273,9 +15288,9 @@
15273
15288
  }
15274
15289
  _inheritsLoose(AvcVideoParser, _BaseVideoParser);
15275
15290
  var _proto = AvcVideoParser.prototype;
15276
- _proto.parsePES = function parsePES(track, textTrack, pes, last, duration) {
15291
+ _proto.parsePES = function parsePES(track, textTrack, pes, endOfSegment, duration) {
15277
15292
  var _this = this;
15278
- var units = this.parseNALu(track, pes.data, last);
15293
+ var units = this.parseNALu(track, pes.data, endOfSegment);
15279
15294
  var VideoSample = this.VideoSample;
15280
15295
  var push;
15281
15296
  var spsfound = false;
@@ -15405,7 +15420,7 @@
15405
15420
  }
15406
15421
  });
15407
15422
  // if last PES packet, push samples
15408
- if (last && VideoSample) {
15423
+ if (endOfSegment && VideoSample) {
15409
15424
  this.pushAccessUnit(VideoSample, track);
15410
15425
  this.VideoSample = null;
15411
15426
  }
@@ -21361,7 +21376,7 @@
21361
21376
  */
21362
21377
  _proto.setAudioOption = function setAudioOption(audioOption) {
21363
21378
  var _this$audioTrackContr;
21364
- return (_this$audioTrackContr = this.audioTrackController) == null ? void 0 : _this$audioTrackContr.setAudioOption(audioOption);
21379
+ return ((_this$audioTrackContr = this.audioTrackController) == null ? void 0 : _this$audioTrackContr.setAudioOption(audioOption)) || null;
21365
21380
  }
21366
21381
  /**
21367
21382
  * Find and select the best matching subtitle track, making a level switch when a Group change is necessary.
@@ -21369,8 +21384,7 @@
21369
21384
  */;
21370
21385
  _proto.setSubtitleOption = function setSubtitleOption(subtitleOption) {
21371
21386
  var _this$subtitleTrackCo;
21372
- (_this$subtitleTrackCo = this.subtitleTrackController) == null ? void 0 : _this$subtitleTrackCo.setSubtitleOption(subtitleOption);
21373
- return null;
21387
+ return ((_this$subtitleTrackCo = this.subtitleTrackController) == null ? void 0 : _this$subtitleTrackCo.setSubtitleOption(subtitleOption)) || null;
21374
21388
  }
21375
21389
 
21376
21390
  /**
@@ -21895,7 +21909,7 @@
21895
21909
  * Get the video-dev/hls.js package version.
21896
21910
  */
21897
21911
  function get() {
21898
- return "1.5.12-0.canary.10351";
21912
+ return "1.5.12-0.canary.10353";
21899
21913
  }
21900
21914
  }, {
21901
21915
  key: "Events",