Skip to content

Commit

Permalink
Merge pull request #3800 from video-dev/bugfix/audio-group-switching-…
Browse files Browse the repository at this point in the history
…tracker-state

Fix audio-buffer stall with frequent audio group switching
  • Loading branch information
robwalch committed Apr 19, 2021
2 parents d31cc5b + 210eb24 commit 9b1a973
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
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

0 comments on commit 9b1a973

Please sign in to comment.