Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine canSkip based on age of last playlist request #6300

Merged
merged 12 commits into from
Apr 8, 2024
Merged
2 changes: 1 addition & 1 deletion src/controller/audio-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class AudioTrackController extends BasePlaylistController {
protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters): void {
const audioTrack = this.currentTrack;
if (this.shouldLoadPlaylist(audioTrack) && audioTrack) {
super.loadPlaylist();
super.loadPlaylist(hlsUrlParameters, audioTrack.details);
robwalch marked this conversation as resolved.
Show resolved Hide resolved
const id = audioTrack.id;
const groupId = audioTrack.groupId as string;
let url = audioTrack.url;
Expand Down
13 changes: 10 additions & 3 deletions src/controller/base-playlist-controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Hls from '../hls';
import type { NetworkComponentAPI } from '../types/component-api';
import { getSkipValue, HlsSkip, HlsUrlParameters, Level } from '../types/level';
import { HlsSkip, HlsUrlParameters, Level, getSkipValue } from '../types/level';
import { computeReloadInterval, mergeDetails } from '../utils/level-helper';
import { ErrorData } from '../types/events';
import { getRetryDelay, isTimeoutError } from '../utils/error-helper';
Expand Down Expand Up @@ -101,7 +101,14 @@ export default class BasePlaylistController
}
}

protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters): void {
protected loadPlaylist(
hlsUrlParameters?: HlsUrlParameters,
levelDetails?: LevelDetails,
): void {
const skipValue = levelDetails && getSkipValue(levelDetails);
if (hlsUrlParameters) {
hlsUrlParameters.skip = skipValue;
}
if (this.requestScheduled === -1) {
this.requestScheduled = self.performance.now();
}
Expand Down Expand Up @@ -310,7 +317,7 @@ export default class BasePlaylistController
msn?: number,
part?: number,
): HlsUrlParameters {
let skip = getSkipValue(details, msn);
let skip: HlsSkip | undefined;
if (previousDeliveryDirectives?.skip && details.deltaUpdateFailed) {
msn = previousDeliveryDirectives.msn;
part = previousDeliveryDirectives.part;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/level-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ export default class LevelController extends BasePlaylistController {
}

protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters) {
super.loadPlaylist();
const currentLevelIndex = this.currentLevelIndex;
const currentLevel = this.currentLevel;
super.loadPlaylist(hlsUrlParameters, currentLevel?.details);
robwalch marked this conversation as resolved.
Show resolved Hide resolved

if (currentLevel && this.shouldLoadPlaylist(currentLevel)) {
let url = currentLevel.uri;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/subtitle-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ class SubtitleTrackController extends BasePlaylistController {
}

protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters): void {
super.loadPlaylist();
const currentTrack = this.currentTrack;
super.loadPlaylist(hlsUrlParameters, currentTrack?.details);
robwalch marked this conversation as resolved.
Show resolved Hide resolved
if (this.shouldLoadPlaylist(currentTrack) && currentTrack) {
const id = currentTrack.id;
const groupId = currentTrack.groupId as string;
Expand Down
11 changes: 7 additions & 4 deletions src/types/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ export const enum HlsSkip {
v2 = 'v2',
}

export function getSkipValue(details: LevelDetails, msn?: number): HlsSkip {
const { canSkipUntil, canSkipDateRanges, endSN } = details;
const snChangeGoal = msn !== undefined ? msn - endSN : 0;
if (canSkipUntil && snChangeGoal < canSkipUntil) {
export function getSkipValue(details: LevelDetails): HlsSkip {
const { canSkipUntil, canSkipDateRanges, age } = details;
// A Client SHOULD NOT request a Playlist Delta Update unless it already
// has a version of the Playlist that is no older than one-half of the Skip Boundary.
// @see: https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-6.3.7
const playlistRecentEnough = age < canSkipUntil / 2;
if (canSkipUntil && playlistRecentEnough) {
if (canSkipDateRanges) {
return HlsSkip.v2;
}
Expand Down