hls.js 1.6.0-beta.2.0.canary.10844 → 1.6.0-beta.2.0.canary.10851

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.mjs CHANGED
@@ -401,7 +401,7 @@ function enableLogs(debugConfig, context, id) {
401
401
  // Some browsers don't allow to use bind on console object anyway
402
402
  // fallback to default if needed
403
403
  try {
404
- newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.6.0-beta.2.0.canary.10844"}`);
404
+ newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.6.0-beta.2.0.canary.10851"}`);
405
405
  } catch (e) {
406
406
  /* log fn threw an exception. All logger methods are no-ops. */
407
407
  return createLogger();
@@ -6426,7 +6426,7 @@ class LevelDetails {
6426
6426
  return this.endSN;
6427
6427
  }
6428
6428
  get expired() {
6429
- if (this.live && this.age) {
6429
+ if (this.live && this.age && this.misses < 3) {
6430
6430
  const playlistWindowDuration = this.partEnd - this.fragmentStart;
6431
6431
  return this.age > Math.max(playlistWindowDuration, this.totalduration) + this.levelTargetDuration;
6432
6432
  }
@@ -7568,6 +7568,9 @@ function updateFragPTSDTS(details, frag, startPTS, endPTS, startDTS, endDTS) {
7568
7568
  return drift;
7569
7569
  }
7570
7570
  function mergeDetails(oldDetails, newDetails) {
7571
+ if (oldDetails === newDetails) {
7572
+ return;
7573
+ }
7571
7574
  // Track the last initSegment processed. Initialize it to the last one on the timeline.
7572
7575
  let currentInitSegment = null;
7573
7576
  const oldFragments = oldDetails.fragments;
@@ -8947,7 +8950,7 @@ class BaseStreamController extends TaskLoop {
8947
8950
  frag = this.getInitialLiveFragment(levelDetails, fragments);
8948
8951
  const mainStart = this.hls.startPosition;
8949
8952
  const liveSyncPosition = this.hls.liveSyncPosition;
8950
- const startPosition = frag ? (mainStart !== -1 ? mainStart : liveSyncPosition) || frag.start : pos;
8953
+ const startPosition = frag ? (mainStart !== -1 && mainStart >= start ? mainStart : liveSyncPosition) || frag.start : pos;
8951
8954
  this.log(`Setting startPosition to ${startPosition} to match initial live edge. mainStart: ${mainStart} liveSyncPosition: ${liveSyncPosition} frag.start: ${(_frag = frag) == null ? void 0 : _frag.start}`);
8952
8955
  this.startPosition = this.nextLoadPosition = startPosition;
8953
8956
  }
@@ -9844,7 +9847,7 @@ var eventemitter3 = {exports: {}};
9844
9847
  var eventemitter3Exports = eventemitter3.exports;
9845
9848
  var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
9846
9849
 
9847
- const version = "1.6.0-beta.2.0.canary.10844";
9850
+ const version = "1.6.0-beta.2.0.canary.10851";
9848
9851
 
9849
9852
  // ensure the worker ends up in the bundle
9850
9853
  // If the worker should not be included this gets aliased to empty.js
@@ -15289,7 +15292,7 @@ class PassThroughRemuxer {
15289
15292
  const duration = getDuration(data, initData);
15290
15293
  const startDTS = getStartDTS(initData, data);
15291
15294
  const decodeTime = startDTS === null ? timeOffset : startDTS;
15292
- if (isInvalidInitPts(initPTS, decodeTime, timeOffset, duration) || initSegment.timescale !== initPTS.timescale && accurateTimeOffset) {
15295
+ if ((accurateTimeOffset || !initPTS) && (isInvalidInitPts(initPTS, decodeTime, timeOffset, duration) || initSegment.timescale !== initPTS.timescale)) {
15293
15296
  initSegment.initPTS = decodeTime - timeOffset;
15294
15297
  if (initPTS && initPTS.timescale === 1) {
15295
15298
  this.logger.warn(`Adjusting initPTS @${timeOffset} from ${initPTS.baseTime / initPTS.timescale} to ${initSegment.initPTS}`);
@@ -16489,41 +16492,44 @@ class AudioStreamController extends BaseStreamController {
16489
16492
  const cachedTrackLoadedData = this.cachedTrackLoadedData;
16490
16493
  if (cachedTrackLoadedData) {
16491
16494
  this.cachedTrackLoadedData = null;
16492
- this.hls.trigger(Events.AUDIO_TRACK_LOADED, cachedTrackLoadedData);
16495
+ this.onAudioTrackLoaded(Events.AUDIO_TRACK_LOADED, cachedTrackLoadedData);
16493
16496
  }
16494
16497
  }
16495
16498
  onAudioTrackLoaded(event, data) {
16496
- var _track$details;
16499
+ var _trackLevel$details;
16497
16500
  const {
16498
16501
  levels
16499
16502
  } = this;
16500
16503
  const {
16501
16504
  details: newDetails,
16502
- id: trackId
16505
+ id: trackId,
16506
+ groupId,
16507
+ track
16503
16508
  } = data;
16509
+ if (!levels) {
16510
+ this.warn(`Audio tracks reset while loading track ${trackId} "${track.name}" of "${groupId}"`);
16511
+ return;
16512
+ }
16504
16513
  const mainDetails = this.mainDetails;
16505
- if (!mainDetails || mainDetails.expired || newDetails.endCC > mainDetails.endCC) {
16514
+ if (!mainDetails || newDetails.endCC > mainDetails.endCC || mainDetails.expired) {
16506
16515
  this.cachedTrackLoadedData = data;
16507
16516
  if (this.state !== State.STOPPED) {
16508
16517
  this.state = State.WAITING_TRACK;
16509
16518
  }
16510
16519
  return;
16511
16520
  }
16512
- if (!levels) {
16513
- this.warn(`Audio tracks were reset while loading level ${trackId}`);
16514
- return;
16515
- }
16516
- this.log(`Audio track ${trackId} loaded [${newDetails.startSN},${newDetails.endSN}]${newDetails.lastPartSn ? `[part-${newDetails.lastPartSn}-${newDetails.lastPartIndex}]` : ''},duration:${newDetails.totalduration}`);
16517
- const track = levels[trackId];
16521
+ this.cachedTrackLoadedData = null;
16522
+ this.log(`Audio track ${trackId} "${track.name}" of "${groupId}" loaded [${newDetails.startSN},${newDetails.endSN}]${newDetails.lastPartSn ? `[part-${newDetails.lastPartSn}-${newDetails.lastPartIndex}]` : ''},duration:${newDetails.totalduration}`);
16523
+ const trackLevel = levels[trackId];
16518
16524
  let sliding = 0;
16519
- if (newDetails.live || (_track$details = track.details) != null && _track$details.live) {
16525
+ if (newDetails.live || (_trackLevel$details = trackLevel.details) != null && _trackLevel$details.live) {
16520
16526
  this.checkLiveUpdate(newDetails);
16521
16527
  if (newDetails.deltaUpdateFailed) {
16522
16528
  return;
16523
16529
  }
16524
- if (track.details) {
16530
+ if (trackLevel.details) {
16525
16531
  var _this$levelLastLoaded;
16526
- sliding = this.alignPlaylists(newDetails, track.details, (_this$levelLastLoaded = this.levelLastLoaded) == null ? void 0 : _this$levelLastLoaded.details);
16532
+ sliding = this.alignPlaylists(newDetails, trackLevel.details, (_this$levelLastLoaded = this.levelLastLoaded) == null ? void 0 : _this$levelLastLoaded.details);
16527
16533
  }
16528
16534
  if (!newDetails.alignedSliding) {
16529
16535
  // Align audio rendition with the "main" playlist on discontinuity change
@@ -16535,8 +16541,8 @@ class AudioStreamController extends BaseStreamController {
16535
16541
  sliding = newDetails.fragmentStart;
16536
16542
  }
16537
16543
  }
16538
- track.details = newDetails;
16539
- this.levelLastLoaded = track;
16544
+ trackLevel.details = newDetails;
16545
+ this.levelLastLoaded = trackLevel;
16540
16546
 
16541
16547
  // compute start position if we are aligned with the main playlist
16542
16548
  if (!this.startFragRequested) {
@@ -16873,10 +16879,10 @@ class AudioStreamController extends BaseStreamController {
16873
16879
 
16874
16880
  // we force a frag loading in audio switch as fragment tracker might not have evicted previous frags in case of quick audio switch
16875
16881
  if (this.switchingTrack || fragState === FragmentState.NOT_LOADED || fragState === FragmentState.PARTIAL) {
16876
- var _track$details2;
16882
+ var _track$details;
16877
16883
  if (!isMediaFragment(frag)) {
16878
16884
  this._loadInitSegment(frag, track);
16879
- } else if ((_track$details2 = track.details) != null && _track$details2.live && !this.initPTS[frag.cc]) {
16885
+ } else if ((_track$details = track.details) != null && _track$details.live && !this.initPTS[frag.cc]) {
16880
16886
  this.log(`Waiting for video PTS in continuity counter ${frag.cc} of live stream before loading audio fragment ${frag.sn} of level ${this.trackId}`);
16881
16887
  this.state = State.WAITING_INIT_PTS;
16882
16888
  const mainDetails = this.mainDetails;
@@ -16898,9 +16904,14 @@ class AudioStreamController extends BaseStreamController {
16898
16904
  const bufferedAttributes = bufferedTrack == null ? void 0 : bufferedTrack.attrs;
16899
16905
  const switchAttributes = switchingTrack.attrs;
16900
16906
  if (media && bufferedAttributes && (bufferedAttributes.CHANNELS !== switchAttributes.CHANNELS || bufferedTrack.name !== switchingTrack.name || bufferedTrack.lang !== switchingTrack.lang)) {
16901
- this.log('Switching audio track : flushing all audio');
16902
- super.flushMainBuffer(0, Number.POSITIVE_INFINITY, 'audio');
16903
- this.bufferedTrack = null;
16907
+ if (useAlternateAudio(switchingTrack.url, this.hls)) {
16908
+ this.log('Switching audio track : flushing all audio');
16909
+ super.flushMainBuffer(0, Number.POSITIVE_INFINITY, 'audio');
16910
+ this.bufferedTrack = null;
16911
+ } else {
16912
+ // Main is being buffered. Set bufferedTrack so that it is flushed when switching back to alt-audio
16913
+ this.bufferedTrack = switchingTrack;
16914
+ }
16904
16915
  }
16905
16916
  }
16906
16917
  completeAudioSwitch(switchingTrack) {
@@ -31820,12 +31831,17 @@ class StreamController extends BaseStreamController {
31820
31831
  }
31821
31832
  // If switching from alt to main audio, flush all audio and trigger track switched
31822
31833
  if (fromAltAudio) {
31834
+ this.fragmentTracker.removeAllFragments();
31835
+ hls.once(Events.BUFFER_FLUSHED, () => {
31836
+ var _this$hls;
31837
+ (_this$hls = this.hls) == null ? void 0 : _this$hls.trigger(Events.AUDIO_TRACK_SWITCHED, data);
31838
+ });
31823
31839
  hls.trigger(Events.BUFFER_FLUSHING, {
31824
31840
  startOffset: 0,
31825
31841
  endOffset: Number.POSITIVE_INFINITY,
31826
31842
  type: null
31827
31843
  });
31828
- this.fragmentTracker.removeAllFragments();
31844
+ return;
31829
31845
  }
31830
31846
  hls.trigger(Events.AUDIO_TRACK_SWITCHED, data);
31831
31847
  } else {