Skip to content

Commit

Permalink
Retry audio and subtitle playlist loading after failure on level swit…
Browse files Browse the repository at this point in the history
…ch when no alternate is available
  • Loading branch information
robwalch committed Feb 25, 2023
1 parent 90984f9 commit c228d11
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/controller/audio-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ class AudioTrackController extends BasePlaylistController {
this.hls.trigger(Events.AUDIO_TRACKS_UPDATED, audioTracksUpdated);

this.selectInitialTrack();
} else if (
this.timer === -1 &&
this.requestScheduled === -1 &&
!this.currentTrack?.details
) {
// Retry playlist loading if no playlist is or has been loaded yet
this.setAudioTrack(this.trackId);
}
}

Expand All @@ -154,6 +161,7 @@ class AudioTrackController extends BasePlaylistController {
data.context.id === this.trackId &&
data.context.groupId === this.groupId
) {
this.requestScheduled = -1;
this.checkRetry(data);
}
}
Expand Down
31 changes: 18 additions & 13 deletions src/controller/error-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export default class ErrorController implements NetworkComponentAPI {
case ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:
case ErrorDetails.SUBTITLE_LOAD_ERROR:
case ErrorDetails.SUBTITLE_TRACK_LOAD_TIMEOUT:
// Switch to redundant level when track fails to load
if (context) {
const level = hls.levels[hls.loadLevel];
if (
Expand All @@ -130,11 +129,16 @@ export default class ErrorController implements NetworkComponentAPI {
level.textGroupIds &&
context.groupId === level.textGroupIds[level.urlId]))
) {
// redundant failover
data.errorAction = {
action: NetworkErrorAction.SendAlternateToPenaltyBox,
flags: ErrorActionFlags.MoveAllAlternatesMatchingHost,
};
// Perform Pathway switch or Redundant failover if possible for fastest recovery
// otherwise allow playlist retry count to reach max error retries
data.errorAction = this.getPlaylistRetryOrSwitchAction(
data,
hls.loadLevel
);
data.errorAction.action =
NetworkErrorAction.SendAlternateToPenaltyBox;
data.errorAction.flags =
ErrorActionFlags.MoveAllAlternatesMatchingHost;
return;
}
}
Expand Down Expand Up @@ -345,13 +349,6 @@ export default class ErrorController implements NetworkComponentAPI {

switch (flags) {
case ErrorActionFlags.None:
if (nextAutoLevel !== undefined) {
this.warn(`${data.details}: switching to level ${nextAutoLevel}`);
this.hls.nextAutoLevel = nextAutoLevel;
errorAction.resolved = true;
// Stream controller is responsible for this but won't switch on false start
this.hls.nextLoadLevel = this.hls.nextAutoLevel;
}
break;
case ErrorActionFlags.MoveAllAlternatesMatchingHost:
{
Expand All @@ -375,6 +372,14 @@ export default class ErrorController implements NetworkComponentAPI {
);
break;
}
// If not resolved by previous actions try to switch to next level
if (!errorAction.resolved && nextAutoLevel !== undefined) {
this.warn(`${data.details}: switching to level ${nextAutoLevel}`);
this.hls.nextAutoLevel = nextAutoLevel;
errorAction.resolved = true;
// Stream controller is responsible for this but won't switch on false start
this.hls.nextLoadLevel = this.hls.nextAutoLevel;
}
}

private redundantFailover(levelIndex: number): boolean {
Expand Down
15 changes: 10 additions & 5 deletions src/controller/subtitle-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,11 @@ class SubtitleTrackController extends BasePlaylistController {
if (!levelInfo?.textGroupIds) {
return;
}

const textGroupId = levelInfo.textGroupIds[levelInfo.urlId];
const lastTrack = this.tracksInGroup
? this.tracksInGroup[this.trackId]
: undefined;
if (this.groupId !== textGroupId) {
const lastTrack = this.tracksInGroup
? this.tracksInGroup[this.trackId]
: undefined;

const subtitleTracks = this.tracks.filter(
(track): boolean => !textGroupId || track.groupId === textGroupId
);
Expand All @@ -224,6 +222,13 @@ class SubtitleTrackController extends BasePlaylistController {
if (initialTrackId !== -1) {
this.setSubtitleTrack(initialTrackId, lastTrack);
}
} else if (
this.timer === -1 &&
this.requestScheduled === -1 &&
!lastTrack?.details
) {
// Retry playlist loading if no playlist is or has been loaded yet
this.setSubtitleTrack(this.trackId, lastTrack);
}
}

Expand Down

0 comments on commit c228d11

Please sign in to comment.