Skip to content

Commit

Permalink
remove currentMedia, abort/pause audio loaders on exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jun 22, 2020
1 parent 2657730 commit ae6e9c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 85 deletions.
24 changes: 10 additions & 14 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
const codecs = this.getCodecsOrExclude_();

// no codecs means that the playlist was excluded
if (!codecs || !this.sourceUpdater_.canChangeType()) {
if (!codecs) {
return;
}

Expand Down Expand Up @@ -1290,13 +1290,9 @@ export class MasterPlaylistController extends videojs.EventTarget {
}

getCodecsOrExclude_() {
if (!this.areMediaTypesKnown_()) {
return;
}

const media = {
main: this.mainSegmentLoader_.currentMedia_ || this.mainSegmentLoader_.startingMedia_ || {},
audio: this.audioSegmentLoader_.currentMedia_ || this.audioSegmentLoader_.startingMedia_ || {}
main: this.mainSegmentLoader_.startingMedia_ || {},
audio: this.audioSegmentLoader_.startingMedia_ || {}
};

// set "main" media equal to video
Expand Down Expand Up @@ -1350,6 +1346,9 @@ 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 Expand Up @@ -1422,17 +1421,14 @@ export class MasterPlaylistController extends videojs.EventTarget {
return;
}

if (!this.areMediaTypesKnown_()) {
return;
}

const codecs = this.getCodecsOrExclude_();

// no codecs means that the playlist was excluded
// or areMediaTypesKnown_ is false.
if (!codecs) {
// reset starting media if media types were
// known aka the starting playlist was excluded.
if (this.areMediaTypesKnown_()) {
this.mainSegmentLoader_.startingMedia_ = void 0;
this.audioSegmentLoader_.startingMedia_ = void 0;
}
return;
}

Expand Down
27 changes: 5 additions & 22 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ export default class SegmentLoader extends videojs.EventTarget {
this.vhs_ = settings.vhs;
this.loaderType_ = settings.loaderType;
this.startingMedia_ = void 0;
this.currentMedia_ = void 0;
this.segmentMetadataTrack_ = settings.segmentMetadataTrack;
this.goalBufferLength_ = settings.goalBufferLength;
this.sourceType_ = settings.sourceType;
Expand Down Expand Up @@ -840,7 +839,7 @@ export default class SegmentLoader extends videojs.EventTarget {
// out before we start adding more data
this.resyncLoader();
}
this.currentMedia_ = void 0;
this.startingMedia_ = void 0;
this.trigger('playlistupdate');

// the rest of this function depends on `oldPlaylist` being defined
Expand Down Expand Up @@ -1453,26 +1452,10 @@ export default class SegmentLoader extends videojs.EventTarget {
// When we have track info, determine what media types this loader is dealing with.
// Guard against cases where we're not getting track info at all until we are
// certain that all streams will provide it.
if ((trackInfo.hasVideo || trackInfo.hasAudio)) {
let changed = false;

if (!this.startingMedia_) {
changed = true;
this.startingMedia_ = trackInfo;
}
if (!shallowEqual(this.currentMedia_, trackInfo)) {
this.currentMedia_ = trackInfo;
changed = true;
}

// Note: if mux.js reports only audio or
// only video for a segment, when they are muxed
// we may trigger a trackinfo update that is only
// audio/video
if (changed) {
this.logger_('trackinfo update', trackInfo);
this.trigger('trackinfo');
}
if ((trackInfo.hasVideo || trackInfo.hasAudio) && !shallowEqual(this.startingMedia_, trackInfo)) {
this.startingMedia_ = trackInfo;
this.logger_('trackinfo update', trackInfo);
this.trigger('trackinfo');
}

}
Expand Down
54 changes: 5 additions & 49 deletions test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,20 +1031,19 @@ QUnit.test('waits for both main and audio loaders to finish before calling endOf
// audio media
this.standardXHRResponse(this.requests.shift(), audioMedia);

return requestAndAppendSegment({
return Promise.all([requestAndAppendSegment({
request: this.requests.shift(),
segment: videoSegment(),
isOnlyVideo: true,
segmentLoader: MPC.mainSegmentLoader_,
clock: this.clock
}).then(() => requestAndAppendSegment({
}), requestAndAppendSegment({
request: this.requests.shift(),
segment: audioSegment(),
isOnlyAudio: true,
segmentLoader: MPC.audioSegmentLoader_,
clock: this.clock
})).then(() => {

})]).then(() => {
assert.equal(videoEnded, 1, 'main segment loader did not trigger ended again');
assert.equal(audioEnded, 1, 'audio segment loader triggered ended');
assert.equal(MPC.mediaSource.readyState, 'ended', 'Media Source ended');
Expand Down Expand Up @@ -1348,7 +1347,6 @@ QUnit.test('blacklists switching from video-only playlists to video+audio', func
});
});

// TODO: MOAR TEST
QUnit.test('blacklists switching between playlists with different codecs', function(assert) {
openMediaSource(this.player, this.clock);

Expand Down Expand Up @@ -4551,8 +4549,6 @@ QUnit.module('MasterPlaylistController codecs', {
const {
audioStartingMedia,
mainStartingMedia,
audioCurrentMedia,
mainCurrentMedia,
audioPlaylist,
mainPlaylist
} = options;
Expand All @@ -4561,18 +4557,10 @@ QUnit.module('MasterPlaylistController codecs', {
this.mpc.mainSegmentLoader_.startingMedia_ = mainStartingMedia;
}

if (mainCurrentMedia) {
this.mpc.mainSegmentLoader_.currentMedia_ = mainCurrentMedia;
}

if (audioStartingMedia) {
this.mpc.audioSegmentLoader_.startingMedia_ = audioStartingMedia;
}

if (audioCurrentMedia) {
this.mpc.audioSegmentLoader_.currentMedia_ = audioCurrentMedia;
}

this.master = {mediaGroups: {AUDIO: {}}, playlists: []};

this.mpc.master = () => this.master;
Expand All @@ -4594,7 +4582,7 @@ QUnit.module('MasterPlaylistController codecs', {
};
}
this.master.playlists.push(audioPlaylist);
this.mpc.mediaTypes_.AUDIO.activePlaylistLoader = {};
this.mpc.mediaTypes_.AUDIO.activePlaylistLoader = {pause() {}};
}
};
},
Expand Down Expand Up @@ -4751,22 +4739,6 @@ QUnit.test('can get codecs from startingMedia', function(assert) {
assert.deepEqual(codecs, {video: 'avc1.4c400d', audio: 'mp4a.40.5'}, 'codecs returned');
});

QUnit.test('can get codecs from currentMedia', function(assert) {
this.contentSetup({
mainStartingMedia: {videoCodec: 'avc1.4c400c', hasVideo: true, hasAudio: false},
audioStartingMedia: {audioCodec: 'mp4a.40.2', hasVideo: false, hasAudio: true},
mainCurrentMedia: {videoCodec: 'avc1.4c400d', hasVideo: true, hasAudio: false},
audioCurrentMedia: {audioCodec: 'mp4a.40.5', hasVideo: false, hasAudio: true},
mainPlaylist: {attributes: {}},
audioPlaylist: {attributes: {}}
});

const codecs = this.mpc.getCodecsOrExclude_();

assert.deepEqual(this.blacklists, [], 'did not blacklist anything');
assert.deepEqual(codecs, {video: 'avc1.4c400d', audio: 'mp4a.40.5'}, 'codecs returned');
});

QUnit.test('playlist codecs take priority over others', function(assert) {
this.contentSetup({
mainStartingMedia: {videoCodec: 'avc1.4c400d', hasVideo: true, hasAudio: false},
Expand All @@ -4781,22 +4753,6 @@ QUnit.test('playlist codecs take priority over others', function(assert) {
assert.deepEqual(codecs, {video: 'avc1.4b400d', audio: 'mp4a.40.20'}, 'codecs returned');
});

QUnit.test('currentMedia codecs take priority over startingMedia codecs', function(assert) {
this.contentSetup({
mainStartingMedia: {videoCodec: 'avc1.4c400d', hasVideo: true, hasAudio: false},
audioStartingMedia: {audioCodec: 'mp4a.40.5', hasVideo: false, hasAudio: true},
mainCurrentMedia: {videoCodec: 'avc1.4b400d', hasVideo: true, hasAudio: false},
audioCurrentMedia: {audioCodec: 'mp4a.40.20', hasVideo: false, hasAudio: true},
mainPlaylist: {attributes: {}},
audioPlaylist: {attributes: {}}
});

const codecs = this.mpc.getCodecsOrExclude_();

assert.deepEqual(this.blacklists, [], 'did not blacklist anything');
assert.deepEqual(codecs, {video: 'avc1.4b400d', audio: 'mp4a.40.20'}, 'codecs returned');
});

QUnit.test('uses default codecs if no codecs are found', function(assert) {
this.contentSetup({
mainStartingMedia: {hasVideo: true, hasAudio: false},
Expand Down Expand Up @@ -5200,7 +5156,7 @@ QUnit.test('main & audio loader only trackinfo works as expected', function(asse
this.mpc.sourceUpdater_.ready = () => true;
this.mpc.sourceUpdater_.canChangeType = () => true;

this.mpc.mainSegmentLoader_.currentMedia_ = {
this.mpc.mainSegmentLoader_.startingMedia_ = {
videoCodec: 'avc1.4c400e',
hasVideo: true,
hasAudio: false
Expand Down

0 comments on commit ae6e9c2

Please sign in to comment.