Skip to content

Commit

Permalink
Update segment in fragment tracker when the last fragment gets `endLi…
Browse files Browse the repository at this point in the history
…st` added

Fixes #5777
  • Loading branch information
robwalch committed Aug 31, 2023
1 parent 108315c commit 9c9e79e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
// (undocumented)
protected bufferFragmentData(data: RemuxedTrack, frag: Fragment, part: Part | null, chunkMeta: ChunkMetadata, noBacktracking?: boolean): void;
// (undocumented)
protected checkLiveUpdate(details: LevelDetails): void;
// (undocumented)
protected clearTrackerIfNeeded(frag: Fragment): void;
// (undocumented)
protected config: HlsConfig;
Expand Down
4 changes: 1 addition & 3 deletions src/controller/audio-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,8 @@ class AudioStreamController
const track = levels[trackId];
let sliding = 0;
if (newDetails.live || track.details?.live) {
this.checkLiveUpdate(newDetails);
const mainDetails = this.mainDetails;
if (!newDetails.fragments[0]) {
newDetails.deltaUpdateFailed = true;
}
if (newDetails.deltaUpdateFailed || !mainDetails) {
return;
}
Expand Down
16 changes: 16 additions & 0 deletions src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ export default class BaseStreamController
}
}

protected checkLiveUpdate(details: LevelDetails) {
if (details.updated && !details.live) {
// Live stream ended, update fragment tracker
const lastFragment = details.fragments[details.fragments.length - 1];
this.fragmentTracker.detectPartialFragments({
frag: lastFragment,
part: null,
stats: lastFragment.stats,
id: lastFragment.type,
});
}
if (!details.fragments[0]) {
details.deltaUpdateFailed = true;
}
}

protected flushMainBuffer(
startOffset: number,
endOffset: number,
Expand Down
4 changes: 3 additions & 1 deletion src/controller/fragment-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ export class FragmentTracker implements ComponentAPI {
fragmentEntity.loaded = null;
if (Object.keys(fragmentEntity.range).length) {
fragmentEntity.buffered = true;
if (fragmentEntity.body.endList) {
const endList = (fragmentEntity.body.endList =
frag.endList || fragmentEntity.body.endList);
if (endList) {
this.endListFragments[fragmentEntity.body.type] = fragmentEntity;
}
if (!isPartial(fragmentEntity)) {
Expand Down
4 changes: 1 addition & 3 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,7 @@ export default class StreamController

let sliding = 0;
if (newDetails.live || curLevel.details?.live) {
if (!newDetails.fragments[0]) {
newDetails.deltaUpdateFailed = true;
}
this.checkLiveUpdate(newDetails);
if (newDetails.deltaUpdateFailed) {
return;
}
Expand Down

0 comments on commit 9c9e79e

Please sign in to comment.