Skip to content

Commit

Permalink
fix: null check sidx on sidxmapping, check that end > start on remove (
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Apr 23, 2021
1 parent 3c9f721 commit 92f1333
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/dash-playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export const updateMaster = (oldMaster, newMaster, sidxMapping) => {
if (playlist.sidx) {
const sidxKey = generateSidxKey(playlist.sidx);

if (sidxMapping && sidxMapping[sidxKey]) {
// add sidx segments to the playlist if we have all the sidx info already
if (sidxMapping && sidxMapping[sidxKey] && sidxMapping[sidxKey].sidx) {
addSidxSegmentsToPlaylist(playlist, sidxMapping[sidxKey].sidx, playlist.sidx.resolvedUri);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,14 @@ export default class SegmentLoader extends videojs.EventTarget {
end = this.duration_();
}

// skip removes that would throw an error
// commonly happens during a rendition switch at the start of a video
// from start 0 to end 0
if (end <= start) {
this.logger_('skipping remove because end ${end} is <= start ${start}');
return;
}

if (!this.sourceUpdater_ || !this.startingMediaInfo_) {
this.logger_('skipping remove because no source updater or starting media info');
// nothing to remove if we haven't processed any media
Expand Down
62 changes: 62 additions & 0 deletions test/dash-playlist-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
filterChangedSidxMappings,
parseMasterXml
} from '../src/dash-playlist-loader';
import parseSidx from 'mux.js/lib/tools/parse-sidx';
import xhrFactory from '../src/xhr';
import {generateSidxKey} from 'mpd-parser';
import {
Expand Down Expand Up @@ -385,6 +386,67 @@ QUnit.test('updateMaster: updates minimumUpdatePeriod', function(assert) {
);
});

QUnit.test('updateMaster: requires sidxMapping.sidx to add sidx segments', function(assert) {
const prev = {
playlists: [{
uri: '0',
id: 0,
segments: [],
sidx: {
resolvedUri: 'https://example.com/foo.mp4',
uri: 'foo.mp4',
duration: 10,
byterange: {
offset: 2,
length: 4
}
}
}],
mediaGroups: {
AUDIO: {},
SUBTITLES: {}
}
};
const next = {
playlists: [{
uri: '0',
id: 0,
segments: [],
sidx: {
resolvedUri: 'https://example.com/foo.mp4',
uri: 'foo.mp4',
duration: 10,
byterange: {
offset: 2,
length: 4
}
}
}],
mediaGroups: {
AUDIO: {},
SUBTITLES: {}
}
};
const sidxMapping = {};
const key = generateSidxKey(prev.playlists[0].sidx);

sidxMapping[key] = {sidxInfo: {uri: 'foo', key}};

assert.deepEqual(
updateMaster(prev, next, sidxMapping),
null,
'no update'
);

sidxMapping[key].sidx = parseSidx(sidxResponse().subarray(8));

const result = updateMaster(prev, next, sidxMapping);

assert.ok(result, 'result returned');
assert.equal(result.playlists[0].segments.length, 1, 'added one segment from sidx');

});

QUnit.test('compareSidxEntry: will not add new sidx info to a mapping', function(assert) {
const playlists = {
0: {
Expand Down
42 changes: 41 additions & 1 deletion test/segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2633,8 +2633,48 @@ QUnit.module('SegmentLoader', function(hooks) {
});
});

QUnit.test('triggers appenderror when append errors', function(assert) {
QUnit.test('does not remove when end <= start', function(assert) {
let audioRemoves = 0;
let videoRemoves = 0;

return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
const playlist = playlistWithDuration(40);

loader.playlist(playlist);
loader.load();
this.clock.tick(1);

loader.sourceUpdater_.removeAudio = (start, end) => {
audioRemoves++;
};
loader.sourceUpdater_.removeVideo = (start, end) => {
videoRemoves++;
};

assert.equal(audioRemoves, 0, 'no audio removes');
assert.equal(videoRemoves, 0, 'no video removes');

standardXHRResponse(this.requests.shift(), muxedSegment());
return new Promise((resolve, reject) => {
loader.one('appended', resolve);
loader.one('error', reject);
});
}).then(() => {
loader.remove(0, 0, () => {});
assert.equal(audioRemoves, 0, 'no audio remove');
assert.equal(videoRemoves, 0, 'no video remove');

loader.remove(5, 4, () => {});
assert.equal(audioRemoves, 0, 'no audio remove');
assert.equal(videoRemoves, 0, 'no video remove');

loader.remove(0, 4, () => {});
assert.equal(audioRemoves, 1, 'valid remove works');
assert.equal(videoRemoves, 1, 'valid remove works');
});
});

QUnit.test('triggers appenderror when append errors', function(assert) {
return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_).then(() => {
return new Promise((resolve, reject) => {
loader.one('appenderror', resolve);
Expand Down

0 comments on commit 92f1333

Please sign in to comment.