Skip to content

Commit

Permalink
Merge bugfix/live-append-only-endlist into patch v1.4.x branch (#5785)
Browse files Browse the repository at this point in the history
* Handle #EXT-X-ENDLIST appended to live playlist without new segment
* Update segment in fragment tracker when the last fragment gets `endList` added
* Do not modify old fragment reference
Fixes #5777

---------

Co-authored-by: Rob Walch <robwalch@users.noreply.github.com>
Co-authored-by: Sergey Marchenko <sergey.dnepro@gmail.com>
  • Loading branch information
3 people committed Aug 31, 2023
1 parent 7cde71f commit 9dfe464
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 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 @@ -290,6 +290,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 @@ -505,10 +505,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
2 changes: 2 additions & 0 deletions src/controller/base-playlist-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export default class BasePlaylistController implements NetworkComponentAPI {
`live playlist ${index} ${
details.advanced
? 'REFRESHED ' + details.lastPartSn + '-' + details.lastPartIndex
: details.updated
? 'UPDATED'
: 'MISSED'
}`
);
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
5 changes: 4 additions & 1 deletion src/loader/level-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export class LevelDetails {
const partSnDiff = this.lastPartSn - previous.lastPartSn;
const partIndexDiff = this.lastPartIndex - previous.lastPartIndex;
this.updated =
this.endSN !== previous.endSN || !!partIndexDiff || !!partSnDiff;
this.endSN !== previous.endSN ||
!!partIndexDiff ||
!!partSnDiff ||
!this.live;
this.advanced =
this.endSN > previous.endSN ||
partSnDiff > 0 ||
Expand Down

0 comments on commit 9dfe464

Please sign in to comment.