hls.js 1.6.3-0.canary.11232 → 1.6.3-0.canary.11233

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.
@@ -1580,7 +1580,7 @@ export default class InterstitialsController
1580
1580
  `INTERSTITIALS_UPDATED (${
1581
1581
  interstitialEvents.length
1582
1582
  }): ${interstitialEvents}
1583
- Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1583
+ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timelinePos}`,
1584
1584
  );
1585
1585
  }
1586
1586
  if (removedIds.length) {
@@ -1607,11 +1607,14 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1607
1607
 
1608
1608
  // Update schedule item references
1609
1609
  // Do not replace Interstitial playingItem without a match - used for INTERSTITIAL_ASSET_ENDED and INTERSTITIAL_ENDED
1610
+ let trimInPlaceForPlayout: null | (() => void) = null;
1610
1611
  if (playingItem) {
1611
1612
  const updatedPlayingItem = this.updateItem(playingItem, this.timelinePos);
1612
1613
  if (this.itemsMatch(playingItem, updatedPlayingItem)) {
1613
1614
  this.playingItem = updatedPlayingItem;
1614
1615
  this.waitingItem = this.endedItem = null;
1616
+ trimInPlaceForPlayout = () =>
1617
+ this.trimInPlace(updatedPlayingItem, playingItem);
1615
1618
  }
1616
1619
  } else {
1617
1620
  // Clear waitingItem if it has been removed from the schedule
@@ -1627,6 +1630,8 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1627
1630
  );
1628
1631
  if (this.itemsMatch(bufferingItem, updatedBufferingItem)) {
1629
1632
  this.bufferingItem = updatedBufferingItem;
1633
+ trimInPlaceForPlayout ||= () =>
1634
+ this.trimInPlace(updatedBufferingItem, bufferingItem);
1630
1635
  } else if (bufferingItem.event) {
1631
1636
  // Interstitial removed from schedule (Live -> VOD or other scenario where Start Date is outside the range of VOD Playlist)
1632
1637
  this.bufferingItem = this.playingItem;
@@ -1659,6 +1664,10 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1659
1664
  return;
1660
1665
  }
1661
1666
 
1667
+ if (trimInPlaceForPlayout) {
1668
+ trimInPlaceForPlayout();
1669
+ }
1670
+
1662
1671
  // Check is buffered to new Interstitial event boundary
1663
1672
  // (Live update publishes Interstitial with new segment)
1664
1673
  this.checkBuffer();
@@ -1678,6 +1687,36 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1678
1687
  return null;
1679
1688
  }
1680
1689
 
1690
+ private trimInPlace(
1691
+ updatedItem: InterstitialScheduleItem | null,
1692
+ itemBeforeUpdate: InterstitialScheduleItem,
1693
+ ) {
1694
+ if (
1695
+ this.isInterstitial(updatedItem) &&
1696
+ updatedItem.event.appendInPlace &&
1697
+ itemBeforeUpdate.end - updatedItem.end > 0.25
1698
+ ) {
1699
+ updatedItem.event.assetList.forEach((asset, index) => {
1700
+ if (updatedItem.event.isAssetPastPlayoutLimit(index)) {
1701
+ this.clearAssetPlayer(asset.identifier, null);
1702
+ }
1703
+ });
1704
+ const flushStart = updatedItem.end + 0.25;
1705
+ const bufferInfo = BufferHelper.bufferInfo(
1706
+ this.primaryMedia,
1707
+ flushStart,
1708
+ 0,
1709
+ );
1710
+ if (
1711
+ bufferInfo.end > flushStart ||
1712
+ (bufferInfo.nextStart || 0) > flushStart
1713
+ ) {
1714
+ this.attachPrimary(flushStart, null);
1715
+ this.flushFrontBuffer(flushStart);
1716
+ }
1717
+ }
1718
+ }
1719
+
1681
1720
  private itemsMatch(
1682
1721
  a: InterstitialScheduleItem,
1683
1722
  b: InterstitialScheduleItem | null | undefined,
@@ -2505,10 +2544,6 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
2505
2544
  playingItem ? segmentToString(playingItem) : '<none>'
2506
2545
  } error: ${interstitial.error}`,
2507
2546
  );
2508
- if (interstitial.appendInPlace) {
2509
- this.attachPrimary(flushStart, null);
2510
- this.flushFrontBuffer(flushStart);
2511
- }
2512
2547
  let timelinePos = this.timelinePos;
2513
2548
  if (timelinePos === -1) {
2514
2549
  timelinePos = this.hls.startPosition;
@@ -2520,6 +2555,10 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
2520
2555
  } else {
2521
2556
  this.clearInterstitial(interstitial, null);
2522
2557
  }
2558
+ if (interstitial.appendInPlace) {
2559
+ this.attachPrimary(flushStart, null);
2560
+ this.flushFrontBuffer(flushStart);
2561
+ }
2523
2562
  } else {
2524
2563
  this.checkStart();
2525
2564
  }