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

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.
@@ -31,8 +31,10 @@ import { Logger } from '../utils/logger';
31
31
  import { isCompatibleTrackChange } from '../utils/mediasource-helper';
32
32
  import { getBasicSelectionOption } from '../utils/rendition-helper';
33
33
  import { stringify } from '../utils/safe-json-stringify';
34
- import type { InterstitialPlayer } from './interstitial-player';
35
- import type { HlsConfig } from '../config';
34
+ import type {
35
+ HlsAssetPlayerConfig,
36
+ InterstitialPlayer,
37
+ } from './interstitial-player';
36
38
  import type Hls from '../hls';
37
39
  import type { LevelDetails } from '../loader/level-details';
38
40
  import type { SourceBufferName } from '../types/buffer';
@@ -1580,7 +1582,7 @@ export default class InterstitialsController
1580
1582
  `INTERSTITIALS_UPDATED (${
1581
1583
  interstitialEvents.length
1582
1584
  }): ${interstitialEvents}
1583
- Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1585
+ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timelinePos}`,
1584
1586
  );
1585
1587
  }
1586
1588
  if (removedIds.length) {
@@ -1607,11 +1609,14 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1607
1609
 
1608
1610
  // Update schedule item references
1609
1611
  // Do not replace Interstitial playingItem without a match - used for INTERSTITIAL_ASSET_ENDED and INTERSTITIAL_ENDED
1612
+ let trimInPlaceForPlayout: null | (() => void) = null;
1610
1613
  if (playingItem) {
1611
1614
  const updatedPlayingItem = this.updateItem(playingItem, this.timelinePos);
1612
1615
  if (this.itemsMatch(playingItem, updatedPlayingItem)) {
1613
1616
  this.playingItem = updatedPlayingItem;
1614
1617
  this.waitingItem = this.endedItem = null;
1618
+ trimInPlaceForPlayout = () =>
1619
+ this.trimInPlace(updatedPlayingItem, playingItem);
1615
1620
  }
1616
1621
  } else {
1617
1622
  // Clear waitingItem if it has been removed from the schedule
@@ -1627,6 +1632,8 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1627
1632
  );
1628
1633
  if (this.itemsMatch(bufferingItem, updatedBufferingItem)) {
1629
1634
  this.bufferingItem = updatedBufferingItem;
1635
+ trimInPlaceForPlayout ||= () =>
1636
+ this.trimInPlace(updatedBufferingItem, bufferingItem);
1630
1637
  } else if (bufferingItem.event) {
1631
1638
  // Interstitial removed from schedule (Live -> VOD or other scenario where Start Date is outside the range of VOD Playlist)
1632
1639
  this.bufferingItem = this.playingItem;
@@ -1659,6 +1666,10 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1659
1666
  return;
1660
1667
  }
1661
1668
 
1669
+ if (trimInPlaceForPlayout) {
1670
+ trimInPlaceForPlayout();
1671
+ }
1672
+
1662
1673
  // Check is buffered to new Interstitial event boundary
1663
1674
  // (Live update publishes Interstitial with new segment)
1664
1675
  this.checkBuffer();
@@ -1678,6 +1689,36 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
1678
1689
  return null;
1679
1690
  }
1680
1691
 
1692
+ private trimInPlace(
1693
+ updatedItem: InterstitialScheduleItem | null,
1694
+ itemBeforeUpdate: InterstitialScheduleItem,
1695
+ ) {
1696
+ if (
1697
+ this.isInterstitial(updatedItem) &&
1698
+ updatedItem.event.appendInPlace &&
1699
+ itemBeforeUpdate.end - updatedItem.end > 0.25
1700
+ ) {
1701
+ updatedItem.event.assetList.forEach((asset, index) => {
1702
+ if (updatedItem.event.isAssetPastPlayoutLimit(index)) {
1703
+ this.clearAssetPlayer(asset.identifier, null);
1704
+ }
1705
+ });
1706
+ const flushStart = updatedItem.end + 0.25;
1707
+ const bufferInfo = BufferHelper.bufferInfo(
1708
+ this.primaryMedia,
1709
+ flushStart,
1710
+ 0,
1711
+ );
1712
+ if (
1713
+ bufferInfo.end > flushStart ||
1714
+ (bufferInfo.nextStart || 0) > flushStart
1715
+ ) {
1716
+ this.attachPrimary(flushStart, null);
1717
+ this.flushFrontBuffer(flushStart);
1718
+ }
1719
+ }
1720
+ }
1721
+
1681
1722
  private itemsMatch(
1682
1723
  a: InterstitialScheduleItem,
1683
1724
  b: InterstitialScheduleItem | null | undefined,
@@ -2101,7 +2142,7 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
2101
2142
  }
2102
2143
  }
2103
2144
  const assetId = assetItem.identifier;
2104
- const playerConfig: Partial<HlsConfig> = {
2145
+ const playerConfig: HlsAssetPlayerConfig = {
2105
2146
  ...userConfig,
2106
2147
  autoStartLoad: true,
2107
2148
  startFragPrefetch: true,
@@ -2505,10 +2546,6 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
2505
2546
  playingItem ? segmentToString(playingItem) : '<none>'
2506
2547
  } error: ${interstitial.error}`,
2507
2548
  );
2508
- if (interstitial.appendInPlace) {
2509
- this.attachPrimary(flushStart, null);
2510
- this.flushFrontBuffer(flushStart);
2511
- }
2512
2549
  let timelinePos = this.timelinePos;
2513
2550
  if (timelinePos === -1) {
2514
2551
  timelinePos = this.hls.startPosition;
@@ -2520,6 +2557,10 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))}`,
2520
2557
  } else {
2521
2558
  this.clearInterstitial(interstitial, null);
2522
2559
  }
2560
+ if (interstitial.appendInPlace) {
2561
+ this.attachPrimary(flushStart, null);
2562
+ this.flushFrontBuffer(flushStart);
2563
+ }
2523
2564
  } else {
2524
2565
  this.checkStart();
2525
2566
  }
package/src/hls.ts CHANGED
@@ -1334,6 +1334,7 @@ export type {
1334
1334
  } from './controller/error-controller';
1335
1335
  export type {
1336
1336
  HlsAssetPlayer,
1337
+ HlsAssetPlayerConfig,
1337
1338
  InterstitialPlayer,
1338
1339
  } from './controller/interstitial-player';
1339
1340
  export type { PlayheadTimes } from './controller/interstitials-controller';