Skip to content

Commit

Permalink
Remove fragment from fragment tracker on BUFFER_FULL error and when i…
Browse files Browse the repository at this point in the history
…n appending state and trying to reload on IDLE (#5354)

Resolves #5328
Related to #5349 / Follow up to #5350
  • Loading branch information
robwalch authored Mar 29, 2023
1 parent 4160070 commit 4cd93e0
Show file tree
Hide file tree
Showing 5 changed files with 32 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): void;
// (undocumented)
protected clearTrackerIfNeeded(frag: Fragment): void;
// (undocumented)
protected config: HlsConfig;
// Warning: (ae-forgotten-export) The symbol "Decrypter" needs to be exported by the entry point hls.d.ts
//
Expand Down
2 changes: 2 additions & 0 deletions src/controller/audio-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ class AudioStreamController
this.startFragRequested = true;
super.loadFragment(frag, track, targetBufferTime);
}
} else {
this.clearTrackerIfNeeded(frag);
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,28 @@ export default class BaseStreamController
});
}

protected clearTrackerIfNeeded(frag: Fragment) {
const fragState = this.fragmentTracker.getState(frag);
if (fragState === FragmentState.APPENDING) {
// Lower the buffer size and try again
const playlistType = frag.type as PlaylistLevelType;
const bufferedInfo = this.getFwdBufferInfo(
this.mediaBuffer,
playlistType
);
const minForwardBufferLength = Math.max(
frag.duration,
bufferedInfo ? bufferedInfo.len : this.config.maxBufferLength
);
if (this.reduceMaxBufferLength(minForwardBufferLength)) {
this.fragmentTracker.removeFragment(frag);
}
} else if (this.mediaBuffer?.buffered.length === 0) {
// Stop gap for bad tracker / buffer flush behavior
this.fragmentTracker.removeAllFragments();
}
}

protected flushMainBuffer(
startOffset: number,
endOffset: number,
Expand Down Expand Up @@ -1495,6 +1517,7 @@ export default class BaseStreamController
);
}
if (data.frag) {
this.fragmentTracker.removeFragment(data.frag);
this.nextLoadPosition = data.frag.start;
}
this.resetLoadingState();
Expand Down
3 changes: 3 additions & 0 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ export default class BufferController implements ComponentAPI {
type: ErrorTypes.MEDIA_ERROR,
parent: frag.type,
details: ErrorDetails.BUFFER_APPEND_ERROR,
frag,
part,
chunkMeta,
error: err,
err,
fatal: false,
Expand Down
10 changes: 2 additions & 8 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,8 @@ export default class StreamController
this.startFragRequested = true;
super.loadFragment(frag, level, targetBufferTime);
}
} else if (fragState === FragmentState.APPENDING) {
// Lower the buffer size and try again
if (this.reduceMaxBufferLength(frag.duration)) {
this.fragmentTracker.removeFragment(frag);
}
} else if (this.media?.buffered.length === 0) {
// Stop gap for bad tracker / buffer flush behavior
this.fragmentTracker.removeAllFragments();
} else {
this.clearTrackerIfNeeded(frag);
}
}

Expand Down

0 comments on commit 4cd93e0

Please sign in to comment.