Skip to content

Commit

Permalink
fix: don't clear DASH minimum update period timeout on pause of a med…
Browse files Browse the repository at this point in the history
…ia loader (#1118)

Previously, for DASH, pausing a media loader would end up pausing the
main loader as well (via removal of the main loader's minimum update
period). For live streams which required manifest refreshes, this meant
that on media changes, the main loader would be paused and sometimes
never resumed.

This change ensures that when a media loader is paused it won't remove
the main loader's minimum update period timeout.

In addition, a change was made so that loading a main DASH playlist
loader recreates a minimum update period timeout if the main DASH loader
was previously paused (and the timeout cleared).

Co-authored-by: Brandon Casey <2381475+brandonocasey@users.noreply.github.com>
  • Loading branch information
gesinger and brandonocasey authored Apr 20, 2021
1 parent aa194d3 commit 82ff4f5
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/dash-playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,11 @@ export default class DashPlaylistLoader extends EventTarget {
}
this.stopRequest();
window.clearTimeout(this.mediaUpdateTimeout);
window.clearTimeout(this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_);
this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_ = null;
this.mediaUpdateTimeout = null;
if (this.isMaster_) {
window.clearTimeout(this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_);
this.masterPlaylistLoader_.minimumUpdatePeriodTimeout_ = null;
}
if (this.state === 'HAVE_NOTHING') {
// If we pause the loader before any data has been retrieved, its as if we never
// started, so reset to an unstarted state.
Expand Down Expand Up @@ -548,6 +550,15 @@ export default class DashPlaylistLoader extends EventTarget {
}

if (media && !media.endList) {
// Check to see if this is the master loader and the MUP was cleared (this happens
// when the loader was paused). `media` should be set at this point since one is always
// set during `start()`.
if (this.isMaster_ && !this.minimumUpdatePeriodTimeout_) {
// Trigger minimumUpdatePeriod to refresh the master manifest
this.trigger('minimumUpdatePeriod');
// Since there was no prior minimumUpdatePeriodTimeout it should be recreated
this.updateMinimumUpdatePeriodTimeout_();
}
this.trigger('mediaupdatetimeout');
} else {
this.trigger('loadedplaylist');
Expand Down
68 changes: 68 additions & 0 deletions test/dash-playlist-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2690,3 +2690,71 @@ QUnit.test('load does not resume the media update timer for non live playlists',

assert.notOk(loader.mediaUpdateTimeout, 'media update timeout not set');
});

QUnit.test('pause removes minimum update period timeout', function(assert) {
const loader = new DashPlaylistLoader('dash-live.mpd', this.fakeVhs);

loader.load();
this.standardXHRResponse(this.requests.shift());
this.clock.tick(1);

assert.ok(loader.minimumUpdatePeriodTimeout_, 'minimum update period timeout set');

loader.pause();

assert.notOk(
loader.minimumUpdatePeriodTimeout_,
'minimum update period timeout not set'
);
});

QUnit.test('load resumes minimum update period timeout for live', function(assert) {
const loader = new DashPlaylistLoader('dash-live.mpd', this.fakeVhs);

loader.load();
this.standardXHRResponse(this.requests.shift());
this.clock.tick(1);

// media should be selected at this point
loader.media(loader.master.playlists[0]);

assert.ok(loader.minimumUpdatePeriodTimeout_, 'minimum update period timeout set');

loader.pause();

assert.notOk(
loader.minimumUpdatePeriodTimeout_,
'minimum update period timeout not set'
);

loader.load();

assert.ok(loader.minimumUpdatePeriodTimeout_, 'minimum update period timeout set');
});

QUnit.test('pause does not remove minimum update period timeout when not master', function(assert) {
const masterLoader = new DashPlaylistLoader('dash-live.mpd', this.fakeVhs);

masterLoader.load();
this.standardXHRResponse(this.requests.shift());
this.clock.tick(1);

const media = masterLoader.master.playlists[0];
// media should be selected at this point

masterLoader.media(media);

const mediaLoader = new DashPlaylistLoader(media, this.fakeVhs, {}, masterLoader);

assert.ok(
masterLoader.minimumUpdatePeriodTimeout_,
'minimum update period timeout set'
);

mediaLoader.pause();

assert.ok(
masterLoader.minimumUpdatePeriodTimeout_,
'minimum update period timeout set'
);
});

0 comments on commit 82ff4f5

Please sign in to comment.