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

Hls.js live eadge delay autodetection #334

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Changes from 1 commit
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
19 changes: 12 additions & 7 deletions packages/p2p-media-loader-hlsjs/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { PlaylistLoaderBase } from "./playlist-loader";
import { SegmentManager } from "./segment-mananger";
import { Core, CoreEventHandlers } from "p2p-media-loader-core";

const LIVE_EDGE_DELAY = 25;

export class Engine {
private readonly core: Core;
private readonly segmentManager: SegmentManager;
Expand All @@ -24,14 +22,10 @@ export class Engine {
this.segmentManager = new SegmentManager(this.core);
}

public getConfig(): Pick<
HlsConfig,
"fLoader" | "pLoader" | "liveSyncDuration"
> {
public getConfig(): Partial<HlsConfig> {
return {
fLoader: this.createFragmentLoaderClass(),
pLoader: this.createPlaylistLoaderClass(),
liveSyncDuration: LIVE_EDGE_DELAY,
};
}

Expand Down Expand Up @@ -118,6 +112,17 @@ export class Engine {
event: string,
data: LevelUpdatedData | AudioTrackLoadedData,
) => {
if (
this.currentHlsInstance &&
data.details.live &&
!this.currentHlsInstance.userConfig.liveSyncDuration &&
!this.currentHlsInstance.userConfig.liveSyncDurationCount &&
data.details.fragments.length > 4
DimaDemchenko marked this conversation as resolved.
Show resolved Hide resolved
) {
this.currentHlsInstance.config.liveSyncDurationCount =
data.details.fragments.length - 1;
}

this.core.setIsLive(data.details.live);
this.segmentManager.updatePlaylist(data);
};
Expand Down