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

Fix backtracking when an appended segment has no buffered timerange #6434

Merged
merged 1 commit into from
May 23, 2024
Merged
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
21 changes: 16 additions & 5 deletions src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export default class BaseStreamController
const { fragmentTracker } = this;
const fragState = fragmentTracker.getState(frag);
if (fragState === FragmentState.APPENDING) {
// Lower the buffer size and try again
// Lower the max buffer length and try again
const playlistType = frag.type as PlaylistLevelType;
const bufferedInfo = this.getFwdBufferInfo(
this.mediaBuffer,
Expand All @@ -457,7 +457,17 @@ export default class BaseStreamController
frag.duration,
bufferedInfo ? bufferedInfo.len : this.config.maxBufferLength,
);
if (this.reduceMaxBufferLength(minForwardBufferLength)) {
// If backtracking, always remove from the tracker without reducing max buffer length
const backtrackFragment = (this as any).backtrackFragment as
| Fragment
| undefined;
const backtracked = backtrackFragment
? (frag.sn as number) - (backtrackFragment.sn as number)
: 0;
if (
backtracked === 1 ||
this.reduceMaxBufferLength(minForwardBufferLength)
) {
fragmentTracker.removeFragment(frag);
}
} else if (this.mediaBuffer?.buffered.length === 0) {
Expand Down Expand Up @@ -1134,10 +1144,11 @@ export default class BaseStreamController
protected reduceMaxBufferLength(threshold: number) {
const config = this.config;
const minLength = threshold || config.maxBufferLength;
if (config.maxMaxBufferLength >= minLength) {
const reducedLength = config.maxMaxBufferLength / 2;
if (reducedLength >= minLength) {
// reduce max buffer length as it might be too high. we do this to avoid loop flushing ...
config.maxMaxBufferLength /= 2;
this.warn(`Reduce max buffer length to ${config.maxMaxBufferLength}s`);
config.maxMaxBufferLength = reducedLength;
this.warn(`Reduce max buffer length to ${reducedLength}s`);
return true;
}
return false;
Expand Down
Loading