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 audio-buffer stall with frequent audio group switching #3800

Merged
merged 1 commit into from Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controller/audio-stream-controller.ts
Expand Up @@ -659,7 +659,7 @@ class AudioStreamController
) {
if (type === ElementaryStreamTypes.AUDIO) {
const media = this.mediaBuffer ? this.mediaBuffer : this.media;
this.afterBufferFlushed(media, type);
this.afterBufferFlushed(media, type, PlaylistLevelType.AUDIO);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/controller/base-stream-controller.ts
Expand Up @@ -1184,14 +1184,22 @@ export default class BaseStreamController
}
}

protected afterBufferFlushed(media: Bufferable, type: SourceBufferName) {
protected afterBufferFlushed(
media: Bufferable,
bufferType: SourceBufferName,
playlistType: PlaylistLevelType
) {
if (!media) {
return;
}
// After successful buffer flushing, filter flushed fragments from bufferedFrags use mediaBuffered instead of media
// (so that we will check against video.buffered ranges in case of alt audio track)
const bufferedTimeRanges = BufferHelper.getBuffered(media);
this.fragmentTracker.detectEvictedFragments(type, bufferedTimeRanges);
this.fragmentTracker.detectEvictedFragments(
bufferType,
bufferedTimeRanges,
playlistType
);
if (this.state === State.ENDED) {
this.resetLoadingState();
}
Expand Down
11 changes: 9 additions & 2 deletions src/controller/fragment-tracker.ts
Expand Up @@ -136,12 +136,19 @@ export class FragmentTracker implements ComponentAPI {
*/
public detectEvictedFragments(
elementaryStream: SourceBufferName,
timeRange: TimeRanges
timeRange: TimeRanges,
playlistType?: PlaylistLevelType
) {
// Check if any flagged fragments have been unloaded
Object.keys(this.fragments).forEach((key) => {
const fragmentEntity = this.fragments[key];
if (!fragmentEntity || !fragmentEntity.buffered) {
if (!fragmentEntity) {
return;
}
if (!fragmentEntity.buffered) {
if (fragmentEntity.body.type === playlistType) {
this.removeFragment(fragmentEntity.body);
}
return;
}
const esData = fragmentEntity.range[elementaryStream];
Expand Down
2 changes: 1 addition & 1 deletion src/controller/stream-controller.ts
Expand Up @@ -938,7 +938,7 @@ export default class StreamController
(type === ElementaryStreamTypes.VIDEO
? this.videoBuffer
: this.mediaBuffer) || this.media;
this.afterBufferFlushed(media, type);
this.afterBufferFlushed(media, type, PlaylistLevelType.MAIN);
}
}

Expand Down