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
4 changes: 2 additions & 2 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 } 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 @@ -310,7 +310,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
11 changes: 10 additions & 1 deletion src/controller/level-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
ManifestLoadingData,
FragBufferedData,
} from '../types/events';
import { Level, VideoRangeValues, isVideoRange } from '../types/level';
import {
Level,
VideoRangeValues,
isVideoRange,
getSkipValue,
} from '../types/level';
import { Events } from '../events';
import { ErrorTypes, ErrorDetails } from '../errors';
import {
Expand Down Expand Up @@ -575,9 +580,13 @@ export default class LevelController extends BasePlaylistController {
const currentLevel = this.currentLevel;

if (currentLevel && this.shouldLoadPlaylist(currentLevel)) {
const skipValue = currentLevel.details
? getSkipValue(currentLevel.details)
: undefined;
let url = currentLevel.uri;
if (hlsUrlParameters) {
try {
hlsUrlParameters.skip = skipValue;
robwalch marked this conversation as resolved.
Show resolved Hide resolved
url = hlsUrlParameters.addDirectives(url);
} catch (error) {
this.warn(
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
Loading