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

Feat/doris 2353 pathway selection #99

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,11 @@ export class ContentSteeringController implements NetworkComponentAPI {
// (undocumented)
filterParsedLevels(levels: Level[]): Level[];
// (undocumented)
get pathwayPriority(): string[] | null;
set pathwayPriority(pathwayPriority: string[]);
// (undocumented)
pathways(): string[];
// (undocumented)
removeLevel(levelToRemove: Level): void;
// (undocumented)
startLoad(): void;
Expand Down Expand Up @@ -1637,6 +1642,10 @@ class Hls implements HlsEventEmitter {
on<E extends keyof HlsListeners, Context = undefined>(event: E, listener: HlsListeners[E], context?: Context): void;
// (undocumented)
once<E extends keyof HlsListeners, Context = undefined>(event: E, listener: HlsListeners[E], context?: Context): void;
get pathwayPriority(): string[] | null;
set pathwayPriority(pathwayPriority: string[]);
// (undocumented)
get pathways(): string[];
pauseBuffering(): void;
get playingDate(): Date | null;
recoverMediaError(): void;
Expand Down
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hls.js",
"version": "1.5.12",
"version": "1.5.13",
"license": "Apache-2.0",
"description": "JavaScript HLS client using MediaSourceExtension",
"homepage": "https://github.com/video-dev/hls.js",
Expand Down
30 changes: 21 additions & 9 deletions src/controller/content-steering-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class ContentSteeringController implements NetworkComponentAPI {
private loader: Loader<LoaderContext> | null = null;
private uri: string | null = null;
private pathwayId: string = '.';
private pathwayPriority: string[] | null = null;
private _pathwayPriority: string[] | null = null;
private timeToLoad: number = 300;
private reloadTimer: number = -1;
private updated: number = 0;
Expand Down Expand Up @@ -90,6 +90,23 @@ export default class ContentSteeringController implements NetworkComponentAPI {
hls.off(Events.ERROR, this.onError, this);
}

pathways() {
grabofus marked this conversation as resolved.
Show resolved Hide resolved
return (this.levels || []).reduce((pathways, level) => {
if (pathways.indexOf(level.pathwayId) === -1) {
pathways.push(level.pathwayId);
}
return pathways;
}, [] as string[]);
}

get pathwayPriority(): string[] | null {
return this._pathwayPriority;
}

set pathwayPriority(pathwayPriority: string[]) {
this.updatePathwayPriority(pathwayPriority);
}

startLoad() {
this.started = true;
this.clearTimeout();
Expand Down Expand Up @@ -176,7 +193,7 @@ export default class ContentSteeringController implements NetworkComponentAPI {
errorAction.flags === ErrorActionFlags.MoveAllAlternatesMatchingHost
) {
const levels = this.levels;
let pathwayPriority = this.pathwayPriority;
let pathwayPriority = this._pathwayPriority;
let errorPathway = this.pathwayId;
if (data.context) {
const { groupId, pathwayId, type } = data.context;
Expand All @@ -191,12 +208,7 @@ export default class ContentSteeringController implements NetworkComponentAPI {
}
if (!pathwayPriority && levels) {
// If PATHWAY-PRIORITY was not provided, list pathways for error handling
pathwayPriority = levels.reduce((pathways, level) => {
if (pathways.indexOf(level.pathwayId) === -1) {
pathways.push(level.pathwayId);
}
return pathways;
}, [] as string[]);
pathwayPriority = this.pathways();
}
if (pathwayPriority && pathwayPriority.length > 1) {
this.updatePathwayPriority(pathwayPriority);
Expand Down Expand Up @@ -245,7 +257,7 @@ export default class ContentSteeringController implements NetworkComponentAPI {
}

private updatePathwayPriority(pathwayPriority: string[]) {
this.pathwayPriority = pathwayPriority;
this._pathwayPriority = pathwayPriority;
let levels: Level[] | undefined;

// Evaluate if we should remove the pathway from the penalized list
Expand Down
28 changes: 28 additions & 0 deletions src/controller/level-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,34 @@ export default class LevelController extends BasePlaylistController {
this._startLevel = newLevel;
}

get pathways(): string[] {
return this.steering?.pathways() ?? [];
}

get pathwayPriority(): string[] | null {
if (this.steering) {
return this.steering.pathwayPriority;
}

return null;
}

set pathwayPriority(pathwayPriority: string[]) {
if (this.steering) {
const pathwaysList = this.steering.pathways();
const filteredPathwayPriority = pathwayPriority.filter((pathwayId) => {
return pathwaysList.indexOf(pathwayId) !== -1;
});
if (pathwayPriority.length < 1) {
this.warn(
`pathwayPriority ${pathwayPriority} should contain at least one pathway from list: ${pathwaysList}`,
);
return;
}
this.steering.pathwayPriority = filteredPathwayPriority;
}
}

protected onError(event: Events.ERROR, data: ErrorData) {
if (data.fatal || !data.context) {
return;
Expand Down
15 changes: 15 additions & 0 deletions src/hls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,21 @@ export default class Hls implements HlsEventEmitter {
get forceStartLoad(): boolean {
return this.streamController.forceStartLoad;
}

get pathways(): string[] {
return this.levelController.pathways;
}

/**
* ContentSteering pathwayPriority getter/setter
*/
get pathwayPriority(): string[] | null {
return this.levelController.pathwayPriority;
}

set pathwayPriority(pathwayPriority: string[]) {
this.levelController.pathwayPriority = pathwayPriority;
}
}

export type {
Expand Down
Loading