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.js CHANGED
@@ -522,7 +522,7 @@
522
522
  // Some browsers don't allow to use bind on console object anyway
523
523
  // fallback to default if needed
524
524
  try {
525
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.12-0.canary.10351");
525
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.12-0.canary.10353");
526
526
  } catch (e) {
527
527
  /* log fn threw an exception. All logger methods are no-ops. */
528
528
  return createLogger();
@@ -7304,12 +7304,9 @@
7304
7304
  }
7305
7305
  if (videoPreference) {
7306
7306
  allowedVideoRanges = videoPreference.allowedVideoRanges || VideoRangeValues.slice(0);
7307
- preferHDR = videoPreference.preferHDR !== undefined ? videoPreference.preferHDR : isHdrSupported();
7308
- if (preferHDR) {
7309
- allowedVideoRanges = allowedVideoRanges.filter(function (range) {
7310
- return range !== 'SDR';
7311
- });
7312
- } else {
7307
+ var allowAutoPreferHDR = allowedVideoRanges.join('') !== 'SDR' && !videoPreference.videoCodec;
7308
+ preferHDR = videoPreference.preferHDR !== undefined ? videoPreference.preferHDR : allowAutoPreferHDR && isHdrSupported();
7309
+ if (!preferHDR) {
7313
7310
  allowedVideoRanges = ['SDR'];
7314
7311
  }
7315
7312
  }
@@ -7323,13 +7320,15 @@
7323
7320
  var codecSets = Object.keys(codecTiers);
7324
7321
  var channelsPreference = audioPreference == null ? void 0 : audioPreference.channels;
7325
7322
  var audioCodecPreference = audioPreference == null ? void 0 : audioPreference.audioCodec;
7323
+ var videoCodecPreference = videoPreference == null ? void 0 : videoPreference.videoCodec;
7326
7324
  var preferStereo = channelsPreference && parseInt(channelsPreference) === 2;
7327
7325
  // Use first level set to determine stereo, and minimum resolution and framerate
7328
- var hasStereo = true;
7326
+ var hasStereo = false;
7329
7327
  var hasCurrentVideoRange = false;
7330
7328
  var minHeight = Infinity;
7331
7329
  var minFramerate = Infinity;
7332
7330
  var minBitrate = Infinity;
7331
+ var minIndex = Infinity;
7333
7332
  var selectedScore = 0;
7334
7333
  var videoRanges = [];
7335
7334
  var _getVideoSelectionOpt = getVideoSelectionOptions(currentVideoRange, videoPreference),
@@ -7337,7 +7336,7 @@
7337
7336
  allowedVideoRanges = _getVideoSelectionOpt.allowedVideoRanges;
7338
7337
  var _loop = function _loop() {
7339
7338
  var tier = codecTiers[codecSets[i]];
7340
- hasStereo = tier.channels[2] > 0;
7339
+ hasStereo || (hasStereo = tier.channels[2] > 0);
7341
7340
  minHeight = Math.min(minHeight, tier.minHeight);
7342
7341
  minFramerate = Math.min(minFramerate, tier.minFramerate);
7343
7342
  minBitrate = Math.min(minBitrate, tier.minBitrate);
@@ -7346,7 +7345,6 @@
7346
7345
  });
7347
7346
  if (matchingVideoRanges.length > 0) {
7348
7347
  hasCurrentVideoRange = true;
7349
- videoRanges = matchingVideoRanges;
7350
7348
  }
7351
7349
  };
7352
7350
  for (var i = codecSets.length; i--;) {
@@ -7361,7 +7359,6 @@
7361
7359
  // If there are no variants with matching preference, set currentVideoRange to undefined
7362
7360
  if (!hasCurrentVideoRange) {
7363
7361
  currentVideoRange = undefined;
7364
- videoRanges = [];
7365
7362
  }
7366
7363
  var codecSet = codecSets.reduce(function (selected, candidate) {
7367
7364
  // 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
@@ -7369,6 +7366,9 @@
7369
7366
  if (candidate === selected) {
7370
7367
  return selected;
7371
7368
  }
7369
+ videoRanges = hasCurrentVideoRange ? allowedVideoRanges.filter(function (range) {
7370
+ return candidateTier.videoRanges[range] > 0;
7371
+ }) : [];
7372
7372
  if (candidateTier.minBitrate > currentBw) {
7373
7373
  logStartCodecCandidateIgnored(candidate, "min bitrate of " + candidateTier.minBitrate + " > current estimate of " + currentBw);
7374
7374
  return selected;
@@ -7404,6 +7404,10 @@
7404
7404
  logStartCodecCandidateIgnored(candidate, "no variants with VIDEO-RANGE of " + JSON.stringify(videoRanges) + " found");
7405
7405
  return selected;
7406
7406
  }
7407
+ if (videoCodecPreference && candidate.indexOf(videoCodecPreference.substring(0, 4)) % 5 !== 0) {
7408
+ logStartCodecCandidateIgnored(candidate, "video codec preference \"" + videoCodecPreference + "\" not found");
7409
+ return selected;
7410
+ }
7407
7411
  if (candidateTier.maxScore < selectedScore) {
7408
7412
  logStartCodecCandidateIgnored(candidate, "max score of " + candidateTier.maxScore + " < selected max of " + selectedScore);
7409
7413
  return selected;
@@ -7412,6 +7416,7 @@
7412
7416
  if (selected && (codecsSetSelectionPreferenceValue(candidate) >= codecsSetSelectionPreferenceValue(selected) || candidateTier.fragmentError > codecTiers[selected].fragmentError)) {
7413
7417
  return selected;
7414
7418
  }
7419
+ minIndex = candidateTier.minIndex;
7415
7420
  selectedScore = candidateTier.maxScore;
7416
7421
  return candidate;
7417
7422
  }, undefined);
@@ -7420,7 +7425,8 @@
7420
7425
  videoRanges: videoRanges,
7421
7426
  preferHDR: preferHDR,
7422
7427
  minFramerate: minFramerate,
7423
- minBitrate: minBitrate
7428
+ minBitrate: minBitrate,
7429
+ minIndex: minIndex
7424
7430
  };
7425
7431
  }
7426
7432
  function logStartCodecCandidateIgnored(codeSet, reason) {
@@ -7458,7 +7464,7 @@
7458
7464
  });
7459
7465
  }
7460
7466
  function getCodecTiers(levels, audioTracksByGroup, minAutoLevel, maxAutoLevel) {
7461
- return levels.slice(minAutoLevel, maxAutoLevel + 1).reduce(function (tiers, level) {
7467
+ return levels.slice(minAutoLevel, maxAutoLevel + 1).reduce(function (tiers, level, index) {
7462
7468
  if (!level.codecSet) {
7463
7469
  return tiers;
7464
7470
  }
@@ -7469,6 +7475,7 @@
7469
7475
  minBitrate: Infinity,
7470
7476
  minHeight: Infinity,
7471
7477
  minFramerate: Infinity,
7478
+ minIndex: index,
7472
7479
  maxScore: 0,
7473
7480
  videoRanges: {
7474
7481
  SDR: 0
@@ -7484,6 +7491,7 @@
7484
7491
  var lesserWidthOrHeight = Math.min(level.height, level.width);
7485
7492
  tier.minHeight = Math.min(tier.minHeight, lesserWidthOrHeight);
7486
7493
  tier.minFramerate = Math.min(tier.minFramerate, level.frameRate);
7494
+ tier.minIndex = Math.min(tier.minIndex, index);
7487
7495
  tier.maxScore = Math.max(tier.maxScore, level.score);
7488
7496
  tier.fragmentError += level.fragmentError;
7489
7497
  tier.videoRanges[level.videoRange] = (tier.videoRanges[level.videoRange] || 0) + 1;
@@ -8037,6 +8045,7 @@
8037
8045
  var audioPreference = config.audioPreference,
8038
8046
  videoPreference = config.videoPreference;
8039
8047
  var audioTracksByGroup = this.audioTracksByGroup || (this.audioTracksByGroup = getAudioTracksByGroup(allAudioTracks));
8048
+ var minStartIndex = -1;
8040
8049
  if (firstSelection) {
8041
8050
  if (this.firstSelection !== -1) {
8042
8051
  return this.firstSelection;
@@ -8047,7 +8056,9 @@
8047
8056
  videoRanges = startTier.videoRanges,
8048
8057
  minFramerate = startTier.minFramerate,
8049
8058
  minBitrate = startTier.minBitrate,
8059
+ minIndex = startTier.minIndex,
8050
8060
  preferHDR = startTier.preferHDR;
8061
+ minStartIndex = minIndex;
8051
8062
  currentCodecSet = codecSet;
8052
8063
  currentVideoRange = preferHDR ? videoRanges[videoRanges.length - 1] : videoRanges[0];
8053
8064
  currentFrameRate = minFramerate;
@@ -8096,8 +8107,10 @@
8096
8107
  // skip candidates which change codec-family or video-range,
8097
8108
  // and which decrease or increase frame-rate for up and down-switch respectfully
8098
8109
  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)) {
8099
- levelsSkipped.push(i);
8100
- return 0; // continue
8110
+ if (firstSelection && i !== minStartIndex) {
8111
+ levelsSkipped.push(i);
8112
+ return 0; // continue
8113
+ }
8101
8114
  }
8102
8115
  var levelDetails = levelInfo.details;
8103
8116
  var avgDuration = (partCurrent ? levelDetails == null ? void 0 : levelDetails.partTarget : levelDetails == null ? void 0 : levelDetails.averagetargetduration) || currentFragDuration;
@@ -8132,7 +8145,7 @@
8132
8145
  if (levelsSkipped.length) {
8133
8146
  _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);
8134
8147
  }
8135
- _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);
8148
+ _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);
8136
8149
  }
8137
8150
  if (firstSelection) {
8138
8151
  _this3.firstSelection = i;
@@ -12275,6 +12288,20 @@
12275
12288
  length: 0
12276
12289
  };
12277
12290
  };
12291
+ _proto.getLastNalUnit = function getLastNalUnit(samples) {
12292
+ var _VideoSample;
12293
+ var VideoSample = this.VideoSample;
12294
+ var lastUnit;
12295
+ // try to fallback to previous sample if current one is empty
12296
+ if (!VideoSample || VideoSample.units.length === 0) {
12297
+ VideoSample = samples[samples.length - 1];
12298
+ }
12299
+ if ((_VideoSample = VideoSample) != null && _VideoSample.units) {
12300
+ var units = VideoSample.units;
12301
+ lastUnit = units[units.length - 1];
12302
+ }
12303
+ return lastUnit;
12304
+ };
12278
12305
  _proto.pushAccessUnit = function pushAccessUnit(VideoSample, videoTrack) {
12279
12306
  if (VideoSample.units.length && VideoSample.frame) {
12280
12307
  // if sample does not have PTS/DTS, patch with last sample PTS/DTS
@@ -12297,7 +12324,7 @@
12297
12324
  logger.log(VideoSample.pts + '/' + VideoSample.dts + ':' + VideoSample.debug);
12298
12325
  }
12299
12326
  };
12300
- _proto.parseNALu = function parseNALu(track, array, last) {
12327
+ _proto.parseNALu = function parseNALu(track, array, endOfSegment) {
12301
12328
  var len = array.byteLength;
12302
12329
  var state = track.naluState || 0;
12303
12330
  var lastState = state;
@@ -12339,10 +12366,6 @@
12339
12366
  data: array.subarray(lastUnitStart, overflow),
12340
12367
  type: lastUnitType
12341
12368
  };
12342
- if (track.lastNalu) {
12343
- units.push(track.lastNalu);
12344
- track.lastNalu = null;
12345
- }
12346
12369
  // logger.log('pushing NALU, type/size:' + unit.type + '/' + unit.data.byteLength);
12347
12370
  units.push(unit);
12348
12371
  } else {
@@ -12350,7 +12373,7 @@
12350
12373
  // first check if start code delimiter is overlapping between 2 PES packets,
12351
12374
  // ie it started in last packet (lastState not zero)
12352
12375
  // and ended at the beginning of this PES packet (i <= 4 - lastState)
12353
- var lastUnit = track.lastNalu;
12376
+ var lastUnit = this.getLastNalUnit(track.samples);
12354
12377
  if (lastUnit) {
12355
12378
  if (lastState && i <= 4 - lastState) {
12356
12379
  // start delimiter overlapping between PES packets
@@ -12367,8 +12390,6 @@
12367
12390
  // logger.log('first NALU found with overflow:' + overflow);
12368
12391
  lastUnit.data = appendUint8Array(lastUnit.data, array.subarray(0, overflow));
12369
12392
  lastUnit.state = 0;
12370
- units.push(lastUnit);
12371
- track.lastNalu = null;
12372
12393
  }
12373
12394
  }
12374
12395
  }
@@ -12393,21 +12414,15 @@
12393
12414
  type: lastUnitType,
12394
12415
  state: state
12395
12416
  };
12396
- if (!last) {
12397
- track.lastNalu = _unit;
12398
- // logger.log('store NALu to push it on next PES');
12399
- } else {
12400
- units.push(_unit);
12401
- // logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state);
12402
- }
12403
- } else if (units.length === 0) {
12404
- // no NALu found
12417
+ units.push(_unit);
12418
+ // logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state);
12419
+ }
12420
+ // no NALu found
12421
+ if (units.length === 0) {
12405
12422
  // append pes.data to previous NAL unit
12406
- var _lastUnit = track.lastNalu;
12423
+ var _lastUnit = this.getLastNalUnit(track.samples);
12407
12424
  if (_lastUnit) {
12408
12425
  _lastUnit.data = appendUint8Array(_lastUnit.data, array);
12409
- units.push(_lastUnit);
12410
- track.lastNalu = null;
12411
12426
  }
12412
12427
  }
12413
12428
  track.naluState = state;
@@ -12577,9 +12592,9 @@
12577
12592
  }
12578
12593
  _inheritsLoose(AvcVideoParser, _BaseVideoParser);
12579
12594
  var _proto = AvcVideoParser.prototype;
12580
- _proto.parsePES = function parsePES(track, textTrack, pes, last, duration) {
12595
+ _proto.parsePES = function parsePES(track, textTrack, pes, endOfSegment, duration) {
12581
12596
  var _this = this;
12582
- var units = this.parseNALu(track, pes.data, last);
12597
+ var units = this.parseNALu(track, pes.data, endOfSegment);
12583
12598
  var VideoSample = this.VideoSample;
12584
12599
  var push;
12585
12600
  var spsfound = false;
@@ -12709,7 +12724,7 @@
12709
12724
  }
12710
12725
  });
12711
12726
  // if last PES packet, push samples
12712
- if (last && VideoSample) {
12727
+ if (endOfSegment && VideoSample) {
12713
12728
  this.pushAccessUnit(VideoSample, track);
12714
12729
  this.VideoSample = null;
12715
12730
  }
@@ -12916,9 +12931,9 @@
12916
12931
  }
12917
12932
  _inheritsLoose(HevcVideoParser, _BaseVideoParser);
12918
12933
  var _proto = HevcVideoParser.prototype;
12919
- _proto.parsePES = function parsePES(track, textTrack, pes, last, duration) {
12934
+ _proto.parsePES = function parsePES(track, textTrack, pes, endOfSegment, duration) {
12920
12935
  var _this2 = this;
12921
- var units = this.parseNALu(track, pes.data, last);
12936
+ var units = this.parseNALu(track, pes.data, endOfSegment);
12922
12937
  var VideoSample = this.VideoSample;
12923
12938
  var push;
12924
12939
  var spsfound = false;
@@ -13080,7 +13095,7 @@
13080
13095
  }
13081
13096
  });
13082
13097
  // if last PES packet, push samples
13083
- if (last && VideoSample) {
13098
+ if (endOfSegment && VideoSample) {
13084
13099
  this.pushAccessUnit(VideoSample, track);
13085
13100
  this.VideoSample = null;
13086
13101
  }
@@ -30129,7 +30144,7 @@
30129
30144
  */
30130
30145
  _proto.setAudioOption = function setAudioOption(audioOption) {
30131
30146
  var _this$audioTrackContr;
30132
- return (_this$audioTrackContr = this.audioTrackController) == null ? void 0 : _this$audioTrackContr.setAudioOption(audioOption);
30147
+ return ((_this$audioTrackContr = this.audioTrackController) == null ? void 0 : _this$audioTrackContr.setAudioOption(audioOption)) || null;
30133
30148
  }
30134
30149
  /**
30135
30150
  * Find and select the best matching subtitle track, making a level switch when a Group change is necessary.
@@ -30137,8 +30152,7 @@
30137
30152
  */;
30138
30153
  _proto.setSubtitleOption = function setSubtitleOption(subtitleOption) {
30139
30154
  var _this$subtitleTrackCo;
30140
- (_this$subtitleTrackCo = this.subtitleTrackController) == null ? void 0 : _this$subtitleTrackCo.setSubtitleOption(subtitleOption);
30141
- return null;
30155
+ return ((_this$subtitleTrackCo = this.subtitleTrackController) == null ? void 0 : _this$subtitleTrackCo.setSubtitleOption(subtitleOption)) || null;
30142
30156
  }
30143
30157
 
30144
30158
  /**
@@ -30663,7 +30677,7 @@
30663
30677
  * Get the video-dev/hls.js package version.
30664
30678
  */
30665
30679
  function get() {
30666
- return "1.5.12-0.canary.10351";
30680
+ return "1.5.12-0.canary.10353";
30667
30681
  }
30668
30682
  }, {
30669
30683
  key: "Events",
package/dist/hls.js.d.ts CHANGED
@@ -3156,6 +3156,7 @@ declare const VideoRangeValues: readonly ["SDR", "PQ", "HLG"];
3156
3156
  export declare type VideoSelectionOption = {
3157
3157
  preferHDR?: boolean;
3158
3158
  allowedVideoRanges?: Array<VideoRange>;
3159
+ videoCodec?: string;
3159
3160
  };
3160
3161
 
3161
3162
  export { }