Skip to content

Commit

Permalink
feat: exclude all incompatable browser/muxer codecs (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Jul 16, 2020
1 parent 1ab0f07 commit 2d0f0d7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ export class MasterPlaylistController extends videojs.EventTarget {
let updatedPlaylist = this.masterPlaylistLoader_.media();

if (!updatedPlaylist) {
// exclude any variants that are not supported by the browser before selecting
// an initial media as the playlist selectors do not consider browser support
this.excludeUnsupportedVariants_();

let selectedMedia;

if (this.enableLowInitialPlaylist) {
Expand Down Expand Up @@ -1436,6 +1440,23 @@ export class MasterPlaylistController extends videojs.EventTarget {
this.excludeIncompatibleVariants_(codecString);
}

/**
* Excludes playlists with codecs that are unsupported by the muxer and browser.
*/
excludeUnsupportedVariants_() {
this.master().playlists.forEach(variant => {
const codecs = codecsForPlaylist(this.master, variant);

if (codecs.audio && !muxerSupportsCodec(codecs.audio) && !browserSupportsCodec(codecs.audio)) {
variant.excludeUntil = Infinity;
}

if (codecs.video && !muxerSupportsCodec(codecs.video) && !browserSupportsCodec(codecs.video)) {
variant.excludeUntil = Infinity;
}
});
}

/**
* Blacklist playlists that are known to be codec or
* stream-incompatible with the SourceBuffer configuration. For
Expand Down
36 changes: 32 additions & 4 deletions test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,31 @@ QUnit.test(
}
);

QUnit.test('excludes playlists with unsupported codecs before initial selection', function(assert) {
this.masterPlaylistController.selectPlaylist = () => {
assert.equal(
this.masterPlaylistController.master().playlists[0].excludeUntil,
Infinity,
'excludes unsupported playlist before initial selection'
);
};

openMediaSource(this.player, this.clock);

// master
this.requests.shift().respond(
200, null,
'#EXTM3U\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=1,CODECS="theora,mp4a.40.5"\n' +
'media.m3u8\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=10000,CODECS="avc1.4d400d,mp4a.40.2"\n' +
'media1.m3u8\n'
);

// media
this.standardXHRResponse(this.requests.shift());
});

QUnit.test(
'updates the combined segment loader on live playlist refreshes',
function(assert) {
Expand Down Expand Up @@ -1352,6 +1377,13 @@ QUnit.test('blacklists switching between playlists with different codecs', funct

this.player.tech_.vhs.bandwidth = 1;

const mpc = this.masterPlaylistController;

// don't exclude unsupported variants now so we can
// keep them until until later on.
mpc.excludeUnsupportedVariants_ = () => {};
mpc.sourceUpdater_.canChangeType = () => false;

// master
this.requests.shift()
.respond(
Expand Down Expand Up @@ -1381,10 +1413,6 @@ QUnit.test('blacklists switching between playlists with different codecs', funct
'selected HE-AAC stream'
);

const mpc = this.masterPlaylistController;

mpc.sourceUpdater_.canChangeType = () => false;

let debugLogs = [];

mpc.logger_ = (...logs) => {
Expand Down
6 changes: 5 additions & 1 deletion test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1839,13 +1839,17 @@ QUnit.test('blacklists fmp4 playlists by browser support', function(assert) {
'#EXT-X-STREAM-INF:BANDWIDTH=1,CODECS="avc1.4d400d,mp4a.40.2"\n' +
'media1.m3u8\n';

const mpc = this.player.tech_.vhs.masterPlaylistController_;

// do not exclude incompatible so that we can run this test.
mpc.excludeUnsupportedVariants_ = () => {};

// master
this.requests.shift().respond(200, null, playlistString);

// media
this.standardXHRResponse(this.requests.shift());

const mpc = this.player.tech_.vhs.masterPlaylistController_;
const playlistLoader = mpc.masterPlaylistLoader_;
const loader = mpc.mainSegmentLoader_;
const master = this.player.tech_.vhs.playlists.master;
Expand Down

0 comments on commit 2d0f0d7

Please sign in to comment.