Skip to content

Commit e6e17aa

Browse files
committed
Simplify asset list progression and make interstitial logging more consistent
#7180
1 parent 7ba84fd commit e6e17aa

File tree

2 files changed

+29
-44
lines changed

2 files changed

+29
-44
lines changed

src/controller/interstitials-controller.ts

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,17 +1044,7 @@ export default class InterstitialsController
10441044
if (interstitial) {
10451045
const itemIndex = schedule.findEventIndex(parentIdentifier);
10461046
const assetListIndex = schedule.findAssetIndex(interstitial, time);
1047-
const validAssetIndex = getNextAssetIndex(
1048-
interstitial,
1049-
assetListIndex - 1,
1050-
true,
1051-
);
1052-
if (validAssetIndex === -1) {
1053-
// If -1 then there is no valid asset to play
1054-
this.advanceAfterAssetEnded(interstitial, itemIndex, assetListIndex);
1055-
return;
1056-
}
1057-
this.setSchedulePosition(itemIndex, validAssetIndex);
1047+
this.advanceAfterAssetEnded(interstitial, itemIndex, assetListIndex - 1);
10581048
}
10591049
}
10601050

@@ -1174,17 +1164,15 @@ export default class InterstitialsController
11741164
interstitial,
11751165
this.timelinePos,
11761166
);
1177-
const validAssetListIndex = getNextAssetIndex(
1167+
const assetIndexCandidate = getNextAssetIndex(
11781168
interstitial,
11791169
assetListIndex - 1,
1180-
true,
11811170
);
1182-
if (validAssetListIndex === -1) {
1183-
// If -1 then there is no valid asset to play
1171+
if (interstitial.isAssetPastPlayoutLimit(assetIndexCandidate)) {
11841172
this.advanceAfterAssetEnded(interstitial, index, assetListIndex);
11851173
return;
11861174
}
1187-
assetListIndex = validAssetListIndex;
1175+
assetListIndex = assetIndexCandidate;
11881176
}
11891177
// Ensure Interstitial is enqueued
11901178
const waitingItem = this.waitingItem;
@@ -1334,7 +1322,7 @@ export default class InterstitialsController
13341322
if (!scheduleItems) {
13351323
return;
13361324
}
1337-
this.log(`resumed ${segmentToString(scheduledItem)}`);
1325+
this.log(`INTERSTITIALS_PRIMARY_RESUMED ${segmentToString(scheduledItem)}`);
13381326
this.hls.trigger(Events.INTERSTITIALS_PRIMARY_RESUMED, {
13391327
schedule: scheduleItems.slice(0),
13401328
scheduleIndex: index,
@@ -1596,7 +1584,7 @@ export default class InterstitialsController
15961584
const interstitialsUpdated = !!(
15971585
interstitialEvents.length || removedIds.length
15981586
);
1599-
if (interstitialsUpdated) {
1587+
if (interstitialsUpdated || previousItems) {
16001588
this.log(
16011589
`INTERSTITIALS_UPDATED (${
16021590
interstitialEvents.length
@@ -1893,16 +1881,16 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
18931881
item.start,
18941882
Math.min(item.end, this.timelinePos),
18951883
);
1884+
const timeRemaining = bufferingPlayer
1885+
? bufferingPlayer.remaining
1886+
: bufferingLast
1887+
? bufferingLast.end - this.timelinePos
1888+
: 0;
1889+
this.log(
1890+
`INTERSTITIALS_BUFFERED_TO_BOUNDARY ${segmentToString(item)}` +
1891+
(bufferingLast ? ` (${timeRemaining.toFixed(2)} remaining)` : ''),
1892+
);
18961893
if (!this.playbackDisabled) {
1897-
const timeRemaining = bufferingPlayer
1898-
? bufferingPlayer.remaining
1899-
: bufferingLast
1900-
? bufferingLast.end - this.timelinePos
1901-
: 0;
1902-
this.log(
1903-
`buffered to boundary ${segmentToString(item)}` +
1904-
(bufferingLast ? ` (${timeRemaining.toFixed(2)} remaining)` : ''),
1905-
);
19061894
if (isInterstitial) {
19071895
// primary fragment loading will exit early in base-stream-controller while `bufferingItem` is set to an Interstitial block
19081896
item.event.assetList.forEach((asset) => {
@@ -2133,7 +2121,6 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
21332121
assetItem: InterstitialAssetItem,
21342122
assetListIndex: number,
21352123
): HlsAssetPlayer {
2136-
this.log(`create HLSAssetPlayer for ${eventAssetToString(assetItem)}`);
21372124
const primary = this.hls;
21382125
const userConfig = primary.userConfig;
21392126
let videoPreference = userConfig.videoPreference;
@@ -2273,10 +2260,7 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
22732260
const nextAssetIndex = getNextAssetIndex(interstitial, assetListIndex);
22742261
const item = this.schedule.items?.[scheduleIndex];
22752262
if (this.isInterstitial(item)) {
2276-
if (
2277-
assetListIndex !== -1 &&
2278-
!interstitial.isAssetPastPlayoutLimit(nextAssetIndex)
2279-
) {
2263+
if (!interstitial.isAssetPastPlayoutLimit(nextAssetIndex)) {
22802264
this.bufferedToItem(item, nextAssetIndex);
22812265
} else {
22822266
const nextItem = this.schedule.items?.[scheduleIndex + 1];
@@ -2355,7 +2339,9 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
23552339
error.message,
23562340
);
23572341
});
2358-
2342+
this.log(
2343+
`INTERSTITIAL_ASSET_PLAYER_CREATED ${eventAssetToString(assetItem)}`,
2344+
);
23592345
this.hls.trigger(Events.INTERSTITIAL_ASSET_PLAYER_CREATED, {
23602346
asset: assetItem,
23612347
assetListIndex,
@@ -2434,7 +2420,7 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
24342420
delete playingAsset.error;
24352421
}
24362422
this.log(
2437-
`INTERSTITIAL_ASSET_STARTED ${assetListIndex + 1}/${assetListLength} ${player}`,
2423+
`INTERSTITIAL_ASSET_STARTED ${assetListIndex + 1}/${assetListLength} ${eventAssetToString(assetItem)}`,
24382424
);
24392425
this.hls.trigger(Events.INTERSTITIAL_ASSET_STARTED, {
24402426
asset: assetItem,
@@ -2485,7 +2471,7 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
24852471
!isCompatibleTrackChange(activeTracks, player.tracks)
24862472
) {
24872473
const error = new Error(
2488-
`Asset "${assetId}" SourceBuffer tracks ('${Object.keys(player.tracks)}') are not compatible with primary content tracks ('${Object.keys(activeTracks)}')`,
2474+
`Asset ${eventAssetToString(assetItem)} SourceBuffer tracks ('${Object.keys(player.tracks)}') are not compatible with primary content tracks ('${Object.keys(activeTracks)}')`,
24892475
);
24902476
const errorData: ErrorData = {
24912477
fatal: true,
@@ -2536,7 +2522,9 @@ Schedule: ${scheduleItems.map((seg) => segmentToString(seg))} pos: ${this.timeli
25362522
scheduleIndex,
25372523
player,
25382524
});
2539-
this.warn(`Asset item error: ${data.error}`);
2525+
this.warn(
2526+
`INTERSTITIAL_ASSET_ERROR ${eventAssetToString(assetItem)} ${data.error}`,
2527+
);
25402528
this.hls.trigger(Events.INTERSTITIAL_ASSET_ERROR, interstitialAssetError);
25412529
if (!data.fatal) {
25422530
return;

src/loader/interstitial-event.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,17 @@ export class InterstitialEvent {
118118
}
119119

120120
public isAssetPastPlayoutLimit(assetIndex: number): boolean {
121-
if (assetIndex >= this.assetList.length) {
121+
if (assetIndex > 0 && assetIndex >= this.assetList.length) {
122122
return true;
123123
}
124124
const playoutLimit = this.playoutLimit;
125125
if (assetIndex <= 0 || isNaN(playoutLimit)) {
126126
return false;
127127
}
128-
const assetOffset = this.assetList[assetIndex].startOffset;
128+
if (playoutLimit === 0) {
129+
return true;
130+
}
131+
const assetOffset = this.assetList[assetIndex]?.startOffset || 0;
129132
return assetOffset > playoutLimit;
130133
}
131134

@@ -316,16 +319,10 @@ export function getInterstitialUrl(
316319
export function getNextAssetIndex(
317320
interstitial: InterstitialEvent,
318321
assetListIndex: number,
319-
inBounds?: boolean,
320322
): number {
321323
while (interstitial.assetList[++assetListIndex]?.error) {
322324
/* no-op */
323325
}
324-
if (inBounds && assetListIndex) {
325-
if (assetListIndex >= interstitial.assetList.length) {
326-
return -1;
327-
}
328-
}
329326
return assetListIndex;
330327
}
331328

0 commit comments

Comments
 (0)