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: stop alt loaders on main mediachanging to prevent append race #895

Merged
merged 3 commits into from
Jul 9, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,9 +1346,6 @@ export class MasterPlaylistController extends videojs.EventTarget {
if (usingAudioLoader && unsupportedAudio && this.media().attributes.AUDIO) {
const audioGroup = this.media().attributes.AUDIO;

this.mediaTypes_.AUDIO.activePlaylistLoader.pause();
this.audioSegmentLoader_.pause();
this.audioSegmentLoader_.abort();
this.master().playlists.forEach(variant => {
const variantAudioGroup = variant.attributes && variant.attributes.AUDIO;

Expand Down
16 changes: 16 additions & 0 deletions src/media-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ export const onGroupChanged = (type, settings) => () => {
startLoaders(activeGroup.playlistLoader, mediaType);
};

export const onGroupChanging = (type, settings) => () => {
const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use stopLoaders? And should onGroupChanged no longer stopLoaders?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally I tried using stopLoaders but that caused an issue because we abort the current audio playlist loader request when starting playback even though we aren't changing audio playlists. I will check if mediachange should just stop the audio playlist loader, since the segmentLoader will be stopped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK after testing out changing onGroupChanged to only stop the activePlaylistLoader is doesn't work. Loaders are started and stopped frequently during the start of playback and if we don't stop them in mediachange too it can cause playback to hang because the segment loader is trying to load, but there isn't an activePlaylistlistLoader.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test added

segmentLoaders: {
[type]: segmentLoader
}
} = settings;

segmentLoader.abort();
segmentLoader.pause();
};

/**
* Returns a function to be called when the media track changes. It performs a
* destructive reset of the SegmentLoader to ensure we start loading as close to
Expand Down Expand Up @@ -730,6 +741,7 @@ export const setupMediaGroups = (settings) => {
mediaTypes[type].activeGroup = activeGroup(type, settings);
mediaTypes[type].activeTrack = activeTrack[type](type, settings);
mediaTypes[type].onGroupChanged = onGroupChanged(type, settings);
mediaTypes[type].onGroupChanging = onGroupChanging(type, settings);
mediaTypes[type].onTrackChanged = onTrackChanged(type, settings);
});

Expand All @@ -748,6 +760,10 @@ export const setupMediaGroups = (settings) => {
['AUDIO', 'SUBTITLES'].forEach(type => mediaTypes[type].onGroupChanged());
});

masterPlaylistLoader.on('mediachanging', () => {
['AUDIO', 'SUBTITLES'].forEach(type => mediaTypes[type].onGroupChanging());
});

// custom audio track change event handler for usage event
const onAudioTrackChanged = () => {
mediaTypes.AUDIO.onTrackChanged();
Expand Down
26 changes: 26 additions & 0 deletions test/media-groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,32 @@ QUnit.test('activeGroup returns the correct subtitle group', function(assert) {
);
});

QUnit.test('onGroupChanging aborts and pauses segment loaders', function(assert) {
const calls = {
abort: 0,
pause: 0
};
const segmentLoader = {
abort: () => calls.abort++,
pause: () => calls.pause++
};

const settings = {
segmentLoaders: {
AUDIO: segmentLoader
}
};
const type = 'AUDIO';

const onGroupChanging = MediaGroups.onGroupChanging(type, settings);

assert.deepEqual(calls, {abort: 0, pause: 0}, 'no calls yet');

onGroupChanging();

assert.deepEqual(calls, {abort: 1, pause: 1}, 'one abort one pause');
});

QUnit.test(
'onGroupChanged updates active playlist loader and resyncs segment loader',
function(assert) {
Expand Down