Skip to content

Commit

Permalink
fix: verify sidx is present before doing anything related to it (#561)
Browse files Browse the repository at this point in the history
Fixes #457, fixes #557.
  • Loading branch information
marceljager authored and gkatsev committed Jun 27, 2019
1 parent 24f00d3 commit 15d753c
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions src/dash-playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ export default class DashPlaylistLoader extends EventTarget {

// switch to previously loaded playlists immediately
if (mediaChange &&
this.loadedPlaylists_[playlist.uri] &&
this.loadedPlaylists_[playlist.uri].endList) {
this.loadedPlaylists_[playlist.uri] &&
this.loadedPlaylists_[playlist.uri].endList) {
this.state = 'HAVE_METADATA';
this.media_ = playlist;

Expand Down Expand Up @@ -681,37 +681,40 @@ export default class DashPlaylistLoader extends EventTarget {

const master = this.parseMasterXml();
const updatedMaster = updateMaster(this.master, master);
const currentSidxInfo = this.media().sidx;

if (updatedMaster) {
const sidxKey = generateSidxKey(this.media().sidx);

// the sidx was updated, so the previous mapping was removed
if (!this.sidxMapping_[sidxKey]) {
const playlist = this.media();

this.request = requestSidx_(
playlist.sidx,
playlist,
this.hls_.xhr,
{ handleManifestRedirects: this.handleManifestRedirects },
this.sidxRequestFinished_(playlist, master, this.state, (newMaster, sidx) => {
if (!newMaster || !sidx) {
throw new Error('failed to request sidx on minimumUpdatePeriod');
}

// update loader's sidxMapping with parsed sidx box
this.sidxMapping_[sidxKey].sidx = sidx;

this.minimumUpdatePeriodTimeout_ = window.setTimeout(() => {
this.trigger('minimumUpdatePeriod');
}, this.master.minimumUpdatePeriod);

// TODO: do we need to reload the current playlist?
this.refreshMedia_(this.media().uri);

return;
})
);
if (currentSidxInfo) {
const sidxKey = generateSidxKey(currentSidxInfo);

// the sidx was updated, so the previous mapping was removed
if (!this.sidxMapping_[sidxKey]) {
const playlist = this.media();

this.request = requestSidx_(
playlist.sidx,
playlist,
this.hls_.xhr,
{ handleManifestRedirects: this.handleManifestRedirects },
this.sidxRequestFinished_(playlist, master, this.state, (newMaster, sidx) => {
if (!newMaster || !sidx) {
throw new Error('failed to request sidx on minimumUpdatePeriod');
}

// update loader's sidxMapping with parsed sidx box
this.sidxMapping_[sidxKey].sidx = sidx;

this.minimumUpdatePeriodTimeout_ = window.setTimeout(() => {
this.trigger('minimumUpdatePeriod');
}, this.master.minimumUpdatePeriod);

// TODO: do we need to reload the current playlist?
this.refreshMedia_(this.media().uri);

return;
})
);
}
} else {

this.master = updatedMaster;
Expand Down

0 comments on commit 15d753c

Please sign in to comment.