Skip to content

Commit

Permalink
Limit live playlist reloading to scheduled updates (#6873)
Browse files Browse the repository at this point in the history
Fixes #6858
  • Loading branch information
robwalch authored Nov 29, 2024
1 parent 6e0656a commit 550dc2a
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 221 deletions.
22 changes: 12 additions & 10 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ export class AudioTrackController extends BasePlaylistController {
// (undocumented)
destroy(): void;
// (undocumented)
protected loadingPlaylist(audioTrack: MediaPlaylist, hlsUrlParameters: HlsUrlParameters | undefined): void;
// (undocumented)
protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters): void;
// (undocumented)
protected onAudioTrackLoaded(event: Events.AUDIO_TRACK_LOADED, data: AudioTrackLoadedData): void;
Expand Down Expand Up @@ -303,33 +305,29 @@ export type BaseData = {
export class BasePlaylistController extends Logger implements NetworkComponentAPI {
constructor(hls: Hls, logPrefix: string);
// (undocumented)
protected canLoad: boolean;
// (undocumented)
protected checkRetry(errorEvent: ErrorData): boolean;
// (undocumented)
protected clearTimer(): void;
// (undocumented)
destroy(): void;
// (undocumented)
protected getUrlWithDirectives(uri: string, hlsUrlParameters: HlsUrlParameters | undefined): string;
// (undocumented)
protected hls: Hls;
// (undocumented)
protected loadingPlaylist(playlist: Level | MediaPlaylist, hlsUrlParameters?: HlsUrlParameters): void;
// (undocumented)
protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters): void;
// (undocumented)
protected playlistLoaded(index: number, data: LevelLoadedData | AudioTrackLoadedData | TrackLoadedData, previousDetails?: LevelDetails): void;
// (undocumented)
protected requestScheduled: number;
protected scheduleLoading(levelOrTrack: Level | MediaPlaylist, deliveryDirectives?: HlsUrlParameters): void;
// (undocumented)
protected shouldLoadPlaylist(playlist: Level | MediaPlaylist | null | undefined): boolean;
// (undocumented)
protected shouldReloadPlaylist(playlist: Level | MediaPlaylist | null | undefined): boolean;
protected shouldLoadPlaylist(playlist: Level | MediaPlaylist | null | undefined): playlist is Level | MediaPlaylist;
// (undocumented)
startLoad(): void;
// (undocumented)
stopLoad(): void;
// (undocumented)
protected switchParams(playlistUri: string, previous: LevelDetails | undefined, current: LevelDetails | undefined): HlsUrlParameters | undefined;
// (undocumented)
protected timer: number;
}

// Warning: (ae-missing-release-tag) "BaseSegment" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -3182,6 +3180,8 @@ export class LevelDetails {
// (undocumented)
renditionReports?: AttrList[];
// (undocumented)
requestScheduled: number;
// (undocumented)
skippedSegments: number;
// (undocumented)
startCC: number;
Expand Down Expand Up @@ -4482,6 +4482,8 @@ export class SubtitleTrackController extends BasePlaylistController {
// (undocumented)
destroy(): void;
// (undocumented)
protected loadingPlaylist(currentTrack: MediaPlaylist, hlsUrlParameters: HlsUrlParameters | undefined): void;
// (undocumented)
protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters): void;
// (undocumented)
protected onError(event: Events.ERROR, data: ErrorData): void;
Expand Down
78 changes: 32 additions & 46 deletions src/controller/audio-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ class AudioTrackController extends BasePlaylistController {
error,
});
}
} else if (this.shouldReloadPlaylist(currentTrack)) {
// Retry playlist loading if no playlist is or has been loaded yet
this.setAudioTrack(this.trackId);
}
}

Expand All @@ -224,7 +221,6 @@ class AudioTrackController extends BasePlaylistController {
data.context.id === this.trackId &&
(!this.groupIds || this.groupIds.indexOf(data.context.groupId) !== -1)
) {
this.requestScheduled = -1;
this.checkRetry(data);
}
}
Expand Down Expand Up @@ -319,9 +315,6 @@ class AudioTrackController extends BasePlaylistController {
return;
}

// stopping live reloading timer if any
this.clearTimer();

this.selectDefaultTrack = false;
const lastTrack = this.currentTrack;
const track = tracks[newId];
Expand Down Expand Up @@ -403,49 +396,42 @@ class AudioTrackController extends BasePlaylistController {
}

protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters): void {
super.loadPlaylist();
const audioTrack = this.currentTrack;
if (!audioTrack) {
if (!this.shouldLoadPlaylist(audioTrack)) {
return;
}
let url = audioTrack.url;
if (
this.shouldLoadPlaylist(audioTrack) &&
url !== this.hls.levels[this.hls.loadLevel]?.uri
) {
super.loadPlaylist();
const id = audioTrack.id;
const groupId = audioTrack.groupId as string;
if (hlsUrlParameters) {
try {
url = hlsUrlParameters.addDirectives(url);
} catch (error) {
this.warn(
`Could not construct new URL with HLS Delivery Directives: ${error}`,
);
}
}
// track not retrieved yet, or live playlist we need to (re)load it
const details = audioTrack.details;
const age = details?.age;
this.log(
`Loading audio-track ${id} "${audioTrack.name}" lang:${audioTrack.lang} group:${groupId}${
hlsUrlParameters?.msn !== undefined
? ' at sn ' +
hlsUrlParameters.msn +
' part ' +
hlsUrlParameters.part
: ''
}${age && details.live ? ' age ' + age.toFixed(1) + (details.type ? ' ' + details.type || '' : '') : ''} ${url}`,
);
this.clearTimer();
this.hls.trigger(Events.AUDIO_TRACK_LOADING, {
url,
id,
groupId,
deliveryDirectives: hlsUrlParameters || null,
track: audioTrack,
});
if (audioTrack.url === this.hls.levels[this.hls.loadLevel]?.uri) {
// Do not load audio rendition with URI matching main variant URI
return;
}
this.scheduleLoading(audioTrack, hlsUrlParameters);
}

protected loadingPlaylist(
audioTrack: MediaPlaylist,
hlsUrlParameters: HlsUrlParameters | undefined,
) {
super.loadingPlaylist(audioTrack, hlsUrlParameters);
const id = audioTrack.id;
const groupId = audioTrack.groupId as string;
const url = this.getUrlWithDirectives(audioTrack.url, hlsUrlParameters);
const details = audioTrack.details;
const age = details?.age;
this.log(
`Loading audio-track ${id} "${audioTrack.name}" lang:${audioTrack.lang} group:${groupId}${
hlsUrlParameters?.msn !== undefined
? ' at sn ' + hlsUrlParameters.msn + ' part ' + hlsUrlParameters.part
: ''
}${age && details.live ? ' age ' + age.toFixed(1) + (details.type ? ' ' + details.type || '' : '') : ''} ${url}`,
);
this.hls.trigger(Events.AUDIO_TRACK_LOADING, {
url,
id,
groupId,
deliveryDirectives: hlsUrlParameters || null,
track: audioTrack,
});
}
}

Expand Down
Loading

0 comments on commit 550dc2a

Please sign in to comment.